我想在通过条件检查 cookie 是否存在后跟踪网站页面上按钮的 onclick
。
非常简单,但是哪种语法最有效?
我研究了 GA 事件跟踪语法的 ga
和 gaq_push
前缀(如果我错了,请原谅我),但它们看起来非常相似?
_gaq.push
<script type="text/javascript">
jQuery(document).ready(function () {
if (jQuery.cookie('entry_winagrand_cookie') !== null) {
jQuery('notregisterbtn').on('click', function () {
_gaq.push(['_trackEvent', 'QR_Win_A_Grand', 'Clicked through to Register']);
});
}
});
</script>
嘎
<script type="text/javascript">
jQuery(document).ready(function () {
if (jQuery.cookie('entry_winagrand_cookie') !== null) {
jQuery('notregisterbtn').on('click', function () {
ga('send', 'event', 'button', 'click', 'QR_Win_A_Grand', 'Clicked_through_to_register');
});
}
});
</script>
最佳答案
如果您使用ga.js (“传统”异步代码)你必须使用_gaq.push。如果您使用analytics.js你需要使用 ga 发送。这些方法不可互换,它们属于 Google Analytics(分析)跟踪代码的两个不同版本。
现在(2017 年)有一个新的代码版本 (gtag.js),因此,如果您使用该版本,则既不使用 ga
也不使用 _gaq.push
,而是使用关注the migration guidelines将您的代码更新到最新版本(或者您非常明智地开始使用 Google 跟踪代码管理器)。
关于jquery - ga 或 _gaq.push 用于 Google Analytics 事件跟踪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18696998/