Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtsternberg/af35121f209c4a65c4699bfbedf29149 to your computer and use it in GitHub Desktop.
Save jtsternberg/af35121f209c4a65c4699bfbedf29149 to your computer and use it in GitHub Desktop.
Track OptinMonster impressions/conversions to Adobe Analytics
jQuery( function( $ ) {
var campaignEventMap = {
'nklsasuw43ypqumlh7mn' : { // Campaign #1
'OptinMonsterOnShow' : 'event6', // Event ID from created event in Adobe for impressions.
'OptinMonsterOptinSuccess' : 'event7' // Event ID from created event in Adobe for conversions.
},
'l4eprc5lai8yn7f3vguq' : { // Campaign #2
'OptinMonsterOnShow' : 'event8', // Event ID from created event in Adobe for impressions.
'OptinMonsterOptinSuccess' : 'event9' // Event ID from created event in Adobe for conversions.
}
};
// Based on what we know from the docs, the event ids should be appended to the s.events string.
// https://marketing.adobe.com/resources/help/en_US/sc/implement/events.html
function trackEvent( eventId ) {
if ( s.events && s.events.length ) {
s.events += ',' + eventId;
} else {
s.events = eventId;
}
}
function mapAndTrackEvent( campaignSlug, eventType ) {
var campaignEvts = campaignEventMap[ campaignSlug ];
if ( campaignEvts && campaignEvts[ eventType ] ) {
trackEvent( campaignEvts[ eventType ] );
}
}
$( document ).on( 'OptinMonsterOnShow OptinMonsterOptinSuccess', function( evt, props, app ) {
mapAndTrackEvent( app.getProp('optin'), evt.type );
});
});
@jtsternberg
Copy link
Author

To get the campaign name, you can use app.getProp('campaign') in the callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment