Analytics Market Chart

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

There is new JavaScript to create multiple custom variables. The _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.

There are five slots available per visit. A variable must always be assigned to slot 1 through 5. All five slots can be assigned on a single page.
Names can be any series of letters, numbers or symbols. Best practice is to keep names concise, but there is no need to make them cryptic.
Values can be any series of letters, numbers or symbols. Best practice is to keep values concise, but there is no need to make them cryptic.
Scope is an optional parameter, indicated by a number. 1 indicates a visitor-level variable. 2 indicates a visit-level variable. 3 indicates a page-level variable. If no parameter is supplied, the variable defaults to page-level.

This code would create this visit-level variable in slot 1: "visit type=prospect".

pageTracker._setCustomVar(1, "visit type", "prospect", 2)

Creating multiple variables on a page would just be a matter of calling this JavaScript once for each variable and passing the appropriate parameters.

Visitor-level variables

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.

Visit-level variables

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.

Page-level variables

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.


  1. If no visit- or visitor-level variables are used on a site, every page can have five variables with different name-value pairs.
  2. 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.
  3. 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.

Best Practices

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.