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 gtag.js GA4:

<script>
mc4wp.forms.on('subscribed', function(form) {
    gtag('event', 'mc4wp_signup', {'mc4wp_action': 'subscribed', 'mc4wp_form_name':  form.name, 'mc4wp_form_id': form.id});
});
</script>

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

<script>
mc4wp.forms.on('subscribed', function(form) {
    ga('send', 'event', 'Forms', 'Sign-up', 'Name: ' + form.name + ' ID: ' + form.id);
});
</script>

Use the following code if you are using Google Tag Manager:

<script>
mc4wp.forms.on('subscribed', function(form) {
    window.dataLayer = window.dataLayer || []; 
    window.dataLayer.push({ 'event' : 'Sign-up', 'name' : form.name + ' ID: ' + form.id });
});
</script>

Don’t forget to create a Trigger (custom event with name “Sign-up”) and tag in Google Tag Manager!

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

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