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

XF 1.1 User Defined in Google Analytics with Xenforo

Discussion in 'XenForo Questions and Support' started by AzzidReign, Mar 31, 2012.

  1. AzzidReign

    AzzidReign Well-Known Member

    It seems like only some metrics come up in this page for us and wondering how I can get all the variables to show up. Basically I want to break it down Members/Logged in vs. Guests on the site. I have over 1 million undefined on this page and only ~1k+ for guests, with even less stats for everything else. I want to know how I can get this properly working so I can track members vs guests. Has anyone done this successfully?
     
  2. AzzidReign

    AzzidReign Well-Known Member

    After looking at it a little more, xF uses async code and is a little different than what I'm seeing in some google examples. It looks like something like this needs to be added:
    Code:
    _gaq.push(['_setCustomVar',
          1,                // This custom var is set to slot #1.  Required parameter.
          'Member Type',    // The name of the custom variable.  Required parameter.
          'Premium',        // The value of the custom variable.  Required parameter.
                            //  (possible values might be Free, Bronze, Gold, and Platinum)
          1                // Sets the scope to visitor-level.  Optional parameter.
    ]); 
    And needs to be added to:
    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 2 things are confusing me. 1) Where do I put the custom var code. 2) How to set up the "required parameter" properly for Premium members, Regular members, and Guests.

    I'm thinking it may have to look like this (if someone how knows could confirm?):
    Code:
    <xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
     
        var _gaq = [['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}'], ['_trackPageview']];
            _gaq.push(['_setCustomVar',
          1,                // This custom var is set to slot #1.  Required parameter.
          'Member Type',    // The name of the custom variable.  Required parameter.
          'Premium',        // The value of the custom variable.  Required parameter.
                            //  (possible values might be Free, Bronze, Gold, and Platinum)
          1                // Sets the scope to visitor-level.  Optional parameter.
    ]);
        !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>
     
  3. DBA

    DBA Well-Known Member

    You ever figure this out?

    Was going to check out some stats in Google Analytics only to realize that I'd forgotten to (re)implement this after switching to XF. VBSEO did do other things besides just SEO. ;)
     
  4. DBA

    DBA Well-Known Member

    Ok did a little research and think that this might work:

    HTML:
    _gaq.push(['_setCustomVar',
          1,
          'Usergroup',
    <xen:if is="{xen:helper ismemberof, $visitor, 1}">
          'Unregistered-1',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 2}" />
          'Registered-2',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 3}" />
          'Administrator-3',
    <xen:elseif is="{xen:helper ismemberof, $visitor, 4}" />
          'Moderator-4',
    </xen:if>
          1
    ]);
    I've added it to my site, guess we'll see what happens. :D
     
    AzzidReign likes this.
  5. AzzidReign

    AzzidReign Well-Known Member

    No I never did figure it out after my initial attempt. It went to the way side. Let me know if it does report for you with this set up. Thanks.
     
  6. DBA

    DBA Well-Known Member

    Learner likes this.

Share This Page