Home > Resources > BlogUnleash the Power of Digital Marketing

Essential Insights, Helpful Tips, Topical Advice, and General Musings

All posts

Google Analytics eCommerce Tracking Problems with Sub-Domains

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.

  • Facebook
  • Twitter
  • DZone It!
  • Digg It!
  • StumbleUpon
  • Technorati
  • Del.icio.us
  • NewsVine
  • Reddit
  • Blinklist
  • Add diigo bookmark
  • Furl it!
  • Subscribe RSS
  • Twitter

Comments  2

  • Mark 15 Jun

    What do the initData and setAllowHash arguments do? What is their purpose?
  • Les 06 Jul

    Mark: The "initData()" call initializes or re-initializes the GATC (Google Analytics Tracker Code) object. Keep in mind the ga.js code already does the first initialization however, we didn’t want to take a chance of losing another days worth of ecommerce data so we just re-initialized again to be on the safe side. You may not need this now but you should test it for a day to ensure things are working properly. Regarding the “setAllowHash(false)” function, from a Forum Guru “ShoreTel” he states it “turns off ‘domain hashing’ in the same way that setDomainName("none") does, but without the extra side effect of limiting your cookies to a single subdomain (usefull for cross-subdomain tracking).” Read more about this function from the following URL: http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowHash I hope this helps and sorry I got back to you bit late on this. Best, Les
Post a comment!
  1. Formatting options