Using Google Analytics with SharePoint intranet site


Ever wanted to use Google Analytics on an intranet site, particularly one hosted with SharePoint? Well it’s dead easy – you follow the same instructions that you would for any web site. Just copy and paste the generated JavaScript code into the master page of your site. This will work, but there are some caveats so read on.

As long as the user has internet access

Google Analytics works by having the user’s browser execute some JavaScript code. Of course this code is hosted on Google’s servers and sends data back to these servers. So it doesn’t matter that your website is an intranet site, as long as the person viewing it has access to both the internal website (der!) and the Google Analytics servers.

The geography stats will be a bit warped

Google Analytics is a great tool to show you where in the world your visitors are coming from. If you’re using it on an intranet site then you probably won’t end up with the same detailed results (even if you have a multi-national company). It all depends how your internal get access to the internet. Depending on the size and geographic spread of your organisation you might have 1 or hundreds of connections to the internet. These connections from the inside to the outside world is what will appear in the stats. For example if you have 200 users in the Sydney office but they all share one outbound internet connection, the Google machine will do it’s best to determine the location of the external IP address of that connection and will just show that on the map. Well makes sense in such a simple scenario – all the users are in the one office!

But imagine if it gets a bit more complicated and you have users all over the country but they all access the internet via just 1 or 2 connections (for security reasons, cost reasons, crazy network admin reasons, whatever), then you’re only going to see ‘location’ for each external IP address that shows when your users are accessing the internet.

Remember it takes a few hours before your stats will appear

This is the same as for any web site, be patient before worrying that the code hasn’t been installed correctly. If you can View –> Source on the generated page and find the source code it should all be working.

You might have to fudge the internal URL to add a new site

The UI Google Analytics doesn’t seem to accept URLs without a . in them, so http://sharepoint isn’t going to work. You might have to fudge it to http://sharepoint.internal or use the fully qualified domain name anyway. I don’t think this matters, the generated JavaScript uses a specific tracking ID and I believe this is all that is needed for the JavaScript code to identify the site it is running on, it doesn’t actually look at the URL. Please correct me if you think this is wrong.

Do you really want to do this?

Sure Google are trustworthy, they once pledged to do no evil remember? But just think carefully about the security implications of having an internal user execute externally hosted JavaScript on your intranet or other internal website. Not only that, but will the Google Analytics service be around forever or at least as long as you need it? So it might not be the long term solution for you. Or it could just be the quick and dirty solution you need for some basic usage analytics.

You won’t get any SharePoint specific stats

Google Analytics doesn’t know anything about SharePoint and won’t treat it any differently to a normal website. So you’re not going to get any special stats on number of documents uploaded, number of content types in use, disk storage, most active users etc. For something like that you will have to fork out dollars and use a product like Nintex Reporting.

But I don’t have access to the master page

You can still try this if you don’t have access to the master page, as long as you can add a web part to a web page. Simply add a Content Editor Web Part, edit the Source of the web part and paste the Google generated JavaScript. Make sure to make the web part hidden – this ensures the user doesn’t see the ‘Content Editor Web Part’ title, but the code is still included in the page.


I’d love to hear of your success or wrangling with Google Analytics on internal websites, particularly SharePoint. Leave me a comment below.