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 gaq_push GA事件跟踪语法的前缀(原谅我,如果我错了),但他们看起来很相似?

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

_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

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发送。这些方法是不可互换的,它们属于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.