Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Danny van Kooten

    (@dvankooten)

    If you load the Analytics.js file in your pages, you should be able to track form submissions with something like the following.

    JavaScript

    var submitButton = document.querySelector('.mc4wp-form input[type="submit"]');
    addListener(submitButton, 'click', function() {
      ga('send', 'event', 'button', 'click', 'nav-buttons');
    });
    
    // helper function to add listeners (cross-browser compatible)
    function addListener(element, type, callback) {
     if (element.addEventListener) element.addEventListener(type, callback);
     else if (element.attachEvent) element.attachEvent('on' + type, callback);
    }

    You can drop that code anywhere in your JS files. If you have no clue how to do this, an easier way might be to stick to HTML only.

    Form mark-up:

    <input type="submit" value="Subscribe" onclick="ga('send', 'event', 'button', 'click', 'nav-buttons');" />

    Thread Starter eizymeizy_0809

    (@eizymeizy_0809)

    That should solve it (the HTML version). Great, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Google Analytics event tracking’ is closed to new replies.