Is this the proper way to trigger a button click event to be tracked in Google Analytics? I’m working in wordpress and this seems easier and simpler to maintain than editing the theme files. I would insert the second script below with a plugin that allows you to do that.

Analytics code:

  (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',
'https://www.googleanalytics.com/analytics.js','ga');

  ga('create', 'XX-XXXXXXXX-X', 'auto');
  ga('send', 'pageview');

Submit button click event for tracking:

document.getElementById("button_id").onclick = function ga('send', 'event', 'ButtonClick', 'Click', 'ButtonClicked', '0');

Read more here: Calling Google Analytics Goal Tracking Function with Javascript onClick event


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: