Google Analytics Issue
April 7, 2009
I am working on a project, where there is:
- the main website (http://examplewebsite.com)
- a subdomain (http://sub.examplewebsite.com), and
- a blog (http://examplewebsiteblog.com).
I want to throw Google Analytics onall three sites and get them working together.
From the Google Analytics documentation, it illustrates what needs to be done to add the code in situations like this. The coding is below.
In this scenario, you might want to enable tracking across a given domain and its sub-domains, and include a separate domain in the mix. For example, suppose you have an online store and you also want to track visitor and campaign data to your blog. The following shows key tracking code customizations for three example URLs.
- Primary:
www.example-petstore.comvar pageTracker = _gat._getTracker("UA-12345-1"); pageTracker._setDomainName(".example-petstore.com"); pageTracker._setAllowLinker(true); pageTracker._setAllowHash(false);In addition, you would use the
_link()and_linkByPost()for any form or links towww.my-example-blogsite.com. This is not required for links to the sub-domain of this site, since the_setDomainName()function defined.example-petstore.comas the domain to enable cookie access for any other subdomains.- Secondary:
dogs.example-petstore.comvar pageTracker = _gat._getTracker("UA-12345-1"); pageTracker._setDomainName(".example-petstore.com"); pageTracker._setAllowLinker(true); pageTracker._setAllowHash(false);In addition, you would use the
_link()and_linkByPost()for any form or links towww.my-example-blogsite.com. as well as to the primary domain.- Terciary:
www.my-example-blogsite.comvar pageTracker = _gat._getTracker("UA-12345-1"); pageTracker._setDomainName("none"); pageTracker._setAllowLinker(true); pageTracker._setAllowHash(false);
So for the main website I added this 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>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8230059-1");
pageTracker._setDomainName(".examplewebsite.com");
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
_link();
_linkByPost();
pageTracker._trackPageview();
} catch(err) {}</script>
For the subdomain I added this 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>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8230059-1");
pageTracker._setDomainName(".examplewebsite.com");
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
_link();
_linkByPost();
pageTracker._trackPageview();
} catch(err) {}</script>
And for the blog I added this 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>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8230059-1");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
pageTracker._trackPageview();
} catch(err) {}</script>
The code is pulling, but incorrectly. The main website is the blog, and nothing is pulling from the main website or the subdomain. I feel I am missing something with the _link() and _linkByPost(), but just not sure.
So are there any Google Analytics Masters out there that can shed some light on this issue?
Leave a Reply
You must be logged in to post a comment.