Google Analytics gives you the ability to capture additional information on a Hit, Session, User, or Product. This section will focus on capturing data on Users, but this same technique can be applied to Hits, Sessions, and Products just as easily.
This is the fifth article in a series. The series outlines how to use Google Analytics to answer questions you may have as a Guide manager responsible for providing an effective self-service support option to your customers. The series covers the following topics:
- Part 1 - Asking the right questions
- Part 2 - Measuring the effectiveness of search
- Part 3 - Tracking customers' actions
- Part 4 - Fine-tuning Help Center
- Part 5 - Capturing Help Center user data - YOU ARE HERE
If you haven't already done so, enable Google Analytics in your Help Center. See Enabling Google Analytics.
Capture a user's role, name, and email in Google Analytics
For any logged in user in Help Center, Zendesk can pass Google Analytics information on their role and name if they are logged in. A user in Help Center has one of the following roles:
- manager: This is an logged in agent with admin privileges
- agent: This is an logged in agent with standard privileges
- end_user: This is a logged in end user
- anonymous: This is a user in Help Center that is not logged into Zendesk
To enable capture of custom dimensions with a user's role
- Log in to Google Analytics and go to the Admin tab.
- Under the Property tab for your project, click Custom Definitions, then Custom Dimensions.
- Click New Custom Dimensions.
- Add a new dimension named "User Type" scoped to a User and make sure it is set to Active, then click Create.
- In Guide, go to edit the code for your theme (see Editing your Help Center theme).
- Open the script.js file in edit mode and paste the "Capture submit request event" code below in the $(document).ready(function() { ... }); block:
$(document).ready(function() { //send user role to Google Analytics var userRole = HelpCenter.user.role; ga('set', 'dimension1', userRole); ga('send', 'pageview');
Make sure the dimension numbers match the values for the custom variables you have in your Google Analytics account.

You should then have a report of Help Center pageviews by user role:
40 Comments
Thanks for posting this article, very helpful! Three questions:
Hey Dan,
Answer below.
#1. You can use either. Not sure if there is an advantage in using one or the other, but would love to know if you find out.
#2. Oops! Don't do that :) Removed that section from the article.
#3. Yep. The same format should be able to used to pass through any variable.
Thanks for the feedback.
Cheers,
Jason
Hi Jayson Maynard,
i have encounter a problem when capturing the user data, i followed every step that is in the article but doesn't show for me the User roles even the User Emails. it doesn't show any data
Hey Carl!
Can you post a screenshot of the code you put in the JS editor? I'm not super familiar with JS, but my educated guess is that there's a problem there.
Hello! I'm experiencing the same problem; if anyone can help me see what I'm missing I would be REALLY appreciative!
I see user sessions in GA but am not seeing the user data for signed in users. And just to clarify--there have been signed in user sessions.
We have the custom dimensions created and the JS in the Guide (see snippet below), then I set up a new Dashboard in GA to view the data, I see sessions elsewhere, but no sessions that are reporting the `user_role`
GA custom report under Customization > Dashboards > New report:
Here are the results from the Dashboard:
Screenshot from our JS file in our custom theme:
And here's the exact code that I pasted in:
```
//Google Analytics User Data capture a la https://support.zendesk.com/hc/en-us/articles/204279766
var dimensionValue = HelpCenter.user.role;
ga('set', 'dimension1', dimensionValue);
var dimensionValue = HelpCenter.user.name;
ga('set', 'dimension2', dimensionValue);
var dimensionValue = HelpCenter.user.email;
ga('set', 'dimension3', dimensionValue);
```
Again, any help would be GREATLY appreciated!
Hi Micah,
I'm struggling with this myself, but one thing I noticed }); is missing from the end of your JS code. See screenshot below. I'm not sure if this solves your problem but figured I would point it out.
Thanks,
Tim
Hi Tim,
Thanks so much for pointing this out. I had wondered about that, but as I'm not very familiar with JS I wasn't sure if the function needed to be closed there, or just at the end of the function.
So far, I've had no luck with any of the tweaks I've tried, but I'll be sure to report back if that fixes things.
Thanks again!
Micah
No problem.
Zendesk- I'm having quite a bit of trouble myself with this and would appreciate any help.
Thanks,
Tim
Hey Tim,
Try adding :
to the end of your script. This seems to have worked for me. I'm still working to verify that I'm getting all of the correct data; but now I am seeing at least some data in GA (whoot!).
~Micah
Thanks, Micah. Unfortunately, that hasn't made a difference yet. Could you possibly post your code and report settings?
Thanks,
Tim
Hi Tim,
Happy to. From what I'm seeing in GA the sessions report takes a day or so to populate though.
JS in our custom theme:
Custom report options under Customization > Custom Reports > New:
Custom Report results:

As I said, looks like data takes about a day to populate, and I'm completely new to GA so I'm not sure if this is the best way to view/slice this data, I'm just happy to see that we're starting to ingest it... now I can get someone who is more familiar with GA to set up any needed segments, reports, views, etc.
I hope this helps you in your quest!
Best,
Micah
Thank you, Micah! I really appreciate it. I'm finally seeing user data. I'm not sure what user data you want to see, but I'm most interested in seeing the email address of each user. So, I created the below report to show each user's email address and I filtered for 'end_user'.
Best,
Tim
Hi Micah and Tim, Glad you both got this sorted this out. Nice teamwork! :)
But I wanted to let others know that we did have some problems in our article. It's just been updated, so hopefully anyone else who comes along and wants to implement this won't struggle!
Thanks to Becca on our support team for the updated version!
Hi Jennifer,
I really appreciate Becca's help--she was instrumental in getting data to populate in GA; appreciate the great support! And thanks for updating the article to include the suggestions she made--this will be really helpful for folks--thanks again!
Glad to hear it, Micah! Thanks for coming back with the shout out to Becca. She is great.
Glad she helped you solve your problem and was able to update this article for others!
The link at -
If you haven't already done so, enable Google Analytics in your Help Center. See Enabling Google Analytics.
doesn't lead to enabling google analytics page
Should it refer to - https://support.zendesk.com/hc/en-us/articles/205402318-Enabling-Google-Analytics-for-your-Help-Center
You're correct, Avil. Thanks for pointing that out! I've fixed the link in the article.
Can someone advise whether you can include custom role information? We are interested in user data for our agents in our internal knowledge base (used only by our agents in our call center and not customers/the general public). This article seems to only provide how to get the basic roles of end user, agent, manager, anonymous....but these aren't very helpful for an agent only Help Center.
I do see there was some concern in the comments about what google allows (https://support.zendesk.com/hc/en-us/articles/204279766/comments/115001269747), but that really seems to be regarding personally identifiable information, and I don't think custom role would be considered something personally identifiable.
Hi Lilia,
This information is not included in the HelpCenter.user object but could be obtained via an API call to /api/v2/users/me.json. This will expose the custom_role_id. You'd likely want to cache that information via a cookie or local storage in the browser to reduce load times and the number of API calls.
Thanks!
Thanks Ryan!
Can you advise if the help center user object is the following? I am not sure as it doesn't appear to contain HelpCenter.user.role which the code ZD supplied in this article. https://developer.zendesk.com/apps/docs/help-center-templates/objects#user-object
Also, can you advise if there are any reference materials on executing an API call within the help center? I have searched and come up empty except for the following article...which is about troubleshooting a null result on a call to /api/v2/users/me.json (caused by having a host mapped help center): https://support.zendesk.com/hc/en-us/articles/115008781728-Using-the-endpoint-users-me-json-in-Guide-returns-an-Anonymous-user-object
This seems like something we'll need to hand off to our engineering team but I would like to understand the effort.
Thanks
-Lila
Hey Lila,
I'm referring the HelpCenter.user object used in the JavaScript code samples in this article. For example this
You'll need to use JavaScript to make an AJAX call to that API endpoint and parse the results to get the custom role. You can see the output of this by going to https://support.zendesk.com/api/v2/users/me.json for our HelpCenter when you're logged in. Or replace our domain, with your domain to see it on your HelpCenter.
The article you've referenced has sample code on how to execute this AJAX call and advises you to use the relative URL to access the API rather than the absolute URL when you have a host mapped HelpCenter.
So the JavaScript will look like
Instead of
Thanks Ryan. Is there documentation on what is available in the HelpCenter.user object?
Hey Lila,
There isn't specific documentation for it but it should largely follow the definition of the end user when an end user is logged in and the user object when an agent or admin is logged in.
Thanks!
Is there any way to send a user's external id to GA?
Hey @Dylan,
If you have access to that value via JavaScript you should be able to set it as a custom dimension you send to GA.
Thanks!
Hi. The code in the instructions is:
But in the comments, Micah and Tim use the following code, apparently successfully:
Should I be entering 'userRole' or 'dimensionValue'?
Thanks!
Hey Thomas,
userRole and dimensionValue are just variable names in the JavaScript, so it doesn't matter what you call it as long as it's consistent. The code is actually identical and will send the same data to Google.
Thanks!
Hi,
I've had this set up on our Sandbox site for a few days now, and it's still not returning any data in the custom report.
The code:
The report settings:
The custom dimension:
Is there anything in the above that looks off? Or are there any suggestions why it might not be returning any data?
Thanks!
Hi Thomas,
Just wanted to verify that you've enabled Google Analytics in you Sandbox account's Help Center and that you're looking at the proper tracking ID (Google will allow you to generate multiple tracking IDs so you can set up test accounts).
Assuming that looks good, I would take a look at the Google Analytics Debugger for Chrome which should report the calls and data being made in the JavaScript console of the browser. I would also look at the JavaScript console to verify if there are any JavaScript errors in your code.
Thanks!
Thanks Ryan, I must confess to knowing very little about JS, however on line 116 of my code I have identified an
which is a result of me closing the function too early (on line 12 of the code I pasted above). It now seems to be executing more commands, and is sending the information to GA, I guess I'll wait and see if it trickles through.
Thanks for your help again!
Please sign in to leave a comment.