Skip to content

Instantly share code, notes, and snippets.

😎
Awesome Motive-ing

Justin Sternberg jtsternberg

😎
Awesome Motive-ing
View GitHub Profile
@jtsternberg
jtsternberg / om.DisplayRules.afterRun.js
Created May 28, 2020
Runs after the campaign rule-check runs. Can be used to prevent the showing of a campaign even if rules pass.
View om.DisplayRules.afterRun.js
document.addEventListener('om.DisplayRules.afterRun', function(event) {
var DisplayRules = evt.detail.DisplayRules;
var Campaign = event.detail.Campaign;
if ( 'YOUR-CAMPAIGN-ID' === Campaign.id && DisplayRules.show ) {
if ( 'pepperoni' !== window.pizza ) {
// Only allow rules to pass if pizza variable exists
// and it's value is 'pepperoni'.
DisplayRules.show = false;
@jtsternberg
jtsternberg / om.Html.scripts.js
Created May 26, 2020
Runs while the campaign form HTML is being processed and just before processing any scripts inside the HTML and adding them to the head of the page.
View om.Html.scripts.js
document.addEventListener('om.Html.scripts', function(event) {
console.log(event.detail.Html);
console.log(event.detail.Campaign);
} );
@jtsternberg
jtsternberg / deletecustomvariable.js
Last active May 7, 2020 — forked from thomasgriffin/deletecustomvariable.js
OptinMonster Dynamic Text Replacement API - deleteCustomVariable
View deletecustomvariable.js
<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 — forked from thomasgriffin/hascustomvariables.js
OptinMonster Dynamic Text Replacement API - hasCustomVariables
View hascustomvariables.js
<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 — forked from thomasgriffin/hascustomvariable.js
OptinMonster Dynamic Text Replacement API - hasCustomVariable
View hascustomvariable.js
<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 — forked from thomasgriffin/getcustomvariables.js
OptinMonster Dynamic Text Replacement API - getCustomVariables
View getcustomvariables.js
<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 — forked from thomasgriffin/getcustomvariable.js
OptinMonster Dynamic Text Replacement API - getCustomVariable
View getcustomvariable.js
<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 — forked from thomasgriffin/setcustomvariable.js
OptinMonster Dynamic Text Replacement API - setCustomVariable
View setcustomvariable.js
<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 / query-args-anon-function.js
Created Apr 15, 2020
Output query args in console
View query-args-anon-function.js
(function (qs) {
var query = (qs || window.location.search).substring(1),
bits = query ? query.split('&').map(function (params) {
var p = params.split('=')
return [ p[0], p[1] ? decodeURIComponent(p[1]) : p[1] ]
}) : [],
index = -1,
result = {},
pair
@jtsternberg
jtsternberg / wpforms-to-optin-monster.php
Last active Dec 5, 2019
Automatically trigger an OptinMonster form to show, filled out, when an WP Form is submitted.
View wpforms-to-optin-monster.php
<?php
/*
* Plugin Name: WP Forms to OptinMonster
* Plugin URI: http://optinmonster.com
* Description: Automatically trigger an OptinMonster form to show, filled out, when an WP Form is submitted.
* Version: 0.1.0
* Author: Justin Sternberg
* Author URI: http://optinmonster.com
*/
You can’t perform that action at this time.