Last active
July 23, 2018 21:09
-
-
Save jtsternberg/af35121f209c4a65c4699bfbedf29149 to your computer and use it in GitHub Desktop.
Track OptinMonster impressions/conversions to Adobe Analytics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To get the campaign name, you can use
app.getProp('campaign')
in the callback.