Friday, July 10, 2009

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:

image

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:

<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("YOUR_WEB_PROPERTY_ID");
pageTracker._setDomainName("none");
pageTracker._trackPageview();
} catch(err) {}</script>
Bookmark and Share  Comments [4] | Permalink | GoogleAnalytics | SharePoint
Thursday, July 23, 2009 7:52:49 AM (Mountain Daylight Time, UTC-06:00)
Como colocar o codigo do Google Analytics no sharepoint??
How to put the Google Analytics code in sharepoint?
Thursday, July 23, 2009 5:44:48 PM (Mountain Daylight Time, UTC-06:00)
Rafael,
Please refer my previously-published post for details on how to add Google Analytics to your SharePoint site:
Add Google Analytics to a SharePoint Publishing Site
Monday, December 07, 2009 9:57:48 AM (Mountain Standard Time, UTC-07:00)
Hi,
I am trying to implement GA with our single name url e.g http://intranetdev. Firstly, i cannot add this url in goolge analytics (with add new profile) so i dontget the tracking code.

Can you tell me the steps u followed.

Thanks in advance
isha
Thursday, January 07, 2010 6:45:09 PM (Mountain Standard Time, UTC-07:00)
Isha,
Try just adding something to the name when you create the profile e.g. intranetdev.com or just use the company's domain name you are doing the work for. You can include the tracking code in any site after you've created the profile - it won't break because your site really isn't what the profile "says" it is.

Leave a Comment

Name (required)
Email (will not be published)
Website
 

Comment Preview
Subscribe
Top 5 Posts
Add Google Analytics to a SharePoint Publishing Site
Integrating jQuery 1.3, ASP.NET 3.5 Visual Studio 2008
Add Custom Table Formats to SharePoint Content Editor
Configuring log4net for SharePoint Windows Authentication
Convert Visual Studio 2008 Class Library Project to Web Application Project
Tags
ASP.NET (5) dasBlog (5) GoogleAnalytics (2) jQuery (1) log4net (2) SharePoint (18) WebDesign (3)
 
 
 
Spreadfirefox Affiliate Button
 
Download Notepad++