XF 1.2 Google Analytics [Sub-Domain]?

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:
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>
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:
Code:
<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"));
</script>
<!--- The part below seems like the bit I need to add to the template -->
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-4XXXXX-XXX");
  pageTracker._setDomainName("bonusfeber.no");
  pageTracker._trackPageview();
} catch(err) {}
</script>
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?

Thanks,
-Bill
 
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:

Rich (BB code):
<xen:if is="{$requestPaths.host} == 'subdomain.yoursite.com'">

<xen:else />

</xen:if>
 
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,
-Bill
 
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.
 
I figured it out.. It was right in front of me..

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

Easy Peasy :-)
 
Back
Top Bottom