简体   繁体   English

Google Analytics(分析)事件跟踪不起作用。 跟踪联系表单7和动态生成的元素

[英]Google analytics event tracking not working. Tracking Contact form 7 and dynamically generated element

Google analytics is working properly on my site for most things. Google Analytics(分析)在我的网站上可以正常工作。 However I have implemented event tracking on two different elements and after testing, GA is not showing the events occur. 但是,我在两个不同的元素上实施了事件跟踪,经过测试,GA并未显示事件发生的时间。 Here is my tracking code: 这是我的跟踪代码:

<script async src='//www.google-analytics.com/analytics.js'></script>
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-xxxxxxxx-1', 'auto');
ga('send', 'pageview');
</script>

The first element I am attempting to track is an element I have generated and inserted with Javascript: 我尝试跟踪的第一个元素是我生成并使用Javascript插入的元素:

$(".tencol.last").append(" <p class='mobile-number'><a class='mobile-number-link' href='tel:555-555-5555'>(555) 555-5555</a></p>");

document.getElementsByClassName("mobile-number-link")[0].setAttribute( "onClick", "ga.push(['_trackEvent', 'mobile-call', 'mobile-phone-number-click']);");

The 2nd element I am attempting to track is a "Contact Form 7" contact form. 我尝试跟踪的第二个元素是“联系表7”联系表。 I am using the built in 'Additional settings' on the "Contact Form 7" contact form editor page. 我正在使用“联系表7”联系表编辑器页面上的内置“其他设置”。 This is the code I am using in that box: 这是我在该框中使用的代码:

on_sent_ok: "ga.push(['_trackEvent', 'Contact-Form', 'Submit'])";
on_sent_ok: "location.replace('http://www.(mydomain).com/?page_id=740');"

Thank you in advance for the helpful answers 预先感谢您的帮助

You are mixing Universal Analytics syntax and Classic GA syntax. 您正在混合Universal Analytics语法和Classic GA语法。 It looks like your tracking is using the former, but the way you are sending in the events is based on the latter. 看起来您的跟踪正在使用前者,但是事件中的发送方式则基于后者。 Your event tracking code should be: 您的事件跟踪代码应为:

ga('send', 'event', 'mobile-call', 'mobile-phone-number-click'); // for the first element
ga('send', 'event', 'Contact-Form', 'Submit'); // for the second element

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM