Get more than 5 custom variables in Google Analytics

A few months ago Google Analytics released an awesome new feature – Custom Variables.

If you’re new to custom variables, you should read the official Google help page:
http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html

And check out the webinar they did recently:
http://www.youtube.com/watch?v=UmQTfqmoSyk

While custom variables are great – you only get 5 of them, or so Google says. There is an undocumented feature that basically gives you as many custom variables as you want. It’s as simple as setting the number of maximum custom variables as you want to use. Here is the Google Analytics function to use:

[important update July 2, 2010]
Omar brought to my attention that when drilling down via the standard GA interface, when you pick a custom variable after the 5th one (in order that is was set, not in the order on the interface) you get an error saying:

An Error Has Been Detected
Please try again. Thank you for your patience.

My gut tells me that this is ONLY an issue with the interface and that internally the data is still being recorded, but I can’t know for sure.
In any case it seems that from a functional standpoint creating more than 5 custom variables is fairly limited since currently you can only see the variable names and not the values for slots 6 and up.

pageTracker._setMaxCustomVariables(10);

The above code sets the maximum number of custom variables to 10.

Here is some complete code that shows you can use all ten custom variables. I tried this myself and it works :)

<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXXX-1");

pageTracker._setMaxCustomVariables(10);

pageTracker._setCustomVar(1,'visitor_var_1','visitor_value_1',1);
pageTracker._setCustomVar(2,'visitor_var_2','visitor_value_2',1);
pageTracker._setCustomVar(3,'visitor_var_3','visitor_value_3',1);
pageTracker._setCustomVar(4,'visitor_var_4','visitor_value_4',1);
pageTracker._setCustomVar(5,'visitor_var_5','visitor_value_5',1);
pageTracker._setCustomVar(6,'visitor_var_6','visitor_value_6',1);
pageTracker._setCustomVar(7,'visitor_var_7','visitor_value_7',1);
pageTracker._setCustomVar(8,'visitor_var_8','visitor_value_8',1);
pageTracker._setCustomVar(9,'visitor_var_9','visitor_value_9',1);
pageTracker._setCustomVar(10,'visitor_var_10','visitor_value_10',1);

pageTracker._trackPageview();
</script>

I haven’t yet tested the limit of how many custom variables you can have, but keep in mind that Google Analytics has a limit of 2048 characters for the entire tracking request so there is a limit.

Also, just a reminder that custom variables are limited to 64 characters in length for the name and the value.

Here is a screenshot which shows the results of the example above:

The “first_touch” custom variable in the screenshot above is set on a different page.

Let me know if you have any questions.

Ophir

About these ads

About Ophir Prusak

Web Analytics and Optimization Expert

