在Google Analytics.js事件跟踪发送中使用.Net变量

时间:2014-10-23 21:02:44

标签: javascript c# .net google-analytics universal-analytics

我正在尝试使用由变量后面的代码设置的标签来发送事件跟踪值。这一切都在页面上正确呈现,但是,它实际上并不跟踪这些事件。动态事件不会显示在事件区域下的GA中,但硬编码的“下载”事件会显示。

如果我试试这个,只有第一个“下载”事件在GA中显示:

$('#DownloadButton').on('click', function () {
      var s1 = "<%= Var1 %>";
      var s2 = "<%= Var2 %>";
      var s3 = "<%= Var1 %> | <%= Var2 %>";

      ga('send', 'event', 'button', 'click', 'Download');

      //these next variable labels never are received in GA
      ga('send', 'event', 'cat1', 'v1', s1);
      ga('send', 'event', 'cat2', 'v2', s2);
      ga('send', 'event', 'cat3', 'both', s3);

});

如果我将服务器变量内联,那么“下载”和Var1会被发送,但不是最后两个:

$('#DownloadButton').on('click', function () {

      ga('send', 'event', 'button', 'click', 'Download');
      ga('send', 'event', 'cat1', 'v1', "<%= Var1 %>");

      //these last two never get received by GA
      ga('send', 'event', 'cat2', 'v2', "<%= Var2 %>");
      ga('send', 'event', 'cat3', 'both', "<%= Var1 %> | <%= Var2 %>");

});

它似乎在点击“&lt;%= Var1%&gt;”结束后中断。

Var1是一个名为“Gala Apple”的名称,并在页面上正确呈现:

ga('send', 'event', 'sheet', 'Side1', "Gala Apple"); 

1 个答案:

答案 0 :(得分:0)

GA在chrome商店中有这个工具:

https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en

它允许您查看发送到GA服务器的内容。要使用它,请打开chrome,启用调试器,然后在开发人员工具中打开控制台选项卡。当您加载页面并触发事件时,它应将它们记录到窗口。

如果您在点击#DownloadButton时观看它,它应该会对正在发生的事情有所了解。我的猜测是,它没有到达那些行,因为你的按钮附加了另一个click处理程序,它改变了页面位置,或者做了一些停止执行的事情。由于js是单线程的,取决于它需要多长时间,它可能会在完成发送其他跟踪信标之前离开页面。