Skip to content

Instantly share code, notes, and snippets.

View ericakfranz's full-sized avatar

Erica Franz ericakfranz

View GitHub Profile
@ericakfranz
ericakfranz / OptinMonsterBeforeOptin.js
Last active May 19, 2016 19:18
Add a custom redirect url (http://optinmonster.com/) if the subscriber uses a non-business email address such as yahoo, gmail, hotmail, etc.
jQuery(document).ready(function($){
$(document).on('OptinMonsterBeforeOptin', function(event, data, object){
// Grab the email address submitted by the user.
var email = $('#om-' + data.optin).find('input[type="email"]').val();
// Test to ensure it is a proper email. Otherwise, redirect to another page.
if ( /@yahoo.com$/.test(email) || /@gmail.com$/.test(email) || /@hotmail.com$/.test(email) || /@googlemail.com$/.test(email) || /@live.com$/.test(email) || /@aol.com$/.test(email) || /@outlook.com$/.test(email) || /@comcast.net$/.test(email) || /@inbox.com$/.test(email) || /@hushmail.com$/.test(email) || /@lycos.com$/.test(email) || /@zoho.com$/.test(email) || /@gmx.com$/.test(email) ) {
window[data.optin_js].optin = function(){
return window.location.href = 'http://optinmonster.com/';
};
@ericakfranz
ericakfranz / OptinMonsterOnClose.js
Created December 7, 2015 22:16
Stop a video from playing in our Canvas lightbox optin when it closes.
jQuery(document).ready( function($){
//Snag the URL of the iframe so we can use it later
var url = $('.optin_custom_html_applied iframe').attr('src');
$(document).on('OptinMonsterOnClose', function( event, data, object){
//Assign the iframe's src to null, which kills the video
$('.optin_custom_html_applied iframe').attr('src', '');
});
});
@ericakfranz
ericakfranz / OptinMonsterTracked.js
Created December 7, 2015 22:17
Write to the console when an OM optin is successfully tracked.
jQuery(document).ready( function($){
$(document).on('OptinMonsterTracked', function( event, data, object ){
console.log(data.optin + '-' + data.type + " successfully tracked");
});
});
@ericakfranz
ericakfranz / OptinMonsterTrackedImpression.js
Created December 7, 2015 22:18
Write to the console when an OM optin successfully tracks an Impression.
jQuery(document).ready( function($){
$(document).on('OptinMonsterTrackedImpression', function( event, data, object ){
console.log(data.optin + '-' + data.type + ' successfully tracked an impression.');
});
});
@ericakfranz
ericakfranz / OptinMonsterPreOptin.js
Created December 7, 2015 22:19
Write to the console when an OM optin is about to be successfully converted.
jQuery(document).ready( function($){
$(document).on('OptinMonsterTrackedImpression', function( event, data, object ){
console.log('A successful conversion is about to be made for the ' + data.optin + '-' + data.type + ' optin.');
});
});
@ericakfranz
ericakfranz / OptinMonsterTrackedConversion.js
Created December 7, 2015 22:20
When an OM optin tracks a Conversion, push an event to GA account.
jQuery(document).ready( function($) {
$(document).on('OptinMonsterTrackedConversion', function( event, data, object ){
dataLayer.push({
'event': 'gaTriggerEvent',
'gaEventCategory': 'form',
'gaEventAction': 'submit',
'gaEventLabel': 'optin-monster'
});
});
});
@ericakfranz
ericakfranz / OptinMonsterOnError.js
Created December 7, 2015 22:21
Animate the error messages displayed each time they're triggered.
jQuery(document).ready( function($){
$(document).on('OptinMonsterOnError', function(event, data, object){
var l = 20;
for( var i = 0; i < 10; i++ )
$( ".optin-monster-error" ).animate( { 'margin-left': "+=" + ( l = -l ) + 'px' }, 50);
});
});
@ericakfranz
ericakfranz / OptinMonsterOptinSuccess.js
Created December 7, 2015 22:22
Close the OM optin after a successful submission.
jQuery(document).ready( function($){
$(document).on('OptinMonsterOptinSuccess', function( event, data, object ){
object.close();
});
});
@ericakfranz
ericakfranz / OptinMonsterOnRedirect.js
Created December 7, 2015 22:23
Write to the console when an OM optin is about to redirect to the specified Redirect URL (native integrations only).
jQuery(document).ready( function($){
$(document).on('OptinMonsterOnRedirect', function(event, data, object){
console.log(“Redirect in progress..”);
});
});
@ericakfranz
ericakfranz / OptinMonsterOptinSuccessClose.js
Last active December 7, 2015 22:28
Trigger file download once a successfully submitted optin is closed.
// Function SaveToDisk forces file download instead of viewing in browser
function SaveToDisk(fileURL, fileName) {
// for non-IE
if (!window.ActiveXObject) {
var save = document.createElement('a');
save.href = fileURL;
save.target = '_blank';
save.download = fileName || 'unknown';
var event = document.createEvent('Event');