If you have a website that uses or links to multiple sub-domains then you will find this information helpful. To clarify what I mean by using multiple sub-domains here are a couple examples:
-
A site whose content/static pages are on “www.mydomain.com” but their store is on a sub-domain of “store.mydomain.com”
-
A site whose main site is “www.mydomain.com” but they partner with a 3rd party service for internal search and uses a domain of “search.mydomain.com” to display search results to consumers
-
A site who has implemented a blog on a sub-domain of “blog.mydomain.com” that is interlinked with their primary domain of “www.mydomain.com”
If your website is similar or fits into one of the examples above, then keep reading. [more]
Google Analytics provides instructions from their FAQ as follows (http://www.google.com/support/googleanalytics/bin/answer.py?answer=55524&topic=11009)
Add the following line (in bold) to the tracking code on all pages of your subdomain and your main domain:
<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">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._setAllowHash(false);
pageTracker._setDomainName(".example.com");
pageTracker._trackPageview();
</script>
This line should reference the primary domain (example.com).
However, after implementing the above you may encounter eCommerce tracking issues as we did with one of our clients. From researching Google Groups on this topic, we found that there are possibly a few more lines of code that may be necessary (in bold):
<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">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._setAllowHash(false);
pageTracker._setDomainName(".example.com");
pageTracker._trackPageview();
</script>
After implementing the above as well as the necessary eCommerce transaction tracking scripts, we were able to solve the problem and get eCommerce tracking working properly.
Google FAQs can sometimes be confusing and not very helpful when problems arise. Use other resources like Google Groups and forums and blogs to help solve these problems.
Contact us if you need assistance with eCommerce problems/issues like this as it could save you days of trial & error adjustments.