Track form events with Google Analytics

The plugin makes it easy for you to interact with the various form events and run a piece of code, like tracking the event with Google Analytics.

Say you want to send an event to Google Analytics every time someone used a form to subscribe? You can do that by adding the following snippet to the bottom of your form mark-up.

Use the following code if you are using analytics.js.

<script type="text/javascript">
mc4wp.forms.on('subscribed', function(form) {
	// analytics.js
	ga && ga('send', 'event', 'Forms', 'Sign-up', 'MailChimp for WP Sign-Up');
});
</script>

Use the following code if you are using Google Analytics by Yoast plugin.

<script type="text/javascript">
mc4wp.forms.on('subscribed', function(form) {
	// Google Analytics by Yoast
	__gaTracker && __gaTracker('send', 'event', 'Forms', 'Sign-up', 'MailChimp for WP Sign-Up');
});
</script>

If you are still using the older ga.js instead of analytics.js you will need to migrate to analytics.js for event tracking to work.

The code above will only send the event to Google Analytics if the sign-up request actually succeeded, so failed attempts will not be tracked.

It can take up to 24 hours before results show up in Google Analytics reports.

Was this article helpful? ·