简体   繁体   English

analytics.js脚本调整

[英]analytics.js script adjustment

I have this script which works together with Analytics Asynchronous ga.js. 我有这个脚本,可与Analytics Asynchronous ga.js一起使用。

<script>
(function (tos) {
  window.setInterval(function () {
    tos = (function (t) {
      return t[0] == 50 ? (parseInt(t[1]) + 1) + ':00' : (t[1] || '0') + ':' + (parseInt(t[0]) + 10);
    })(tos.split(':').reverse());
    window.pageTracker ? pageTracker._trackEvent('Time', 'Log', tos) : _gaq.push(['_trackEvent', 'Time', 'Log', tos]);
  }, 10000);
})('00');
</script>

I'm trying to adjust it to Analytics Universal tracking code, analytics.js. 我正在尝试将其调整为Google Analytics(分析)通用跟踪代码analytics.js。

I think most of this script will work for analytics.js, but the line that won't work is this 我认为此脚本的大部分内容都适用于analytics.js,但行不通的是

window.pageTracker ? pageTracker._trackEvent('Time', 'Log', tos) : _gaq.push(['_trackEvent', 'Time', 'Log', tos]);

I'm not sure if the window.pageTracker ? 我不确定window.pageTracker吗? pageTracker._trackEvent part also works for analytics.js. pageTracker._trackEvent部分也适用于analytics.js。 The last part of the line can be changed to ga('send', 'event', 'Time', 'Log', tos); 该行的最后一部分可以更改为ga('send','event','Time','Log',tos); I presume? 我相信?

Would this work in analytics.js? 可以在analytics.js中使用吗? And if not, what should I replace it with? 如果没有,我应该用什么代替它?

window.pageTracker ? pageTracker._trackEvent('Time', 'Log', tos) : ga('send', 'event', 'Time', 'Log', tos);
window.pageTracker ? pageTracker._trackEvent('Time', 'Log', tos) : _gaq.push(['_trackEvent', 'Time', 'Log', tos]);

You see this line in a lot of analytics event tracking tweaks. 您会在许多分析事件跟踪调整中看到此行。

To break it down it means: 分解它意味着:

pageTracker = part of the urchin.js tracking code _gaq.push = part of the ga.js tracking code pageTracker = urchin.js跟踪代码的一部分_gaq.push = ga.js跟踪代码的一部分

The code used in the question was written in April 2011 when people still used the urchin and the newer asynchronous syntax (ga.js). 该问题中使用的代码写于2011年4月,当时人们仍在使用urchin和更新的异步语法(ga.js)。 These days people don't use the urchin code anymore and the line at the top can be written as 如今,人们不再使用urchin代码,顶部的行可以写为

_gaq.push(['_trackEvent', 'Time', 'Log', tos]);

The line at the top means: if you use pageTracker (=urchin) print the code pageTracker._trackEvent('Time', 'Log', tos) and if not use _gaq.push(['_trackEvent', 'Time', 'Log', tos]); 顶部的一行表示:如果使用pageTracker(= urchin),则打印代码pageTracker._trackEvent('Time', 'Log', tos) ,如果不使用_gaq.push(['_trackEvent', 'Time', 'Log', tos]);

If you are using the latest tracking code (analytics.js) you can use: ga('send', 'event', 'Time', 'Log', tos); 如果您使用的是最新的跟踪代码(analytics.js),则可以使用: ga('send', 'event', 'Time', 'Log', tos);

The whole code would look like this: 整个代码如下所示:

<script>
(function (tos) {
  window.setInterval(function () {
    tos = (function (t) {
      return t[0] == 50 ? (parseInt(t[1]) + 1) + ':00' : (t[1] || '0') + ':' + (parseInt(t[0]) + 10);
    })(tos.split(':').reverse());
    ga('send', 'event', 'Time', 'Log', tos);
  }, 10000);
})('00');
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM