我试图在单击按钮时跟踪呼叫电话事件。我的 GA 代码是从设置向导中提供的。<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id={{site.google_analytics_tracking_id}}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '{{site.google_analytics_tracking_id}}'); </script>我的按钮代码是:<!-- Banner --><section id="banner"> <div class="inner"> <header> <h2>{{ site.title }}</h2> <figure> <picture class="image logo"> <span class="icon logo fa-balance-scale"></span> </picture> <figcaption><small>Serving: {{ site.location }}</small></figcaption> </figure> </header> <p><strong>We Work Hard To Protect Your Rights!</strong></p> <footer> <ul class="buttons stacked"> <button class="button fit">Call: <a href="tel:{{site.tel}}" onClick=”ga('send', 'event', 'Calls', 'clicked', 'Contact Office', 1);”>{{site.tel}}</a></button> </ul> </footer> </div></section>投票请对问题投赞成票或反对票。在否决投票之前,建议编辑或发表评论?
1 回答
![?](http://img1.sycdn.imooc.com/54585094000184e602200220-100-100.jpg)
墨色风雨
TA贡献1853条经验 获得超6个赞
您已经通过 gtag.js 实现了 GA,您用于 onClick 的函数用于 analytics.js,因此您需要使用正确的函数。您需要以这种格式执行此操作:
gtag('event', <action>, {
'event_category': <category>,
'event_label': <label>,
'value': <value>
});
所以对于你的例子:
gtag('event', 'clicked', {
'event_category': 'Calls',
'event_label': 'Contact Office',
'value': 1
});
添加回答
举报
0/150
提交
取消