Google Analytics and Help Center - Part 5: Capturing Help Center user data

Return to top
Have more questions? Submit a request

68 Comments

  • Thomas Crowley

    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?

    0
  • Brett Bowser
    Zendesk Community Team

    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!

    1
  • Taylor Goldsberry

    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

    $(document).ready(function() {
    0
  • Ryan McGrew
    Zendesk Product Manager

    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 

    $(function () {

    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!

    0
  • Taylor Goldsberry

    Thank you, Ryan. 

     

    This seems to work. I am pulling User Name and Role, but email is still not coming through. 

     

    any thoughts?

    0
  • Ryan McGrew
    Zendesk Product Manager

    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.

    var userRole = HelpCenter.user.role;
    var userName = HelpCenter.user.name;
    var email = HelpCenter.user.email;

    ga('set', 'dimension1', userRole);
    ga('set', 'dimension2', userName);
    ga('set', 'dimension3', email);
    ga('send', 'pageview');
    0
  • David Bastedo

    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?

    0
  • Taylor Goldsberry

    @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. 

    0
  • Brett Bowser
    Zendesk Community Team

    Thanks for sharing Taylor! 

    0
  • Ian Lintner

    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

    0
  • Korak Purkayastha

    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?

    0
  • Nicole S.
    Zendesk Community Team

    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

    1
  • Paul Moran

    @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?

    0
  • Chris Stock
    Community Moderator

    Paul Moran could you send the data as an event rather than a pageview? Something like:

    ga('send', 'event', 'Help Center', 'User', {
    'dimension1': HelpCenter.user.role,
    'dimension2': HelpCenter.user.name,
    'dimension3': HelpCenter.user.email,
    nonInteraction: true
    });

    Taking into account the points made above about transferring PII.

    0
  • Paul Moran

    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.

    0
  • Chris Stock
    Community Moderator

    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:

    // GA Custom Dimensions
    ga('send', 'event', 'Help Center', 'User', {
    'dimension1': HelpCenter.user.role,
    'dimension2': tag,
    nonInteraction: true
    });

    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.

     

    0
  • Paul Moran

    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. 

    0
  • Sarah Eshelman

    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.

     

    0
  • Kay
    Community Moderator

    @... 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)

    document.addEventListener("DOMContentLoaded", function(){

    //send user role to Google Analytics 
    var userRole = HelpCenter.user.role;
    ga('set', 'dimension1', userRole);
    ga('send', 'pageview');

    });


    OLD - With jQuery

    $(document).ready(function() {
    
    //send user role to Google Analytics 
    
    var userRole = HelpCenter.user.role;
    ga('set', 'dimension1', userRole);
    ga('send', 'pageview');

    });
    0
  • Jennifer Rowe
    Zendesk Documentation Team

    Kay thanks for letting us know about the missing curly bracket and right parenthesis in the code. We'll fix it!

    0
  • Artur Tsudik

    Hello there. Please help. 

    This code does not show up in my script.js 

    $(document).ready(function() {
    0
  • 4C Insights

    Hello!

    I'm currently able to pass user email and role into GA from Zendesk, but I'm unable to capture organization. Can you help provide some guidance here? The code I have in Zendesk is below.
     
    Definitely know something is up with the "HelpCenter.user.organizations.name" piece. Thank you!
     
        ga('send', 'event', 'Help Center', 'User', {
       'dimension1': HelpCenter.user.role,
       'dimension2': HelpCenter.user.email,
       'dimension3': HelpCenter.user.organizations.name,
       nonInteraction: true
        });
    0
  • Kay
    Community Moderator

    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

    (HelpCenter.user.organizations.length > 0) ? HelpCenter.user.organizations[0].name : '';
    0
  • 4C Insights

    Thank you so much Kay!

    Just to be sure, the final result should look like the below? Appreciate the guidance!

    ga('send', 'event', 'Help Center', 'User', {
       'dimension1': HelpCenter.user.role,
       'dimension2': HelpCenter.user.email,
       'dimension3':
    (HelpCenter.user.organizations.length > 0) ? HelpCenter.user.organizations[0].name : '';   
    nonInteraction: true
        });
    0
  • 4C Insights

    You can ignore the above - it worked after testing! Thank you again.

    0
  • Jennifer Rowe
    Zendesk Documentation Team

    Glad to hear it worked, Joey. Thanks for letting us know!

    0
  • Haley Chapman

    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?

     

     

    0
  • Madison Davis
    Zendesk Community Team

    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!

    0
  • Tom Perry

    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. 



    0
  • Kay
    Community Moderator

    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)

    document.addEventListener("DOMContentLoaded", function(){

    //send user role to Google Analytics 
    var userRole = HelpCenter.user.role;
    ga('set', 'dimension1', userRole);
    ga('send', 'pageview');

    });

     

    Tom Perry

    If you want to track an organisation of a user, try something like this

    var userOrg = HelpCenter.user.organizations[0].name;
    ga('set', 'dimension2', userOrg);
    0

Please sign in to leave a comment.

Powered by Zendesk