Solving the ‘direct (direct)’ conundrum with subdomains and Google Analytics’ Ecommerce code
(By Tom on 21 December 2008 | Posted in Announcements)
Since launching Bannerflow this fall, we’ve been using Google Analytics for tracking Bannerflow’s performance.
We ran into a problem when tracking the ecommerce aspects of the site across our subdomains — we weren’t able to accurately track the sources of our revenue. In fact, each time a transaction occurred, the source was showing as direct (direct). We knew something was up.
We examined the cookies that Google Analytics was writing to our browsers and we noticed that each time we were sent to our ecommerce subdomain — app.bannerflow.com — a new, separate cookie was being written. This was the root of what was causing our problem.
After hours and hours, we found out the solution to our problem. All we had to do was remove the period (.) that preceeded the domain name within the Google Analytics tracking code function setDomainName. So instead of “.bannerflow.com” we used just “bannerflow.com”. This differs from Google’s documentation. Here’s how our code looked once the edit was made:
<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._setDomainName("bannerflow.com");
pageTracker._trackPageview();
</script>
(Note: this is what worked for our particular setup, which includes an implementation of Apache and other server configurations. We’re not yet sure why the method outlined in Google’s documentation doesn’t work with our configuration, but the method outlined above does.)