简体   繁体   中英

Google Analytics Form Tracking Events not working

We have a form that we're trying to track in Google Analytics. We have the following code executed after form submission:

<script language=\"javascript\">_gaq.push(['_trackEvent', 'ProductForm', 'submit', window.location.href])</script>

And here is the general Analytics code we're using globally on the site:

<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-12345678-1', 'auto');
ga('send', 'pageview');
</script>

However the form events are not tracking in Analytics. Any idea what's wrong with the particular tracking method we're using or do we simply need to upgrade our Analytics version?

Thanks!

_gaq.push is outdated, you will need update.

Try that code:

ga('send', 'event', {'page': window.location.href,'title': 'ProductForm'});

You can see more examples here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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