【问题标题】:Google Analytics Event Tracking onClick CodeGoogle Analytics 事件跟踪 onClick 代码
【发布时间】:2021-11-10 04:52:15
【问题描述】:

我正在尝试在我的网站上设置事件跟踪,但无法正常工作。

我的跟踪代码:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-420xxxxxxx', 'mywebsite.org');
  ga('send', 'pageview');

</script>

我的事件跟踪代码:

<a href="#PurchasePanelLink" class="uk-button uk-button-primary" onClick="$('#PurchasePanel').show(); _gaq.push(['_trackEvent', 'Button', 'Click', 'Purchase Details',, false]);">Purchase Details</a>

【问题讨论】:

    标签: google-analytics


    【解决方案1】:

    您将经典代码与通用代码混合在一起。不起作用。你需要替换这个:

    _gaq.push(['_trackEvent', 'Button', 'Click', 'Purchase Details',, false]);
    

    有了这个:

    ga('send', 'event', 'Button', 'Click', 'Purchase Details');
    

    事件的 GAJS 参考:https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation

    【讨论】:

    【解决方案2】:

    可以使用 send 命令发送事件命中。根据新的analytics.js

    语法:

    ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
    

    例如,如果您想跟踪购买事件

    ga('send', 'event', 'Button', 'Click', 'Purchase Details');
    

    这里:-

    eventCategory 是按钮。必填字段,其值类型为文本

    eventAction 是点击。必填字段,其值类型为文本

    eventLabel 是购买详情。它是可选字段,它的值类型是文本

    eventValue 为空。它是可选字段,它的值类型是整数

    【讨论】:

      【解决方案3】:

      看起来您使用的是新的 analytics.js 而不是 ga.js,因此您需要使用正确的事件跟踪方法集:

      ga('send', 'event', 'category', 'action');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-22
        • 2017-03-04
        • 1970-01-01
        • 1970-01-01
        • 2016-11-07
        • 1970-01-01
        • 2014-09-21
        • 2023-04-10
        相关资源
        最近更新 更多