Skip to content

Instantly share code, notes, and snippets.

View jtsternberg's full-sized avatar
😎
Awesome Motive-ing

Justin Sternberg jtsternberg

😎
Awesome Motive-ing
View GitHub Profile
@jtsternberg
jtsternberg / deletecustomvariable.js
Last active May 7, 2020 21:54 — forked from thomasgriffin/deletecustomvariable.js
OptinMonster Dynamic Text Replacement API - deleteCustomVariable
<script type="text/javascript">
document.addEventListener('om.Dtr.init', function(event) {
/**
* API method for deleting a custom variable. Must be accessed via the Dtr object.
*
* @param string $key The custom variable to delete.
* @return null
*/
event.detail.Dtr.deleteCustomVariable('foo');
});
@jtsternberg
jtsternberg / hascustomvariables.js
Last active May 7, 2020 21:53 — forked from thomasgriffin/hascustomvariables.js
OptinMonster Dynamic Text Replacement API - hasCustomVariables
<script type="text/javascript">
document.addEventListener('om.Dtr.init', function(event) {
/**
* API method for checking whether there are any custom variables set.
* Must be accessed via the Dtr object.
*
* @return bool True if any custom variable has been registered, false otherwise.
*/
event.detail.Dtr.hasCustomVariables();
});
@jtsternberg
jtsternberg / hascustomvariable.js
Last active May 7, 2020 21:53 — forked from thomasgriffin/hascustomvariable.js
OptinMonster Dynamic Text Replacement API - hasCustomVariable
<script type="text/javascript">
document.addEventListener('om.Dtr.init', function(event) {
/**
* API method for checking if a custom variable has been registered.
* Must be accessed via the Dtr object.
*
* @param string $key The custom variable key to check.
* @return bool True if the custom variable exists, false otherwise.
*/
event.detail.Dtr.hasCustomVariable('foo');
@jtsternberg
jtsternberg / getcustomvariables.js
Last active May 7, 2020 21:53 — forked from thomasgriffin/getcustomvariables.js
OptinMonster Dynamic Text Replacement API - getCustomVariables
<script type="text/javascript">
document.addEventListener('om.Dtr.init', function(event) {
/**
* API method for retrieving all custom variables. Must be accessed via the Dtr object.
*
* @return object A JavaScript object with key/value pairs for custom variables.
*/
event.detail.Dtr.getCustomVariables();
});
</script>
@jtsternberg
jtsternberg / getcustomvariable.js
Last active May 7, 2020 21:50 — forked from thomasgriffin/getcustomvariable.js
OptinMonster Dynamic Text Replacement API - getCustomVariable
<script type="text/javascript">
document.addEventListener('om.Dtr.init', function(event) {
/**
* API method for retrieving a custom variable. Must be accessed via the app object.
*
* @param string $key The custom variable key to retrieve.
* @return string|bool The value of the custom variable key or false if not found.
*/
event.detail.Dtr.getCustomVariable('foo');
});
@jtsternberg
jtsternberg / setcustomvariable.js
Last active May 7, 2020 21:54 — forked from thomasgriffin/setcustomvariable.js
OptinMonster Dynamic Text Replacement API - setCustomVariable
<script type="text/javascript">
document.addEventListener('om.Dtr.init', function(event) {
/**
* API method for setting a custom variable. Must be accessed via the Dtr object.
*
* @param string $key The custom variable key to set.
* @param string $value The custom variable value to set for the key.
* @return null
*/
event.detail.Dtr.setCustomVariable('foo', 'bar');
@jtsternberg
jtsternberg / om.Analytics.track-example.js
Last active November 15, 2018 19:56 — forked from brianaohern/om-Analytics-conversion-example.js
om.Analytics.track Example using Google Tag Manager to track a specific event in our Google Analytics account.
document.addEventListener('om.Analytics.track', function(event) {
if ( 'conversion' === event.detail.Analytics.type ) {
dataLayer.push({
'event': 'gaTriggerEvent',
'gaEventCategory': 'form',
'gaEventAction': 'submit',
'gaEventLabel': 'optin-monster'
});
}
} );
@jtsternberg
jtsternberg / om.Analytics.track.js
Last active October 26, 2020 21:13 — forked from brianaohern/om-Analytics-conversion.js
Runs any time we are tracking an impression or conversion.
document.addEventListener('om.Analytics.track', function(event) {
// This event is passed the Campaign object
console.log(event.detail.Campaign);
// This event is passed the Analytics object
console.log(event.detail.Analytics);
} );
document.addEventListener('om.Analytics.track', function(event) {
if ( 'conversion' === event.detail.Analytics.type ) {
console.log(event.detail.Campaign.id + '-' + event.detail.Campaign.type + ' successfully tracked a conversion.');
} else {
console.log(event.detail.Campaign.id + '-' + event.detail.Campaign.type + ' successfully tracked an impression.');
}
} );
@jtsternberg
jtsternberg / om.Action.window.js
Created November 15, 2018 19:20 — forked from brianaohern/om-Action-refresh.js
Runs before a new window is opened based on an action.
document.addEventListener('om.Action.window', function(event) {
// This event is passed the Campaign object
console.log(event.detail.Campaign);
// This event is passed the Action object
console.log(event.detail.Action);
} );