A couple of days ago I get in a small issue working on a google analytics account and the referrers showed into the traffic sources. GA was showing the domain monitored as a traffic source without no apparent reason.

Google AnalyticsAfter a bit of investigation, the problem has been identified. The web site was serving its contact module with an SSL protocol under a subdomain.
The problem wasn’t the SSL Certiicate nor the subdomain; the webmaster was simply unaware that subdomains are treatead as different entities into the web analytics platform unless they are instructed to do the opposite.

The solution that will follow is extremely simple, but to being completely sure I asked the opinion to a friend of mine, Marco Cilia that manage GA in 30 seconds (a GA Italian blog).

The solution you need for case like this is very simple: all you need is one line of code into the GA tracking script for all your pages for both the main and subdomain website.

A normal GA code looks like this

try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-1");
pageTracker._trackPageview();
}
catch (err) { }

that you must change into

try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-1");
pageTracker_setDomainName(“.yourdomain.tld”);
pageTracker._trackPageview();
}
catch (err) { }

Basically introducing the following line pageTracker._setDomainName(“.yourdomain.tld”);

This will make every sub domain (www, subdomains) part of the same account, thus preventing any entry into the referrers’ list. In addition the pages of the subdomain will be merged into the account, so you will have access to information like page length, bounce rate and so on.

You need to make the changes in all domain / sub-domains that you want to track as a single entity. This is because the Analytics creates an encoded value of the domain specified by the parameter passed into _setDomainName(), and if the parameter is not identical across all domains, you will get conflicts and unexpected reporting behaviors.

It must be noticed that GA is a cookie based system; this mean that until the previous visitors’ cookie expires, you may continue to see your domain as a referrers entry. Based on my experience this should only last for between 7 and 14 days, but sometimes it takes a little longer.

Technorati Tags: google analytics, domains, tracking
Share and Enjoy:
  • Print
  • email
  • Digg
  • Facebook
  • Twitter
  • del.icio.us
  • Segnalo
  • LinkedIn
  • StumbleUpon
  • FriendFeed