cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Analytics Event to Google API

Adding Analytics Event to Google API

 

Magento Version: 1.9.2.2

 

I’ve had my Google Analytics working fine using the below script placed in System>Configuration>General>Design>Footer>Miscellaneous HTML

 

I want to add e-commerce tracking using the built-in Google API and keep my custom “30 seconds on page” event but I’m not sure how to do both.

 

How do I add a custom event when using the built-in Google Analytics API?

 

<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-******-*', 'auto');
  ga('send', 'pageview');setTimeout("ga('send', 'event', { eventCategory: '30 seconds on page', eventAction: 'Read' })", 30000);

</script>

 

 I’ve tried adding the event code to app/code/core/Mage/GoogleAnalytics/Block/Ga.php but keep getting a error.

 

Any help would be appreciated.