How to Add Google Analytics Event Tracking

Article Last Updated: August 27, 2018

Note: this functionality is only available for AJAX submissions. For more information about AJAX submissions, see the submission settings.

To add Google Analytics event tracking you’ll need to use the yikes-mailchimp-google-analytics action to create your own custom function. Let’s call this function yikes_mailchimp_google_analytics. We supply the current form’s ID to this function, so if you need to use different events or want different functionality based on the form this is easily achievable.

Within our yikes_mailchimp_google_analytics function, we’ll need to create two JavaScript functions:

  1. yikes_mailchimp_google_analytics_failure – this function is fired off when an unsuccessful subscription occurs
  2. yikes_mailchimp_google_analytics_success – this function is fired off when a successful subscription occurs
Note: these two functions will not work if they have a different name

Within each function, add your Google Analytics tracking code. You can see an example of how this works:

In this example we’re simply sending a Google Analytics event with the category “mailchimp-subscribe” and the action “subscription-failed” for a failed subscription and “subscription-successful” for a successful one.

For more information about the Google Analytics Events API, check out their documentation.

As always, reach out to us if you need help.