This weekend David Eckman of VKI Studios sent me an email about RIAForge. His company makes frequent use of RIAForge, and as a provider of Google Analytic implementation services, he wanted to let me know about a problem with the way I had set up the code.
RIAForge makes use of multiple, dynamic root URLs. So you have the main URL (http://www.riaforge.org) and multiple, dynamic project URLs (http://blogcfc.riaforge.org for example). My Analytics codes was not set up properly to handle multiple domains.
I had trouble finding the exact way to generate the right code via Google's interface, but luckily David sent me the mod directly. Here is the old 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">
var pageTracker =
_gat._getTracker("UA-70863-8");
pageTracker._initData();
pageTracker._trackPageview();
</script>
And the modified version, note the line that sets the domain, third from the bottom:
<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-70863-8");
pageTracker._setDomainName("riaforge.org");
pageTracker._initData();
pageTracker._trackPageview();
</script>
Since these guys make their money from this type of advice, I want to thank VKI Studios once again. They were also very cool with me blogging this.
Archived Comments
Ray, what exactly does adding that line accomplish, in the statistics that are tracked? It sounds like it could be something I've been trying to figure out for a client. Could you provide some sort of sample of the data or the way the data is filtered before and after the change?
Oh sorry - I should have explained it better. It treats *.riaforge.org as ONE domain. This means I won't have referers to www.riaforge.org from blogcfc.riaforge.org for example.
By default Google will set a first party cookie to the full domain that you are accessing.
For example, if you were accessing blogcfc.riaforge.com, that's what the cookie would be set to. Then, when you change to something else like farcry.riaforge.com, Google will set a new cookie to that domain.
Unfortunately the side affect of this is that each time a new cookie needs to be set, GA considers you a new user/visitor.
By adding the line of code I gave to Ray, that allows GA to set the cookie at the root domain, which all the sub-domains can access and results in you being tracked as an individual user, in one GA profile, across all the sub-domains.
There is also an option available if you want to track people across totally different domains as well.
Thanks to both Ray and Dave. I had no idea this sort of option existed and I've since done some googling (ironic?) and found the documentation.
What I need to do is aggregate statistics across distinct domains, which I haven't found to be explicitly listed as possible in the docs, but I'm going to try the method for tracking users across domains and see how that works out for me.