New Multiple Custom Variables in Google Analytics
Amid all the other information you can gather about a visitor and his visit, the ability to add dimensions unique to your site makes the reports more actionable.
Having a single user-defined variable in Google Analytics has long been a sore point for users. Google recently announced the rollout of multiple custom variables to every account. This addition can dramatically change the kind of analysis users can do with Google Analytics.
Multiple custom variables can be scoped to a visitor (as has always been the case) or just to a visit or even a page. They are very flexible and can be adapted to almost any scenario.
How to Create Custom Variables
_setVar() method has been deprecated in favor of
_setCustomVar(). This new method accepts four arguments: slot, name, value and scope. Because the variables are sent in the __utm.gif request, they must be set before
_trackPageview() or before an event is fired on a page.
This code would create this visit-level variable in slot 1: "visit type=prospect".
These are stored in a cookie. Once created, they last for as long as the visitor's cookies last, or until they are overwritten. If multiple visitor-level variables are set to the same slot during a visit, the last one set will be reported. They do not apply retroactively to previous visits.
These apply to the current visit. If a visit-level variable is assigned to a slot being used by another variable (regardless of its scope), it will be overwritten. If multiple visit-level variables are assigned in the same visit to the same slot, the last one set will be reported.
These apply to the current page. Five page-level variables may be set simultaneously on a page. If any other type of variable is assigned during a visit to the same slot as a page-level variable, the page-level won't be reported.
Limits to Multiple Custom Variables
Anything can be added as a custom variable name or value. However, every name-value pair is limited to 64 characters.
Also, because there are only five variable slots available, there is a limit to the number of custom variables that can be set in a visit. Once a slot has been used during a visit, care must be taken not to overwrite that variable later during the visit.
As a rule of thumb, each slot in a visit is reported independently. If multiple variables are assigned to the same slot during a visit, the last visit-level variable will be reported.
- If no visit- or visitor-level variables are used on a site, every page can have five variables with different name-value pairs.
- A visit-level variable is assigned to slot 1. Later during the visit, a visitor-level variable is assigned to slot 1. The visit-level variable will be reported. Any subsequent visits will be attributed to the visitor-level variable because it's still stored in the cookie.
- During the same visit, a page-level variable and a visit-level variable are assigned to slot 1, in any order. The visit-level variable will be reported. The page-level variable will not, regardless of whether it was reported last.
Using More Than Five Variables
An undocumented function within the ga.js library actually allows you to raise the limit from five custom variable slots. Just pass the function an integer representing the maximum number you want to set.
The only limitation to this seems to be the fact that the entire __utm.gif request cannot exceed 2048 characters.
Because of these limitations with scope and quantity, the best practice is to decide ahead of time what types of segments you need to track on your site. From there, break them down by scope. Then assign each slot a scope, and never use it for anything but that type of variable.
For example, a company might decide to reserve slot 1 for visitor-level variables, slot 2 for visit-level variables and slot 3 for page-level variables. They may use slot three to set a variable for every single page, but they would know that slots 1 and 2 could only be used sparingly. If the company decided they needed multiple variables of the same scope, they would assign slots 4 and 5 accordingly.
To use these variables to their fullest, it is best practice to give each variable a broad name that could hold any number of values, instead of a binary value. For example, instead of creating a variable for "registered user" with a value of "yes" or "no", create a variable named "user type" with values like "registered", "prospect", etc.
How Multiple Custom Variables Are Reported
Multiple custom variables can be found in a new report under visitors, labeled "Custom Variables". (Data from using the
_setVar() method will still appear under the "User Defined" report.) Each slot is reported independently. So, if the same variable name is used for multiple slots in a visit, they will report separately.
Each variable shows how many visits included it at some point. Clicking on the variable name in the reports will bring up a table of values. These are values that were assigned to that variable name during visits.