jquery - ga 或 _gaq.push 用于 Google Analytics 事件跟踪?

标签 jquery events google-analytics tracking

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

非常简单,但是哪种语法最有效?

我研究了 GA 事件跟踪语法的 gagaq_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/

相关文章:

google-analytics - 如果有人引用了我网站上的图片,Google Analytics 会计算访问次数吗?

r - 无法通过 googleAnalyticsR 导出超过 1000 行

javascript - 选择特定下拉项时使用 jQuery JSON 函数填充文本区域

javascript - jQuery .draggable() 不拖动或拖动太多卡片

javascript - 切换播放/暂停按钮(多个音频)

javascript - 处理焦点事件时触发点击

c# - (扩展图标栏 - chrome 浏览器)我们可以通过 selenium web 驱动程序自动执行此开/关操作吗

javascript - 引用错误: is not defined : localStorage

Laravel Livewire Echo 配置

javascript onclick事件,同一元素的每次点击都有不同的功能