Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm having some trouble to make GA Custom variables work on my website. After following all the tutorials, seeking documentation, debugging with Firebug, I cannont understand what is wrong with my code...

Here is the test page I wrote, to have a very targeted test case:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Custom variable test</title>
    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-13048570-1']);
    </script>
</head>
<body>
    <script type="text/javascript">
        _gaq.push(['_setCustomVar',1,'pageName','testCustomVar']);
        _gaq.push(['_setCustomVar',2,'secondCustomVar','testValue']);
    </script>
    <h1>Hello on my custom variable test!</h1>
    <script type="text/javascript">
        _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>
</body>

My problem is that the custom variables never reach Google Analytics. I've installed the Google Analytics debugger found here (http://www.keithclark.co.uk/labs/google-analytics-debugger/) for Firefox; and when submitting my page, it shows me that two custom variables are set but the name and value are empty; despite the fact that the generated GIF has utme parameter inline (utme 8(pageName*secondCustomVar)9(testCustomVar*testValue)).

http://www.google-analytics.com/__utm.gif?utmwv=5.4.6&utms=4&utmn=1361447983&utmhn=www.tadefig.com&utme=8%28pageName*secondCustomVar%299%28testCustomVar*testValue%29&utmcs=UTF-8&utmsr=1536x864&utmvp=1536x402&utmsc=24-bit&utmul=en-us&utmje=0&utmfl=11.9%20r900&utmdt=Custom%20variable%20test&utmhid=1348157758&utmr=-&utmp=%2Fcustom%2F&utmht=1386931051245&utmac=UA-13048570-1&utmcc=__utma%3D223162654.24701012.1386929812.1386929812.1386929812.1%3B%2B__utmz%3D223162654.1386929812.1.1.utmcsr%3D%28direct%29|utmccn%3D%28direct%29|utmcmd%3D%28none%29%3B&utmu=qQ~

I really have no more ideas why this is not working.

share|improve this question

migrated from stackoverflow.com Dec 16 '13 at 16:47

This question came from our site for professional and enthusiast programmers.

1  
I removed my obviously dumb answer (the scope parameter is even called opt_scope in the docs, which is kind of a giveaway :-) ). So next question would be, how long did you wait ? Custom vars are one of those things that take between 4 to 48 hours to appear (if you account has more then 200 000 hits per day it will be updated only once a day according to documentation), so the info might not be processed yet. –  Eike Pierstorff Dec 13 '13 at 14:43
    
I just tough a little bit about that ; and indeed ; when almost every data is available very quickly, it seems that custom variables do have a certain lag... So, next step will be to create a new test case with a unused slot, on an unused page, and test again... –  Romain VDK Dec 16 '13 at 15:30
    
Can you please provide the URL of our site? Also, I would recommend you to set the scope of each Custom Variable call (although it's an optional parameter). –  Yaniv Navot Sep 11 at 6:22

1 Answer 1

I'm honestly not sure why your implementation isn't working properly, but just wonder if its more to do with Google Analytics having changed how they work to now use what they call Universal Analytics, where instead of calling ga.js scripts now call analytics.js and Dimensions and Metrics have to be pre-configured in Google Analytics and assigned a numerical index each, e.g. dimension0, dimension1, dimension2 (not renamable) for text values, or metric0, metric1, metric2 etc for numerical values.

Read Google Developers: Google Analytics - Custom Dimensions and Metrics for more information.

<html><head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Custom variable test</title>
</head><body>
  <script type="text/javascript">
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r,i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create','UA-13048570-1','auto');
  ga('send','pageview','dimension0','testCustomVar');
  ga('send','pageview','metric0',55.3);
  </script>
  <h1>Hello on my custom variable test!</h1>
</body>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.