26 Responses to “Get more than 5 custom variables in Google Analytics”

  1. Hey Ophir,

    Very cool thing that you found there. I wonder if that is going to be removed any time soon or will be available forever.

    • I don’t work for Google so obviously I can’t say for sure, but from past experience, I highly doubt it will go away any time soon and I’m willing to bet it will still be there in a year from now.

      The cool thing is that even if they do decide to change the maximum number of custom variables in the future, whatever data is already in your Google Analytics account will still be there.

  2. That is a great post… I will add your blog to my blogroll :-)

  3. Hi Ophir,

    I personally see this as the natural evolution of GA vs other variable’d WA solutions such as Omniture or YWA.

    The function has been in ga.js for a while now and I doubt they’ll remove it.
    Worst case scenario, they’ll deprecate it and allow you to implement as many as you want (within cookie/pixel URL limitations of course.)

    Hope to see you and the gang in Mountain View this Fall!

    Best,

    Julien

  4. Hi,
    I’ve followed your blog and added another 4 custom variables to a site. The problem is that now no custom variables show up in analytics! i’ve waited around 2 hours for it to pick the new variables.

    Do you know how long Google takes to respond to new Custom Variables? or have I done something wrong.

    cheers
    Darrell

    • Hi Darell,

      Custom variable data can sometimes take a while to show up in your account.
      It’s usually within 24 hours, but I’ve seen a few instances where it was more like 36 hours.

      Keep in mind that you *will* see visit data *before* seeing custom variable data for the same time frame.
      I know this is very confusing but apparently the custom variable data is analyzed after the main visit data.

  5. Hi Ophir,
    Thanks for the advice. I was seeing the visitor data but not the custom variables.
    I wrongly assumed that if the visitor data was getting through then the custom variable data should be coming through at the same time.
    I’ll check again on Monday :)

    Thanks again

  6. Hi Ophir,

    I want to point out that while you are able to get more than 5 custom variables, anything not in the first 5 slots are unable to be drilled down on.

    just letting you know

    • Hi Omar,

      I just tried drilling down via the standard GA interface and it seems you are indeed correct. When I tried to drill down on the custom variables after the 5th one (in order that is was set, not in the order on the interface) I get an error saying:

      An Error Has Been Detected
      Please try again. Thank you for your patience.

  7. Great stuff Ophir and thanks for sharing.

    In the GA webinar on youtube it’s also been suggested that they will increase the number of custom vars at some point. I guess it’s just about making public what you have found out yourself already. Reminds me of the workaround to export more lines of data than the supposed limit of 500 rows.

    Michael

    • Hi Michael,

      Yes, I’m guessing they’ll do something like what they did with the goals increase a while back. I just realized though that currently you can’t get the values for slots 6 and up in the interface, so the functionality is fairly limited for now.

      I’m a big fan of your work BTW :)

  8. Is this still working for you, Ophir? I’ve checked my code with Firebug but the sixth _setCustomVar() doesn’t get sent with the other five. I’m using the async code, if that makes any difference.

    Thanks!

    • Yes, it’s still working for me, though I’m NOT using the async code.

      You can see it working on my test page at:
      http://www.prusak.com/cust_vars/set-max-custom-var-test.html

      And here is the utme value (I added line the line breaks):
      8(visitor_var_1*visitor_var_2*visitor_var_3*
      visitor_var_4*visitor_var_5*visitor_var_6*
      visitor_var_7*visitor_var_8*visitor_var_9*
      visitor_var_10)9(visitor_value_1*
      visitor_value_2*visitor_value_3*
      visitor_value_4*visitor_value_5*visitor_value_6*
      visitor_value_7*visitor_value_8*visitor_value_9*
      visitor_value_10)11(1*1*1*1*1*1*1*1*1*1)

  9. Thanks, Ophir. My data has just started to come into my GA account after 48 hours or so, but the sixth slot is not coming in. It appears that this does not work with the async GATC.

  10. Thanks a lot for this pretty interesting tip :-)

    I “only” use customvars in advanced segments and custom reports + API.
    => did anyboby find a way to use additional customvars in that way? (for example tweaking the code of the creation form thanks to Firebug or a Grasemonkey script…)

    I’m a bit short on tech skills to code the solution, but this should be possible ;-)

  11. Very interesting post and discussion, thanks guys.

    I’m still a little confused about whether there is a workaround to be able to implement and report on more than 5 custom variables. Are there any working workarounds out there or is there still the limitation of only being able to access the first 5 variables in the reporting interface?

    • Implement and send to Google more than 5 CVs – Yes
      See the CV *names* in GA beyond the 5th CV – Yes
      See the CV *values* in GA beyond the 5th CV – No

      Which makes me wonder why they created the setMaxCustomVariables function …

      • First off thanks for sharing this info with us! Just one question, are the custom variables over index 5 still usable as filters even though I cant “see” their values?

      • How can I implement “pageTracker._setMaxCustomVariables(10);” with new GA versions?

        ——————————-
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-21115022-1']);
        _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); })();

  12. Just remember that you can only specify a maximum of 8 dimensions on queries to the Google Analytics Data API and that includes built-in ones like “source” and “medium”, so although you can set 10 or more, you can never retrieve them all in one valid data feed.

  13. My GOD thank you for this. It’s something that we have been having difficulties overcoming for a while, and seems like an elegant solution to the 5 custom variable limit. We’ll try it!

  14. How to overcome from limit on using 20 custom matric and dimension in google analytics?

Trackbacks/Pingbacks

  1. Segments, Segments Everywhere « Kraft T Thoughts - May 26, 2010

    [...] has already identified a number that are not automatically tracked by vendors.  The number can be increased but then there is the implementation limitation that GA shares with many vendors including Omniture [...]

  2. Google Analyticsで6つ以上のカスタム変数を利用する裏技 | MaxMarketing.jp | MaxMarketing.jp - November 12, 2010

    [...] Impactという海外ブログで紹介されている。”Get more than 5 custom variables in Google Analytics” (Google [...]

  3. Mythbusters on Web Analytics #1: The _setMaxCustomVariables | Conversion Garden - May 21, 2012

    [...] Here comes the discovery of the existence of a “bug” or forbidden feature, the _setMaxCustomVariables option by Ophir Prusak. [...]

  4. 6個以上のカスタム変数を使う裏技 | 解析の原則 - January 2, 2013

    [...] Impactという海外ブログで紹介されている。”Get more than 5 custom variables in Google Analytics” (Google [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 67 other followers

%d bloggers like this: