On my website I have four custom variables. My issue is that Google Analytics for some reason is only registering three of them. The script on the page that is not working properly looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setCustomVar',3,'Category 3','some value']);
_gaq.push(['_setCustomVar',4,'Category 4','some value']);
_gaq.push(['_setAccount', 'UA-XXXXXXXX']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
This page is supposed to track two of the custom variables in index 3 and 4. Another page is tracking custom variables in index 1 and 2.
In Google Analytics I can see that it has registered the categories in the first three slots (Index 1-3) but the category in the fourth slot never gets registered. According to the documentation you can have up to five slots.
Can anyone shed any light on why the fourth variable never gets registered?
Update
Inspecting the utme variable in the analytics request provided some interesting results.
Page 1, which is working, uses the following tracking script:
_gaq.push(['_setCustomVar',1,'Category 1','value1']);
_gaq.push(['_setCustomVar',2,'Category 2','value2']);
This results in the following utme parameter:
8(Category 1*Category 2)9(value1*value2)
Page 2, which is NOT working, uses the following tracking script:
_gaq.push(['_setCustomVar',3,'Category 3','value3']);
_gaq.push(['_setCustomVar',4,'Category 4','value4']);
This results in the following utme parameter:
8(3!Category 3)9(3!value3)
It’s clearly ignoring the last custom value that I’m trying to track!
I had trouble getting this to work too and ultimately it was a case of not reading the document carefully enough.
Not sure if you’re posing the actual code you’re using for setting your variables, if not, make sure you’re in compliance with this warning:
The total combined length of any custom variable name and value may not exceed 128 bytes. Keep in mind that this is not equivalent to 128 characters. Because names and values are URI encoded when stored, some characters use more than one byte. For example, = is stored as %3D rather than = and uses 3 bytes rather than 1. To get a list of URI encoded values, search the web for URL encoding reference.
Have you checked the other recommended practices? These two might be a source of problems for you (if you’re using session variables too):
Do not use duplicate key names across slots.
You have up to 5 simultaneous custom variables for use in a single request (e.g. pageview or event call).
The sum of all your custom varaiables cannot exceed 5 in any given request (i.e. you cannot have 5 visitor and 5 session custom variables set simultaneously).