Skip to content

Instantly share code, notes, and snippets.

View ericakfranz's full-sized avatar

Erica Franz ericakfranz

View GitHub Profile
@ericakfranz
ericakfranz / om-monsterlink-mobile-variant.html
Created January 26, 2024 20:35
MonsterLink with mobile variation
@ericakfranz
ericakfranz / special-monsterlink.html
Created January 26, 2024 20:31
MonsterLink from a non `a` tag element
@ericakfranz
ericakfranz / limit-om-campaigns.js
Created February 6, 2023 23:37
Limit OM Campaigns
/**
* 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.
// 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
Last active November 3, 2023 23:07
Style the privacy checkbox field.
html div#om-{{id}} .{{ns}}-FieldsElement--wrapper input[type=checkbox][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.
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.
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;
});
// 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.
function mySep() {
var url = window.location.href;
if (url.indexOf('?') != -1) {
var sep = '&';
} else var sep = '?';
console.log(sep);
return sep;
}
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 {