
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.
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.
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:
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.
[...] veroorzaken, wat ik al eens eerder tegenkwam op het google support forum. (setvar…? “hoe gebruik ik setvar” op [...]