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 / om-validate-first-last-name.js
Created January 7, 2021 16:30
OptinMonster, validation to require first/last name
<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 November 19, 2020 15:37
Define a list of allowed users which can access the OptinMonster admin pages.
<?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 August 12, 2020 14:40
Send meta with optin request for Webhooks and Zapier integrations
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 October 28, 2020 01:16
Runs after the campaign rule-check runs. Can be used to prevent the showing of a campaign even if rules pass.
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 16:44
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.
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 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');
});