koosa
koosa

Reputation: 3040

Why are my Google Analytics custom variables not recorded?

I'm trying to set 5 custom variables for Google Analytics like so:

<script>
    //<![CDATA[
    var _gaq=[["_setAccount","UA-XXXXXXXXX-X"],["_trackPageLoadTime"]];
    _gaq.push(['_setCustomVar', 1, 'categories', 'News', 3]);   
    _gaq.push(['_setCustomVar', 2, 'tags', 'something, another, passbook, iphone, ipod, ios6, insider, egift, more things, some other stuff', 3]);  
    _gaq.push(['_setCustomVar', 3, 'productcount', 0, 3]);  
    _gaq.push(['_setCustomVar', 4, 'isvideo', 'false', 3]);
_gaq.push(['_trackPageview']);

(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));
//]]>

</script>

I think I've followed all the rules by adding no more than 5 custom vars before the call to trackPageView, but they still don't show up in Google Analytics.

Upvotes: 3

Views: 1171

Answers (1)

TomFuertes
TomFuertes

Reputation: 7270

Possibilities:

  • Custom Variables can lag behind _trackPageview's showing up in the GA UI. (Source #1)
  • If you're using ga_debug.js you can see in your console what's firing back. (Source #2)
  • You're bumping up close to the Custom Variable length of 128 with the CustomVar(2). As this is test data, make sure your real data doesn't go over. (Source #3)
  • Eduardo is right that the 0 vs "0" is causing CustomVar(3) to not fire. (Source #2 & Testing)
  • _trackPageLoadTime is deprecated (Source #2+3 & Testing)

Links/References:

  1. Mastering Google Analytics Custom Variables
  2. Google Analytics Debugger
  3. Official Google Analytics Custom Variables Documentation

Updated Snippet in Demo Page for Debugger:

(serve from something that's not localhost or file://)

<html><head><title>Demo</title><script>

var _gaq=[["_setAccount","UA-XXXXXXXXX-X"]];
_gaq.push(['_setCustomVar', 1, 'categories', 'News', 3]);   
_gaq.push(['_setCustomVar', 2, 'tags', 'something, another, passbook, iphone, ipod, ios6, insider, egift, more things, some other stuff', 3]);  
_gaq.push(['_setCustomVar', 3, 'productcount', '0', 3]);  
_gaq.push(['_setCustomVar', 4, 'isvideo', 'false', 3]);
_gaq.push(['_trackPageview']);
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));

</script></head><body><h1>Open your console</h1></body></html>

Upvotes: 5

Related Questions