ga 或 _gaq.push 用于 Google Analytics 事件跟踪? [英] ga or _gaq.push for Google Analytics event tracking?

查看:23
本文介绍了ga 或 _gaq.push 用于 Google Analytics 事件跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想跟踪网站页面上按钮的 onclick,在条件通过后检查是否存在 cookie.

I would like to track an onclick of a button on a page on a site, after a condition is passed checking if a cookie is present.

非常简单,但哪种语法效果最好?

Very simple but which syntax would work best?

我研究了 GA 事件跟踪语法的 gagaq_push 前缀(如果我错了,请原谅我),但它们看起来非常相似?

I have researched the ga and gaq_push prefix of the GA event tracking syntax and (forgive me if I'm wrong) but they seem pretty similar?

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

ga

<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 send.这些方法不可互换,它们属于两个不同版本的 Google Analytics(分析)跟踪代码.

If you use ga.js ("traditional" asynchronous code) you have to use _gaq.push. If you use analytics.js you need to use ga send. The methods are not interchangeable, they belong to two different versions of the Google Analytics tracking code.

现在(2017 年)有一个新的代码版本 (gtag.js),所以如果你正在使用它,你既不使用 ga 也不使用 _gaq.push 而是使用按照迁移指南将您的代码更新到最新版本(或者您非常明智地开始使用 Google 标签管理器).

By now (2017) there is a new code version (gtag.js), so if you are using that you use neither ga nor _gaq.push but instead follow the migration guidelines to bring your code up to the latest version (or you quite sensibly start to use Google Tag Manager).

这篇关于ga 或 _gaq.push 用于 Google Analytics 事件跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