by Doug

20/02/2014

Internet Marketing

Google Analytics Premium and Google Tag Manager – setting multiple custom variables

Summary:

Setting custom variables with Google Tag Manager (GTM) is really neat and simple.

Setting multiple custom variables is a common requirement especially when using Google Analytics Premium (GAP).

Setting a selection of custom variables based on values found in the dataLayer is an interesting challenge. Having tested this behaviour there are some really tidy behaviours that can be exploited to achieve a clean GTM implementation.

Here’s the results of some testing we’ve done.

Use case

Your site has multiple pages grouped by section, type and author. Users browsing you site might be logged in, existing customers or may have subscribed to your newsletter.

Each pageview by each visitor on the site can be decorated with varying and sometimes large amounts of meta data.

Not all meta data points are always present. At most you may choose to set say, twenty custom variables in one go.

Can you?

This documentation suggests you’re going to have problems: Google Custom Variable Documentation.

You’ll either have problems setting more than 5 custom variables of each type in a __utm.gif hit or the total length of the custom variable name and value pairs will exceed 128 characters.

Have a look at this brute of a tag:

These custom variable settings are part of the standard pageview tag. Running a test on the page we can see the utme part of the __utm.gif request looks like this:

utme:8(30!testcv30*testcv31*testcv32*testcv33*testcv34*testcv35*
testcv36*testcv37*testcv38*testcv39*testcv40*
textcv41*testcv42*testcv43*testcv44*testcv45*testcv46*testcv47*testcv48*
testcv49)9(30!multitest30*multitest31*
multitest32*multitest33*multitest34*multitest35*multitest36*multitest37*
multitest38*multitest39*multitest40*
multitest41*multitest42*multitest43*multitest44*multitest45*multitest46*
multitest47*multitest48*multitest49)
11(30!2*1*1*1*1*1*44!2*2*2*2*2*2)

So far so good. Thats 468 characters by the way…

What does the data look like?

Results

Well, 7 minutes later (Hurrah for data freshness on GAP!) we see these reports (long scroll – sorry):

So….yes. they all got set.

What if these custom variable values were pulled from the dataLayer though? If they’re not present, they don’t get set. Simple solution!

I expected a value of (not set) (as seen using this method for Universal Analytics custom dimensions) or undefined but this was happily not the case.

Conclusions

The technique is strong and seemingly reliable through GTM. Using this in a production environment requires much more thorough testing but these results seemed worth sharing so far.

Comments

Leave a comment

Your email address will not be published. Required fields are marked *