Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
Awesome Motive-ing

Justin Sternberg jtsternberg

😎
Awesome Motive-ing
View GitHub Profile
@jtsternberg
jtsternberg / om-validate-first-last-name.js
Created Jan 7, 2021
OptinMonster, validation to require first/last name
View om-validate-first-last-name.js
<script>
document.addEventListener('om.Campaign.afterShow', function(event) {
var campaign = event.detail.Campaign;
if ( '{{id}}' !== campaign.id ) {
return;
}
var validationError = 'A last name is required.';
var $nameField = document.getElementById( '{{ns}}-field-name' );
@jtsternberg
jtsternberg / om-allowed-users.php
Last active Nov 19, 2020
Define a list of allowed users which can access the OptinMonster admin pages.
View om-allowed-users.php
<?php
// Comma-separated list of WordPress user ids allowed access to the OptinMonster pages.
define( 'ALLOWED_OM_USERS', '1,2,5' );
// The new capability defined for viewing OM pages.
// function for_om_get_allowed_cap() {
// return 'optinmonster_allowed';
// }
// add_filter( 'optin_monster_api_menu_cap', 'for_om_get_allowed_cap' );
@jtsternberg
jtsternberg / send-meta-with-optin-request-for-webhooks-and-zapier.js
Last active Aug 12, 2020
Send meta with optin request for Webhooks and Zapier integrations
View send-meta-with-optin-request-for-webhooks-and-zapier.js
document.addEventListener('om.Optin.init.submit', function( evt ) {
// Only do this for a specific campaign
if ( '<slug>' !== evt.detail.Campaign.id ) {
return;
}
// Some meta you want to send along to your webhook or Zapier...
var meta = JSON.parse( JSON.stringify( window.location ) );
meta.pizza = 'pepperoni';
@jtsternberg
jtsternberg / om.DisplayRules.afterRun.js
Last active Oct 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 = event.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');
});