Google Analytics setVar() deprecated and replaced by setCustomVar()

Other December 7th, 2009 @ 15:12

For a while, there’s been a possibility to separate your users in various segments in Google Analytics, by setting a (single) variable in the Analytics cookie, for example:

pageTracker._setVar("member-premium-true");

Earlier this year, Google introduced the neat possibility to use multiple custom variables, allowing more customization and flexibility. You are allowed to use five slots (1-5) and set a name, value and scope to your variable.
The old setVar method has been deprecated and replaced by the new setCustomVar:

pageTracker._setCustomVar(
      1,                // This custom var is set to slot #1
      "Member Type",    // The name of the custom variable
      "Premium",        // The value of the custom variable
      1                 // Sets the scope to visitor-level
 );
pageTracker._trackPageview();

This isn’t really news, but it wasn’t obvious what had happened by just looking at the Google Analytics API docs, so I thought I’d mention it here just to “spread the word”.

<script type="text/javascript">
				pageTracker._setVar('member-premium-true');
			</script>