为什么我的Google Analytics自定义变量未记录?

时间:2022-09-15 15:52:13

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

我正在尝试为Google Analytics设置5个自定义变量,如下所示:

<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.

我认为我在调用trackPageView之前添加了不超过5个自定义变量来遵循所有规则,但它们仍未显示在Google Analytics中。

1 个解决方案

#1


5  

Possibilities:

  • Custom Variables can lag behind _trackPageview's showing up in the GA UI. (Source #1)
  • 自定义变量可能落后于GA UI中显示的_trackPageview。 (来源#1)

  • If you're using ga_debug.js you can see in your console what's firing back. (Source #2)
  • 如果你正在使用ga_debug.js,你可以在你的控制台中看到什么是回击。 (来源#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)
  • 您正在使用CustomVar(2)接近自定义变量长度128。由于这是测试数据,请确保您的实际数据不会过去。 (来源#3)

  • Eduardo is right that the 0 vs "0" is causing CustomVar(3) to not fire. (Source #2 & Testing)
  • Eduardo是对的,0 vs“0”导致CustomVar(3)无法触发。 (来源#2和测试)

  • _trackPageLoadTime is deprecated (Source #2+3 & Testing)
  • 不推荐使用_trackPageLoadTime(来源#2 + 3和测试)

Links/References:

  1. Mastering Google Analytics Custom Variables
  2. 掌握Google Analytics自定义变量

  3. Google Analytics Debugger
  4. Google Analytics调试程序

  5. Official Google Analytics Custom Variables Documentation
  6. 官方Google Analytics自定义变量文档

Updated Snippet in Demo Page for Debugger:

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

(从不是localhost或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>

#1


5  

Possibilities:

  • Custom Variables can lag behind _trackPageview's showing up in the GA UI. (Source #1)
  • 自定义变量可能落后于GA UI中显示的_trackPageview。 (来源#1)

  • If you're using ga_debug.js you can see in your console what's firing back. (Source #2)
  • 如果你正在使用ga_debug.js,你可以在你的控制台中看到什么是回击。 (来源#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)
  • 您正在使用CustomVar(2)接近自定义变量长度128。由于这是测试数据,请确保您的实际数据不会过去。 (来源#3)

  • Eduardo is right that the 0 vs "0" is causing CustomVar(3) to not fire. (Source #2 & Testing)
  • Eduardo是对的,0 vs“0”导致CustomVar(3)无法触发。 (来源#2和测试)

  • _trackPageLoadTime is deprecated (Source #2+3 & Testing)
  • 不推荐使用_trackPageLoadTime(来源#2 + 3和测试)

Links/References:

  1. Mastering Google Analytics Custom Variables
  2. 掌握Google Analytics自定义变量

  3. Google Analytics Debugger
  4. Google Analytics调试程序

  5. Official Google Analytics Custom Variables Documentation
  6. 官方Google Analytics自定义变量文档

Updated Snippet in Demo Page for Debugger:

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

(从不是localhost或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>