Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
Awesome Motive-ing

Justin Sternberg jtsternberg

😎
Awesome Motive-ing
View GitHub Profile
@jtsternberg
jtsternberg / hubspot-optinmonster-custom-html-integration.html
Created Apr 28, 2021
hubspot optinmonster custom html integration
View hubspot-optinmonster-custom-html-integration.html
<!--[if lte IE 8]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script>
(function() {
var addForm = function() {
window.hbspt.forms.create({
sfdcCampaignId: '70130000000ep2ZZZ',
portalId: '102310',
formId: '190ga042-56fc-4897-bed4-86ea519cb3e9',
@jtsternberg
jtsternberg / om-defer-embed-scripts.php
Created Mar 31, 2021
Add defer tag to OM plugin embed scripts
View om-defer-embed-scripts.php
<?php
add_filter( 'optin_monster_api_final_output', function( $campaigns ) {
if ( ! empty( $campaigns ) ) {
foreach ( $campaigns as $slug => $embed ) {
$campaigns[ $slug ] = str_replace( 's.async=true;', 's.async=true;s.defer=true;', $embed );
}
}
return $campaigns;
} );
@jtsternberg
jtsternberg / disable-monsterlinks.html
Created Mar 30, 2021
Disable all monsterlinks on a page (restores them to normal links)
View disable-monsterlinks.html
@jtsternberg
jtsternberg / prevent-all-om-campaigns.html
Created Mar 30, 2021
Prevent loading all OM campaigns
View prevent-all-om-campaigns.html
<script type="text/javascript">
document.addEventListener('om.Shutdown.init', function(evt) {
evt.detail.Shutdown.preventAll = true;
});
</script>
@jtsternberg
jtsternberg / om-hubspot-loading-form.html
Last active Feb 16, 2021
hubspot optinmonster form loading indicator
View om-hubspot-loading-form.html
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>-->
<!--[if lte IE 8]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<!--[endif]-->
<script>
document.addEventListener('om.Campaign.afterShow', function(event) {
jQuery.getScript("//js.hsforms.net/forms/v2.js", function() {
hbspt.forms.create({
portalId: "<HS_PORTAL_ID>",
formId: '<HS_FORM_ID>',
@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);
} );