1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Track Usergroups in Google Analytics

Track your Guests and Logged-In users in Google Analytics

  1. DBA

    DBA Well-Known Member

    DBA submitted a new resource:

    Track Usergroups in Google Analytics (version 1.0) - Track your Usergroups in Google Analytics

    Read more about this resource...
     
  2. AzzidReign

    AzzidReign Well-Known Member

    Thanks for this...I've been wanting to track this for a while now just didn't know how. Hopefully this gives me the info I need. Are you doing any other advanced tracking on your site?
     
  3. DBA

    DBA Well-Known Member

    The only other thing I'm did with the Analytics code was add this:
    Code:
      _gaq.push(['_setSiteSpeedSampleRate', 100]);
    Plus we have a couple funnels/goals setup, however that doesn't take extra code.
     
  4. AzzidReign

    AzzidReign Well-Known Member

    What's the default for the sample rate? Any reason why you added that?

    What funnels did you set up? For registering? Or for merchandise? If for registering, can you post a screenshot of the set up please?
     
  5. DBA

    DBA Well-Known Member

    The default is only 1% or 10k visitors.
     
    AzzidReign likes this.
  6. AzzidReign

    AzzidReign Well-Known Member

    Well, I installed this the other day and it stopped tracking everything :/ Maybe I edited something wrong. But this is what I have. Maybe I added too many options? Or did them wrong?

    Code:
    <xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
    <script type="text/javascript">
     
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}']);
      _gaq.push(['_setCustomVar',
          1,
          'Usergroup',
    <xen:if is="{xen:helper ismemberof, $visitor, 1}">
          'Unregistered-1',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 2}" />
          'Member-2',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 3}" />
          'Administrator-3',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 4}" />
          'SuperModerator-4',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 7}" />
          'DietModerator-7',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 8}" />
          'Premium-8',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 34}" />
          'Retired-34',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 9}" />
          'VIP-9',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 27}" />
          'Writer-27',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 25}" />
          'CommunityChamp-25',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 47}" />
          'MOTM-47',
    </xen:if>
          1
    ]);
      _gaq.push(['_trackPageview']);
     
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
     
    </script>
    </xen:if>
     
  7. DBA

    DBA Well-Known Member

    Did you already remove it from your site?
     
  8. AzzidReign

    AzzidReign Well-Known Member

    Yeah, I reverted back to the original code.
     
  9. DBA

    DBA Well-Known Member

    Can you try it again? I'd like to check something.
     
  10. AzzidReign

    AzzidReign Well-Known Member

    Changed it back.
     
  11. AzzidReign

    AzzidReign Well-Known Member

    I'm not sure if this is how it should look in the code...I only clipped part of the code for you.
    Code:
      _gaq.push(['_setCustomVar',
          1,
          'Usergroup',
     
          'Administrator-3',
     
          1
    ]);
    It looks like you did some editing to the original code:
    Code:
    <xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
     
        var _gaq = [['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}'], ['_trackPageview']];
        !function(d, t)
        {
            var g = d.createElement(t),
                s = d.getElementsByTagName(t)[0];
            g.async = true;
            g.src = ('https:' == d.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            s.parentNode.insertBefore(g, s);
        }
        (document, 'script');
     
        </script><xen:comment><!--Adapted from http://mathiasbynens.be/notes/async-analytics-snippet--></xen:comment></xen:if>
    So can't we do something like this while keeping most of the original code in tact since it uses async (which I don't think your code does):
    Code:
    <xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
     
        var _gaq = [['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}'], ['_setCustomVar',
                    1,
          'Usergroup',
    <xen:if is="{xen:helper ismemberof, $visitor, 1}">
          'Unregistered-1',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 2}" />
          'Member-2',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 3}" />
          'Administrator-3',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 4}" />
          'SuperModerator-4',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 7}" />
          'DietModerator-7',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 8}" />
          'Premium-8',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 34}" />
          'Retired-34',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 9}" />
          'VIP-9',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 27}" />
          'Writer-27',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 25}" />
          'CommunityChamp-25',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 47}" />
          'MOTM-47',
    </xen:if>
          1], ['_trackPageview']];
        !function(d, t)
        {
            var g = d.createElement(t),
                s = d.getElementsByTagName(t)[0]; 
            g.async = true;
            g.src = ('https:' == d.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            s.parentNode.insertBefore(g, s);
        }
        (document, 'script');
     
        </script><xen:comment><!--Adapted from http://mathiasbynens.be/notes/async-analytics-snippet--></xen:comment></xen:if>
    
    I'm not that good at coding...mainly get it by trial and error so I probably did something wrong.
     
  12. DBA

    DBA Well-Known Member

    Not sure why yours isn't working as my code looks identical.
    Mine:
    Code:
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXXXXX-X']);
      _gaq.push(['_setCustomVar',
          1,
          'Usergroup',
     
          'Administrator-3',
     
          1
    ]);
      _gaq.push(['_trackPageview']);
     
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    
    Copied from your site:
    Code:
     
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA- XXXXXXXXX-X ']);
      _gaq.push(['_setCustomVar',
          1,
          'Usergroup',
     
          'Unregistered-1',
     
          1
    ]);
      _gaq.push(['_trackPageview']);
     
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
     
    
     
  13. AzzidReign

    AzzidReign Well-Known Member

    Not sure if you saw my last bit of code I asked you about, asking if this could work:
    Code:
    <xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
     
        var _gaq = [['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}'], ['_setCustomVar',
                    1,
          'Usergroup',
    <xen:if is="{xen:helper ismemberof, $visitor, 1}">
          'Unregistered-1',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 2}" />
          'Member-2',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 3}" />
          'Administrator-3',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 4}" />
          'SuperModerator-4',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 7}" />
          'DietModerator-7',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 8}" />
          'Premium-8',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 34}" />
          'Retired-34',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 9}" />
          'VIP-9',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 27}" />
          'Writer-27',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 25}" />
          'CommunityChamp-25',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 47}" />
          'MOTM-47',
    </xen:if>
          1], ['_trackPageview']];
        !function(d, t)
        {
            var g = d.createElement(t),
                s = d.getElementsByTagName(t)[0];
            g.async = true;
            g.src = ('https:' == d.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            s.parentNode.insertBefore(g, s);
        }
        (document, 'script');
     
        </script><xen:comment><!--Adapted from http://mathiasbynens.be/notes/async-analytics-snippet--></xen:comment></xen:if>
    It appears to be working properly. Some of the stats are a bit down from when I used the original code. And it seems some of the usergroups aren't tracking but that could also be the small number of users in those usergroups have tracking disabled. But now I'm thinking it could also be the double digits. As per your instructions, I set it up like this:
    [​IMG]

    I'm wondering if I should actually put the whole name in there to differentiate the usergroups. I'm not sure if 47 will fall within 4 and 7 usergroup in the tracking code, and then not actually show up in "47". So should I be doing "MOTM-47" instead of just 47? Sorry for the questions...the documentation on this stuff always confused me which is why it has taken me this long to do it.

    Also, if you don't mind me asking, I set this up in the admin panel under advanced segments:
    [​IMG]
    I don't see where I can just view stats for "guests vs registered". Is there a way to do this? Or what was the point of doing it this way?
     
  14. DBA

    DBA Well-Known Member

    Like I said above, that code appears to be correct.

    Instead of "Containing" try "Exactly matching".

    Are some of those Secondary User Groups? Not sure which one will show (Primary or Secondary) if a user is part of two usergroups.
     
  15. AzzidReign

    AzzidReign Well-Known Member

    2 may be secondary. I'll have to see how that works. Thanks for the help. :)

    Also, is there a report that I can pull to look at the stats of Registered vs Guest?
     
  16. DBA

    DBA Well-Known Member

    You can use it with all reports; go to the report, click "Advance Segments", and select your custom segments.

    If you look at the two images at the bottom of this page you'll see how I setup my logged in and guest segments.
    http://xenforo.com/community/resources/track-usergroups-in-google-analytics.726/

    Since you have so many usergroups I'd suggest using "Exactly matching" instead of "Containing", when you set the segments up.


    If you can't figure it out by Monday (I'll be out of town until then), we can try adding me as a temporary admin and see if I can set them up.
     
    AzzidReign likes this.
  17. AzzidReign

    AzzidReign Well-Known Member

    Ok, so one of my admins mentioned to put the "members-2" at the bottom of the code so that way those that do have secondary usergroups will properly show up in those usergroups in the stats. I'll see how it works. If it works, I'll put up my final code for everyone to check out and if you want to edit your original one you can (since I just modified the original async code xf comes with, which I think you are using the old gA code in yours - the non async).
     
    Live Free likes this.
  18. ProCom

    ProCom Active Member

  19. AzzidReign

    AzzidReign Well-Known Member

    I think I forgot to readd it when we upgraded our skin a while ago. I've been so busy that I haven't put much time into Analytics lately. But iirc, the code I provided, with the minor code change mentioned in my last post, worked great.
     
  20. DBA

    DBA Well-Known Member

    This has become invaluable in the reports, I'd suggest at least trying it as it lets you really drill down your visitors.
     

Share This Page