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

XF 1.2 Google Analytics [Sub-Domain]?

Discussion in 'XenForo Questions and Support' started by Bill.D, Feb 5, 2014.

  1. Bill.D

    Bill.D Active Member

    Hey all,

    I have a Xenforo install on a subdomain andI am trying to track the main site and the subdomain. I found online how to alter the analytics code to do it but it doesn't quite match what I am seeing in the Google_Analytics Template:
    <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>
    This seems to bee the traditional insert and not they asynchronous versions. So here is the code I found for the tradition which seem similar:
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    <!--- The part below seems like the bit I need to add to the template -->
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-4XXXXX-XXX");
    } catch(err) {}
    The part from the middle down seems like what I need to add the the part above does quite match. SO I guess my question is: Can I just add that bottom Part? Or is there another way completely to do this?

  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You want different analytics on your subdomain versus main domain? I don't understand the analytics part of it, but you can use a template conditional like this to output different code depending on the host portion of the URL:

    <xen:if is="{$requestPaths.host} == 'subdomain.yoursite.com'">
    <xen:else />
  3. Bill.D

    Bill.D Active Member

    Hey Jake,

    Thanks for this.. Forgive my ignorance but, do I just put those 3 lines able the code in the google_analytics Template?

    Just to clarify, the main site is bonusfeber.no and the xenforo install is at forum.bonusfeber.no. So I want it to count the forum activity under the main site bonusfeber.no.

    Thanks again,
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That template condition is just a tool which might apply to your situation. I don't understand the adsense part of it so I cannot provide exact instructions. The question is, what adsense changes need to be done for what you want? Then the template conditional might be useful.
  5. Bill.D

    Bill.D Active Member

    I figured it out.. It was right in front of me..

    You take this line:
    var _gaq = [['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}'], ['_trackPageview']];
    And you add this to it:
    ['_setDomainName', 'bonusfeber.dk']
    So it should look like this:
    var _gaq = [['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}'], ['_trackPageview'], ['_setDomainName', 'bonusfeber.dk']];
    Easy Peasy :)

Share This Page