Wednesday, October 5, 2011

Setting up Google Analytics for intranet sites

More and more websites are using Google Analytics since the services provides valuable insights to site traffic, marketing effectiveness, user conversions and the fact that it is free of charge and easy to set up.

Last day while trying to set up Google Analytics for a customer on a their intranet site, we detected that no statistics were sent to Google Analytics for the users that were using Internet Explorer, luckily this was quickly detected since IE is the prominent browser in the customer organization.

In the case of this particular intranet site(and most other intranet sites for that matter), the customers can simply navigate to the site without explicitly typing the domain name of the site, e.g. http://intranetsite, since the site is a member of the local domain.

This browser specific problem is apparently caused because of a cookie restriction in IE for hosts-addresses that does not contain a fully qualified domain name(FQDN).

The Google Analytics documentation states the requirement that all sites must use a FQDN, in order to successfully register statistics. However for our customer this was not an option, also both Firefox and Chrome where able to successfully register statistics without using a FQDN.

The solution to this browser specific problem is to explicitly set the domain name to 'none' in the Google Analytics tracking script:

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXX-1']);
_gaq.push(['_setDomainName', 'none']); //explicitly set the domain name to 'none'

(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


After this minor update all major browsers were successfully able to register statistics for the site using both the FQDN version and the shorter version of the site address.

This teqnique is also useful for setting up Google Analytics on a site that runs on your local computer, perhaps during development or maybe just to play around with Google Analytics.

1 comment :