Optin Monster Event Listener
How to track Optin Monster Pop Up Interactions with google tag manager
Measuring your Optinmonster pop-ups funnel and its performance in analytics tools such as Google Analytics (Universal & GA4), Mixpanel, PiwikPro, Fullstory, etc. Is easy and possible using Google Tag Manager.
And if you’re using advertising platforms like Google Ads, Facebook Ads, Microsoft Ads, Pinterest, etc. You can also measure conversions of these pop-ups using this Optinmonster event listener and Google Tag Manager.
To start the implementation in GTM, create a custom HTML tag that you’ll be adding this event listener script to, give the tag a name and trigger it on pageview or DOM ready.
This script will listen for Optinmonster pop-ups activity (impression, conversion, closing a pop-up and errors) and push the event and its attributes to the dataLayer.
The next step is to setup dataLayer variables, which gives you more insights about the event, these includes;
[campaignID] –> gives the ID of the Optinmonster pop-up campaign
[campaignName] –> this is the campaign name
[campaignDetail] –> returns campaign type, popup type.
There are 4 Optinmonster events triggered by this listener
[optinmonsterimpression] –> triggers when a pop-up is displayed
[optinmonsterconversion] –> for when a user converts
[optinmonsterCampaignClose] –> when a pop-up is closed
[optinmonsterError] –> when an error is experienced while converting
To trigger your marketing pixels/tags when these events happen, create a custom event for each of these events connect your GTM tag to the appropriate trigger.
<script> /* https://optinmonster.com/docs/optinmonster-javascript-events-api/ */ // optinmonster conversion error document.addEventListener('om.Optin.error', function(event) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': 'optinmonsterError', 'campaignID': event.detail.Campaign.id, 'campaignName': event.detail.Campaign.name, 'campaignDetail': event.detail.Campaign.type }); }); //tracking impression and conversion document.addEventListener('om.Analytics.track', function(event) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': "optinmonster" + event.detail.Analytics.type, 'campaignID': event.detail.Campaign.id, 'campaignName': event.detail.Campaign.name, 'campaignDetail': event.detail.Campaign.type }); }); // user closes a campaign document.addEventListener('om.Campaign.close', function(event) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': 'optinmonsterCampaignClose', 'campaignID': event.detail.Campaign.id, 'campaignName': event.detail.Campaign.name, 'campaignDetail': event.detail.Campaign.type }); }); </script>