In the Fall of 2009, Google announced the release of the much anticipated Custom Variables in Google Analytics. Previously the only out of the box way to segment visitors on your site using custom metrics was to use the User Defined variable. While the User Defined method was useful for segmenting traffic into members vs non members, and for things like Michael’s Exact Keyword Tracking script, Analytics users requested more options, customizations, and more control. Well, Google listened.

Unlike the User Defined variable, the Custom Variables allow you to determine the scope of the visitor engagement. Basically that means in addition to setting just a visitor level segment, you can also set session level segments, which will persist while the visitor is active on the site, and page level segments, which correspond to pageviews and events on the site. This allows you to get much more detailed with the information you’re gathering and storing in the custom variable. For example, you could separate different sections of the site by using the page level scope, or you could track if a visitor has completed a particular action during their session with the session level scope.

The Custom Variables function accepts four parameters: Index, Name, Value, and Scope.

  • Index – The index refers which custom variable you are currently using. You can only set up to 5 separate custom variables within a single pageview (or event), and this number references which of those 5 you wish to use.
  • Name – Sets the name of the variable.
  • Value – Sets the value of the custom variable.
  • Scope– This is what sets the scope of the visitor segment. 1 (visitor-level), 2 (session-level), or 3 (page-level).

Now for an example. Here is the code template for a custom variable:

Custom Variables in Google Analytics

_setCustomVar(index, name, value, scope)

And here’s what it looks like when I fill in my member tracking information:

pageTracker._setCustomVar(1, “MemberType”, “Paid”, 1);

Notice that the setCustomVar() function comes before the trackPageview(). The information is only sent to Google Analytics during a pageview or an event, so keep that in mind when placing the code on your site.

Now I’ve set a custom variable on a visitor level that segments visitors into a paid membership category. How do I find this information in my Google Analytics account? Under the Visitors section in the left navigation click on ‘custom variables’ and you’ll see a list of the names of the custom variables you’re using on your site. Click on the names to drill down into the values of each of these variables.

For more information on how to set up custom variables and some additional examples on when you might use them, check out the Google Code article.

Looking for more ways to use Google Analytics reports? Here’s 3 Google Analytics reports that will help you uncover conversion opportunities.