Enable Google Analytics Page Tracking in a Single-Name Intranet Site

Recently I’ve been asked how to get Google Analytics working in an intranet site with a single name in the URL, for example: http://intranet. The first time I added Google Analytics to a site it was a development site accessed by server-name:port-number. For days after correctly adding the tracking code there was still no data showing up in the Google Analytics dashboard reports.

Turns out the fix required adding one simple JavaScript call to a Google JavaScript API function. When adding Google Analytics tracking code to a site with a single name in the URL you need to call _setDomainName(“none”) prior to making the call to _trackPageView:


By default the Google Tracking Code snippet provided in the Google Analytics Profile Settings uses the “auto” domain name mode which expects to see a fully-qualified domain name (FQDN) composed of the domain name, followed by a period, followed by the domain extension (.com, .net, .biz, etc.). Setting the domain name to “none” disables the FQDN requirement and will record your pages in Google Analytics the same as a site with a FQDN.

I have deployed this fix with success to both a SharePoint 2007 Team Site and Publishing Portal site available only by a single name URL and port number. In both cases the site data was not showing up in Analytics until I added the call to set the domain name to “none”. It’s critical that you call _setDomainName before calling _trackPageView for this change to have any effect.

As with all changes to JavaScript tracking code it can take up to 24 hours before you see data start showing up in the Google Analytics dashboard reports, and changes only apply going forward so there’s no way to recover clicks from before you deployed the code change.

Here’s an example of the tracking code with the domain name set to “none”. Replace YOUR_WEB_PROPERTY_ID with the value assigned to your site profile by Google Analytics:

01 <script type="text/javascript">
02 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
03 document.write(unescape("%3Cscript src='" + gaJsHost +
04 "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
05 </script>
06 <script type="text/javascript">
07 try {
08 var pageTracker = _gat._getTracker("YOUR_WEB_PROPERTY_ID");
09 pageTracker._setDomainName("none");
10 pageTracker._trackPageview();
11 } catch(err) {}</script>

Source : http://mikeknowles.com/blog/2009/07/11/EnableGoogleAnalyticsPageTrackingInASingleNameIntranetSite.aspx

Posted in Google Analytics and tagged , , .

One Comment

  1. This is really attention-grabbing, You’re an excessively professional blogger. I have joined your feed and sit up for searching for more of your fantastic post. Additionally, I’ve shared your web site in my social networks

Leave a Reply