One of those things is getting Google Analytics to track traffic from multiple domains to one single Analytics account. Basically, Google Analytics works on a per-domain basis, mainly because it stores information in cookies. These cookies are in turn limited to one top-level domain.
Google Analytics provides native support for cross-domain tracking, but if you for some reason are to implement it on a big, existing site, it is quite a chore really. Why? Well, because it requires you to 'tag' each link in each and every document with onclick="pageTracker._link(this.href);" and form button with onclick="pageTracker._linkByPost(this);" inline in the HTML source. Now, if your site is built using a CMS, the chances for the site's HTML being spread across numerous templates are high.
Depending on the size of the site, this often isn't a viable or economic option.
Automation
The reason for not wanting to tag each link and form button manually can certainly vary, but the solution is the same—make a JavaScript to do the job for you. Or even better, use an existing one like the 'Automatic Link Tagger Script' written by the guys over at Analytics Market.
Complete the wizard, follow the instructions and download the generated script. Quite easy, really. However, it didn't work out of the box on my first try. The wizard's instructions state that the generated script snippet should be placed in the <head> section of the HTML. That rendered the script useless, as it made an attempt to tag all links and form buttons before the DOM was ready.
The working version
So, the final, modified and working version of the script looks like this on the multi-domain site which is using jQuery:
In the <head> section:
<script type="text/javascript" src="/js/linktagger.js"></script>
<script type="text/javascript">
var linkTagger = new _olt('ga.js');
linkTagger.setCrossDomains('one.com|two.com|three.com');
linkTagger.setTagDownloads(true);
linkTagger.setTagOutbound(true);
linkTagger.setTagMailto(true);
//linkTagger.setTestMode(true);
</script>
Right before </body>:
<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-12345678-1");
pageTracker._setDomainName('none');
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
pageTracker._trackPageview();
} catch(err) {}
$(function(){
linkTagger.tag();
});
</script>
Why can't I comment on this shait?
Comment posted 01. Feb at 10.33 PM by Hein Haraldson Berg