Using setVar (_utmsetvar / utm_setvar) for custom segmentation

Having a pie and eating it!

SetVar (for older versions utm_setvar or _utmsetvar) is a function in the Google Analytics javascript code that allows you to set a custom segmentation rule. GA already offers a set of standard segmentations, as well as more advanced segmentation techniques in the reports interface, but setVar (_utmsetvar / utm_setvar) allows you to take a slice from your traffic before the reports and apply the segmentation options available in the reporting. This kind of custom segmentation gives you an extra dimension and more freedom to interpret the data through the reports.

Tags set for setVar in the code will appear in the report Visitors > User Defined.

Uses of setVar  ( _utmsetvar  / utm_setvar)

SetVar can be set to tag specific(entry) pages, but also values from a registration form, e.g. “job title”, which would show the values set for this item in your registration form. This will enable you to figure out how each of these visitor segments behave on the site (and possibly use this knowledge to adjust your marketing strategies).

Although setVar is primarily used for custom segmentations, it can also be used for page variation testing. When testing different page variations, usually multiple versions of a page are served to the user and by tagging each variation with a different setVar version you can find out which version converts better. This functionality is an example of how setVar can be applied creatively, aside from what it was intended for when it was built into the GA code. If you regularly use A/B or Multivariate testing, a better option would be using Google Web Optimizer.

Another hack for setVar custom segmentation is adjusting the javascript code to trigger setVar after a set amount of time (usually seconds), which allows you to work with data for just those users who didn’t bounce off the site upon entry.

Finally, you can also use setVar to segment users that click on particular links on your site.

How does setVar work?

When setVar is used to tag specific pages (or page variations), it can be set within the normal Google Analytics code and should look like this for the updated ga.js code:

<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(”UA-XXXXXX-X”);
pageTracker._trackPageview();

pageTracker._setVar(”tag_value”);
} catch(err) {}</script>

Should you still be using the old urchin.js code, the adjusted code should look like this:

<script src=”http://www.google-analytics.com/urchin.js”
type=”text/javascript”></script>
<script type=”text/javascript”>
_uacct = “UA-12345-1″;
urchinTracker();

__utmSetVar(”tag_value”);
</script>

(N.B. – The examples use the standard GA code, without any adjustments which may have been made on your site already!)

Alternatively, you can make the following calls anywhere on the web page as long as it’s positioned below the GA tracking code and as long as you’re using the updated ga.js code:

  • General: <script type=”text/javascript”>pageTracker._setVar(’tag_value’);</script>
  • As part of the body tag: <body onLoad=”javascript:pageTracker._setVar(‘tag_value’);”>
  • When a link is clicked: <a href=”link.html” onClick=”pageTracker._setVar(’Marketing/PR’);”>Click here</a>

Should you want to use setVar to segment visitors based on values used in your registration form, you should follow this example:

<form onSubmit=”pageTracker._setVar(this.examplemenu.options
[this.examplemenu.selectedIndex].value);”>
<select name=examplemenu>
<option value=”Technical/Engineering”>
Technical/Engineering</option>
<option value=”Marketing/PR”>Marketing/PR</option>
<option value=”Manufacturing”>Manufacturing</option>
<option value=”General Management”>General Management</option>

As with the separate setVar calls described above, using setVar for form options requires you to set the GA tracking code ABOVE the form in the web page’s code in order for the function to work properly.

Notes on the use of setVar

  1. IMPORTANT: If you decide to use setVar on any popular entry pages to your site you will notice the site’s bounce rate plummeting. If bounce rate is an important measure/KPI for you, you should carefully consider the use of setVar. Bounce rate is defined by GA as being a single “hit” to the server but no further “hits” (visitor left site), however, since setVar places a second “hit” to the server, GA automatically assumes that there is no bounce when there actually is one 
  2. SetVar is cookie based, which means you can use setVar only once on the site, otherwise value in cookie will be overwritten by second instance. In other words: This method of segmentation is not multidimensional, although further segmentations can be applied within the reports using the Advanced segmentation builder, for example. There are workarounds, such as John Henson’s method.
  3. The data collected through setVar is expressed in visits, in the reports – the tag is applied to the user only once during a visit session.
  4. Tags set for setVar are stored in the user’s __utmv cookie, which is set by Google Analytics. That means that GA will pick it up setVar when the visitor returns by default. If you don’t want that to happen you can set utmv to NULL once the visitor ends the session (leaves the site), so that the next visit will start with a clean sheet for setVar.
Bookmark and share!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • Furl
  • NewsVine
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
  • LinkedIn
  • MySpace


One Response to “Using setVar (_utmsetvar / utm_setvar) for custom segmentation”

  1. [...] veroorzaken, wat ik al eens eerder tegenkwam op het google support forum. (setvar…? “hoe gebruik ik setvar” op [...]

Leave a Reply