Sharepoint 2010 & Google Analytics

Discovered that you can set a custom variable in Google Analytics to the ID of the Sharepoint user (that’s ID, not Name) :

This is the tracking code I used. The important part here is the _gaq.push([‘_setCustomVar’ line. We can use the Sharepoint JS variable _spUserId:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
		1,         // This custom var is set to slot #1.  Required parameter.
		'User',    // The name of the custom variable.  Required parameter.
		_spUserId, // This is the Sharepoint JS variable _spUserId. Required!
		2          // Sets the scope to session-level.  Optional parameter.
  (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);

Don’t forget to change the UA string from


to the value for your site!