Skip to content

Instantly share code, notes, and snippets.

Avatar

Erica Franz ericakfranz

View GitHub Profile
@ericakfranz
ericakfranz / limit-om-campaigns.js
Created February 6, 2023 23:37
Limit OM Campaigns
View limit-om-campaigns.js
/**
* Limit OptinMonster Campaigns
* @author Erica Franz
* @url https://fatpony.me
* @desc Show only one OptinMonster campaign per page visit regardless of campaign type.
*/
// Run this script when the first Campaign is shown
document.addEventListener('om.Campaign.afterShow', function(event) {
// Locate and remove only empty HTML placeholders for campaigns
@ericakfranz
ericakfranz / WPForms-OMConversion.js
Last active August 2, 2022 16:25
Trigger a conversion in OptinMonster when a specific WPForms AJAX form is submitted.
View WPForms-OMConversion.js
// Let's trigger an OptinMonster conversion only after sucessfull WPForms submission (requires AJAX in WPForms enabled). Piece-mealed from https://wpforms.com/developers/how-to-open-a-new-link-on-form-submission/
// We can use jQuery here because it's a WPForms dependency
jQuery( function( $ ) {
// Edit to change 521 to the ID of your specific WPForms form.
$( '#wpforms-form-521' ).on( 'wpformsAjaxSubmitSuccess', function( e ) {
// trigger conversion
om{{id}}.Listeners.convert();
@ericakfranz
ericakfranz / om-privacy-checkbox-field.css
Created March 13, 2022 05:49
Style the privacy checkbox field.
View om-privacy-checkbox-field.css
html div#om-{{id}} input[name="FieldsElement--privacyText-checkbox"] {
vertical-align: top !important;
}
@ericakfranz
ericakfranz / custom-smart-tag-redirect-to-referrer.js
Last active April 25, 2022 20:26
Creates a {{referrer}} custom smart tag in OptinMonster to output the referrer URL, or if it is empty redirect to another specific URL. Typically used in the "redirect to a URL" success action for an optin form or button element.
View custom-smart-tag-redirect-to-referrer.js
function myReferrer() {
var ref = document.referrer;
if(!ref) {
// redirect to a specific URL if referrer doesn't exist
var redirect = 'https://optinmonster.com';
} else var redirect = ref;
// Let's print what referrer is being passed into the dev tools console, remove this in production
console.log(ref);
@ericakfranz
ericakfranz / autofill-om-optin-email-field.js
Created March 11, 2022 19:26
Autofill the optin email field and hide it. Specifically for use with gamified (spinning wheel) campaigns to allow spinning the wheel without collecting an email.
View autofill-om-optin-email-field.js
document.addEventListener('om.Campaign.afterShow', function(event) {
// Replace YOUR_DUMMY_EMAIL with the email address you want to autofill the field with.
// A validly formatted email address is required here.
var emailValue = "YOUR_DUMMY_EMAIL";
document.getElementById("{{ns}}-field-email").value = emailValue;
});
View om-manually-set-global-cookies.js
// Set OptinMonster Global Cookies when this function runs
function setGlobalCookies() {
document.cookie = "omSuccessCookie=true; expires=Fri, 31 Dec 9999 23:59:59 GMT";
document.cookie = "omGlobalSuccessCookie=true; expires=Fri, 31 Dec 9999 23:59:59 GMT";
document.cookie = "omGlobalInteractionCookie=true; expires=Fri, 31 Dec 9999 23:59:59 GMT";
}
@ericakfranz
ericakfranz / query-separator-smart-tag.js
Created February 26, 2022 16:16
Check if the URL already contains a query argument and choose whether to output a '?' or '&' character before any other string.
View query-separator-smart-tag.js
function mySep() {
var url = window.location.href;
if (url.indexOf('?') != -1) {
var sep = '&';
} else var sep = '?';
console.log(sep);
return sep;
}
View slide-left-center.css
html div#om-{{id}} {
left: 0 !important;
height: 540px !important;
top: calc(540px / 2) !important;
bottom: calc(540px / 2) !important;
margin-top: auto !important;
margin-bottom: auto !important;
animation: 1s ease-out 0s 1 slideInFromLeft;
}
@keyframes slideInFromLeft {
View slide-right-center.css
html div#om-{{id}} {
margin-right: -20px !important;
height: 540px !important;
top: calc(540px / 2) !important;
bottom: calc(540px / 2) !important;
margin-top: auto !important;
margin-bottom: auto !important;
animation: 1s ease-out 0s 1 slideInFromRight;
}
@keyframes slideInFromRight {
@ericakfranz
ericakfranz / setUTMCookie.js
Created February 23, 2022 20:45
Set a cookie if the URL contains specific UTM parameters.
View setUTMCookie.js
function setUTMCookie() {
// Search the URL
var url = window.location.search;
// Store the UTMs we're searching for in a variable
var emailCampaignUTMs = '?utm_source=digg&utm_medium=email&utm_campaign=free_plus_shipping&utm_content=hhc_bundle';
// Calculate the expiration date for our cookie (1 year from the date it's set)
var cookieDate = new Date;