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
- If your theme is using Templating API v2, paste the "Capture submit request event" code below in the DOMContentLoaded block:
document.addEventListener("DOMContentLoaded", function(){
//send user role to Google Analytics
var userRole = HelpCenter.user.role;
ga('set', 'dimension1', userRole);
ga('send', 'pageview');
}); - If your theme is using Templating API v1, paste the "Capture submit request event" code below in the jQuery $(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:
70 Comments
The above worked and it is resolved now. Thanks for the help.
Does anyone know whether users landing on the homepage and then logging in are counted as Anonymous sessions, [logged in user role] sessions, or whether it duplicates the count of sessions and records one for the user while Anonymous and one for the user once logged in?
Hey Thomas,
All of the hits that are in that session will be set to the role level assuming you've set up the Custom Dimensions per the article above.
You'll want to take a look at the following article: Custom Dimensions and Metrics
There's a section titled User Level Scope which will show a diagram that I believe you'll find useful.
Hope this helps!
Please help. I have been trying to get this up and running for days and keep circling the drain.
This code does not show up in my script.js
Hey Taylor,
Looks like you guys have a custom theme (looks really good, btw) and have implemented some custom JavaScript. Looking at how things are structured your script.js file, it would appear you need to add the code around line 21 after the
This should be the right place. Give it a shot, otherwise you may wanna get in touch with the folks who worked on your theme.
Thanks!
Thank you, Ryan.
This seems to work. I am pulling User Name and Role, but email is still not coming through.
any thoughts?
Hey Taylor,
Looks like your Help Center now requires authentication so I can't see exactly what's going on but each data point you wanna track like user name and role should be it's own separate custom metric and you'll need to set them. So the code will need to look something like what I've entered below. Like I said earlier, it may also be worth a chat with the folks who worked on the theme you have, as they'll be much more familiar with the setup. Also remember that we won't be able to send a user name or email, if the current user isn't logged in. So you may see some traffic without that information.
Has anyone noticed that if you follow the instructions above that each page load in your help center triggers two page views being sent to Google Analytics? One triggered by Zendesk's built in GA integration, and another triggered by the custom code this document recommends you insert into script.js
If you have Google Analytics enabled in your Guide admin panel and have put in your tracking ID, then that will trigger a page view being sent off to GA for each page load. This page view does not include the custom dimension.
If you then follow the instructions in this article, and insert ga('send', 'pageview'); in your script.js, then that will trigger an additional page view being sent off to GA. This page view includes the custom dimension.
Making this change would effectively double the page views we would see in Google Analytics.
Has anyone else observed this behavior? Is there a workaround in place so that one could capture these custom dimensions in GA without triggering a second GA page view for each page load?
@David B,
I encountered the same issue. Remove the custom code from any script.js, and keep the Tracking ID enabled within the Admin panel and you will be good to go.
The tracking id captures everything you need unless you want to implement Google Tag Manager to track very specific actions.
Thanks for sharing Taylor!
Just my $.02 any time you are moving data outside of a system that is PII (personally identifiable Information) e.g. if you are sending data to GA you may want to make sure you are in compliance with Google Analytics policies as well as company and governmental rules and regulations.
My best practice is to only use non-identifiable value from zendesk and associate your data further downstream if needed.
https://support.google.com/analytics/answer/7686480?hl=en
I noticed that I do not get 100% sessions data with custom dimensions. Is it because I enabled GA in Guide Settings and also added JS code?
Hi Korak -
I believe this is due to the way that Google Analytics does data sampling. Here's an article from their knowledge base that should help explain it: About Data Sampling
@David Bastedo Yes, I found the same thing. @Taylor if you remove the custom code, it won't send the custom dimension to ga. That's because the custom dimension is being set after the 'send' 'pageview' had already executed.
The only solution I can see is to turn off the google analytics option in 'admin' and just use custom code. Not ideal!
Anyone find a better way?
Paul Moran could you send the data as an event rather than a pageview? Something like:
Taking into account the points made above about transferring PII.
Hi Chris, we wanted to include this data in the hits report. If we did the above, we'd need a separate report for events which isn't ideal for us.
Hi Paul, maybe the 'event' parameter is a red herring. I'm able to see pageviews per user role type as outlined in this article without the ga('send', 'pageview') line.
This is the code I'm using:
I'm setting 'tag' elsewhere in the script. Looking at my events, 'Help Center' gets logged for every page view, with no label, so it's not actually showing me anything.
Chris Stock Thanks, that would work but it's also adding an superfluous 'event' as well as the 'pageview' to GA. I want to report on meaningful events, and this would clutter things up.
For now, I'll leave the zendesk's GA out of the box code in place and I'm going to set the variable when a user triggers an event on the page. I want to report on the user email domain so I've set the 'domain' variable to 'User' scope, and as long as the user logs in at some point, I'll be able to report on the variable.
As for as Google's terms of service agreement, does anyone think I'll have a problem with reporting the email domain only. I think I'm ok since it doesn't readily identify the user. I just want to find out what organization they belong to.
When we use this code it breaks the "Submit" button on our ticket form. Any other suggestions of how to filter out internal traffic to Google Analytics? Right now I'm filtering a bunch of individual internal IPs, which is not ideal.
@... There is }); missing in the code example.
Sarah Eshelman did you copy the code exactly?
In the original post there is a curly bracket and right parenthesis missing in the end.
Preferred - Native javascript (no jQuery needed)
OLD - With jQuery
Kay thanks for letting us know about the missing curly bracket and right parenthesis in the code. We'll fix it!
Hello there. Please help.
This code does not show up in my script.js
Hello!
4C Insights
That might be because it's an array.
Try this, it gives you the first result of the array or an empty result
Thank you so much Kay!
Just to be sure, the final result should look like the below? Appreciate the guidance!
You can ignore the above - it worked after testing! Thank you again.
Glad to hear it worked, Joey. Thanks for letting us know!
I followed the steps in this article a few days ago and I still do not see my custom dimensions of user role and user external ID populating in Google Analytics. Below is my code and GA page. Any suggestions?
Hi Haley! Sorry to hear this is happening, but I suspect that it's because we need to update this article with an additional step of importing a jQuery library. A change in April removed jQuery from Help Center themes by default, so you have the ability to import your own library. You will likely need to follow the instructions here for this function to work in your Help Center. If you could let me know if that resolves your problem, I'll make sure we get this article updated too!
Can any one help me with how the JS should look in order to track organisation as well as the user role? There is a few different variants in the comments and i'm not sure what the best approach is.
Madison Davis there is a reason that jQuery has been removed. As it is no longer necessary for the most users. Here's the same script without jQuery.
Preferred - Native javascript (no jQuery needed)
Tom Perry
If you want to track an organisation of a user, try something like this
Please sign in to leave a comment.