Upcoming LunaMetrics Seminars
Boston, Oct 6-10 Chicago, Oct 20-24 Seattle, Nov 3-7 New York City, Nov 17-21

Custom Variables, Part III: Slots

This is the third post (at long last) in a series about custom variables. We’ve already written about why to use custom variables and how the code works. This last part is about a subtlety of how custom variables operate called “slots”.

Slots and Scope

You’ll remember from Part II that the “slot” or “index” is the first argument in the _setCustomVar function, and we glossed over it at the time because it deserved a whole post of its own.

You can think of the slots like little mailboxes to Google Analytics. You write the name/value pair on a slip of paper and stuff it in the hole, and the Google Analytics mailman pulls it out the other side and notes down the value. There are 5 slots, numbered 1-5, and each slot can only hold one slip of paper at a time.

“So,” you might say, “that means I can have 5 custom variables, right?”

Well, not exactly, because remember each variable has a scope: visitor-, session-, or page-level. Each one of these works slightly differently.

With a page-level variable, the Google Analytics mailman takes the slips of paper out of the box on every page. The boxes are empty again, and available for you to put another slip of paper in on the next page.

With a session-level variable, the Google Analytics mailman takes the slips of paper out of the box at the end of a visit. You are allowed to put a new piece of paper in the slot, but you have to throw the old slip away first.

With a visitor-level variable, the Google Analytics mailman takes the slip out, writes down the value, and puts the slip back in the box (it stays in the __utmv cookie). Again, you can put a new piece of paper in, but you have to throw the old slip away first.

In any slot, the last value recorded wins.

OK, that was a nice story. Just the executive summary, please.

So what’s the upshot here?

  • You can reuse a slot on different pages for a page-level variable.
  • If you reuse a slot for a session- or visitor-level variable, the last value wins. So make sure you really, truly want to overwrite the slot when you’re doing this. Sometimes this makes sense (someone changes status from “member=gold” to a “member=platinum”). Mostly, you want to dedicate a slot to each mutually exclusive session- or visitor-level variable.
  • You should always put variables with the same key in the same slot. You don’t want “member=gold” appearing in 2 different slots, or worse yet, “member=gold” in slot 1 and “member=platinum” in slot 2.
  • The most important lesson is that managing the way the variables is stored is up to you. If you have a complicated situation with lots of variables, make sure you create a chart of slots and scopes to keep track of it all.

Knowing the slots

Being aware of the slots is important, even if you throw this over the fence to your developer and assume they can sort it out. The reason that slots are important is that, to use a custom variable in an Advanced Segment (or in cross-segmentation in reports, or Custom Reports), you need to know what the slot is:

Custom Variable selections for Advanced Segments

Learning more

The Google Code site has some fairly good documentation on custom variables. But the very best thing you can do is watch this webinar in which Phil Mui (the product manager for Google Analytics) walks through exactly how these things work. Straight from Phil to you; it doesn’t get better than that when you want to know something about how GA works.

Jonathan Weber

About Jonathan Weber

Jonathan Weber is the Data Evangelist at LunaMetrics. He spreads the principles of analytics through our training seminars all over the East coast. The next seminar he'll be leading will be a Google Analytics training in Boston. Before he caught the analytics bug, he worked in information architecture. He holds a Master’s degree from the University of Pittsburgh School of Information Sciences. Jonathan’s breadth of knowledge – from statistics to analysis to library science – is somewhat overwhelming.

http://www.lunametrics.com/blog/2010/07/23/custom-variables-part-iii-slots/

8 Responses to “Custom Variables, Part III: Slots”

Jordi says:

What if two visitor level variables are stored in the same slot. Which is reported? The last to enter the slot or both of them?

Jonathan Weber Jonathan says:

If you overwrite visitor (or session) variables in the same slot, the last one wins for the session. (Note that this is different from the old User Defined field, in which the first value for the session won.)

Hi, I’m working on the Mxit platform & would like to create and capture some custom variables to store in Google Analytics.

With Mxit portals, it’s not the usual communication between browser & web server. It’s phone app, mxit server, web server. Mxit sits in the middle, which means we can’t directly capture user specific info.

Mxit does however set custom headers with additional user info, which can be captured for Analytics via custom variables.

We can’t make use of javascript, so I’ve installed the Analytics for mobile php script, which creates and appends data to the gif image.

I’ve set the custom variables on a normal website via javascript and using GA debug I copied the utme parameter and added it to the GA for mobile php code to append to manually append to the gif query string.

Here’s a quick, over simplified example:

The custom values I’d like to set.

$id = $headers['mxitID'];
$country = $headers['country'];
$gender = $headers['gender'];
$age = $headers['age'];

and here I’m appending to the gif query string

&utme=8(MxitID*Country*Gender*Age)9($id*$country*$gender*$age)11(1*1*1*1)

The way I understand it, 8() represents the custom variable names, 9() represents the custom variable values and 11() represents the scope.

It’s been 2 days now, and still no custom variable information in Google Analytics.

I’m checking Visitors > Custom Variables

Any help would be appreciated.

Kind regards,
Charlie Murder

maria says:

Great guide! There is just one thing I really don’t understand.
Is the slot/index the same as the 5 keys that I see on Google Analytics?
If I set the slot/index to 4 does this mean that I will have to click on custom variable key 4 on analytics to see it? Then why don’t they use the word slot instead of key in google analytics? this is just confusing.

Jonathan Weber Jonathan Weber says:

Maria — yes, slots 1-5 correspond to those same numbers. The terminology is definitely a little muddy. Each “slot” has both a “key” and a “value”. So “slot” 1 might have a “key” of eye color and a “value” of blue. Does that help?

Nigel says:

You sound like you know what you’re talking about so I was wondering if you could help diagnose the issue I’m having with my custom variables? I’ve asked the question on Stack Overflow but not a lot of response so far. http://stackoverflow.com/questions/16005910/google-analytics-custom-variables-wont-track any ideas?

Nigel — If you’re seeing the custom variable data in the GIF request to Google Analytics (and I think that you were saying you are), the code is working correctly. If you’re not seeing the data appear in reports, the problem is on the processing side. A couple of suggestions: (1) make sure you’re not trying to view the data in a profile that might filter out the test data (removes internal traffic, removes certain URLs including the page with the variable, etc.); (2) sessionized data like custom variable data is usually somewhat delayed from the basic pageview data. So you probably don’t want to be looking in the current day for testing data to appear (or at least, you can’t be sure that just because your test pageview has showed up, the custom variable will already be there as well).

The custom variable documentation talks about a ‘slot matrix’. Does this mean I can track a visitor-, session-, and page-level variable all in the same slot? i.e. if I set a visitor-level variable in slot 1, and later a session-level variable in slot 1, what will I end up with?