Reputation: 1967
I am currently editing some code that originally written by someone else. And was using the following code for Google Analytics:
On load:
ga('create', 'UA-000000-21');
ga('send', 'pageview');
On some Event:
ga('set', 'page', 'SOME-VALUE');
ga('send', 'pageview');
But according to the new requirement I need to also send the Role of the logged in user. So that the pageviews can be classified according to user role in the Google Analytics dashboard. I have tried using custom column but failed to see any result.
Any help is appreciated. Even a general idea on how to approach this will also be helpful.
Thanks
Upvotes: 1
Views: 284
Reputation: 868
I'd create a new custom dimension and set the users role to that dimension. I am assuming that this is what the question is about.
Once you've set up a new dimension, look at its index and remember it. Also look at what type of scope you'd like, hit, session or visitor.
Create a function that returns the value of your user. Then when you send a page view hit with your initial load, also add the hit of the role to the push queue with:
ga('create', 'UA-XXXX-Y', 'auto');
ga('set', 'cd{index number}', '{value}');
ga('send', 'pageview');
ga('set', 'cd1', 'admin');, for example.
This is the general approach. If you do NOT want to add it with a page view, consider using event tracking and send it as a non-incremental value to attach it to the hit, session or user.
Also, you might want to reconsider using GA if you do not want to tie this to a session at all as per the subject.
Upvotes: 1