Google Analytics Premium and Google Tag Manager – setting multiple custom variables
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.
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.
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:
So far so good. Thats 468 characters by the way…
What does the data look like?
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.
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.