Created
March 30, 2011 19:18
-
-
Save cleblanc87/895094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function() { | |
var bake_cookie = function(name, value, expire) { | |
jQuery.cookie(name, value, { expires : expire, domain : 'tanga.com'}); | |
} | |
// if the user is coming from tanga already | |
// we only want to increment the page_views | |
if(document.referrer.indexOf("tanga.com") != -1) { | |
bake_cookie('page_views', parseInt(jQuery.cookie('page_views'))+1, 1000); | |
} | |
// user is coming from outside tanga | |
else { | |
//if the user been here before | |
//we dont need to initialize the cookies | |
if(jQuery.cookie('num_visits')) { | |
//if it been 24 hours since their first visit | |
//we can now call this their next visit | |
//since it is a fresh visit, page_views gets set to 1 | |
if(!jQuery.cookie('on_first_visit')) { | |
bake_cookie('num_visits', parseInt(jQuery.cookie('num_visits'))+1, 1000); | |
bake_cookie('page_views', '1', 1000); | |
} | |
//their first visit was less then 24 hours ago, dont want to count this as a second visit yet, but we want to increment thier page views | |
else { | |
bake_cookie('page_views', parseInt(jQuery.cookie('page_views'))+1, 1000); | |
} | |
} | |
//the user has never been here, initialize the cookies | |
else { | |
bake_cookie('num_visits', '1', 1000); | |
bake_cookie('page_views', '1', 1000); | |
bake_cookie('on_first_visit', '1', 1); | |
} | |
} | |
//if the user has only been to tanga once, on the second page view, | |
//show the 3 things about tanga image | |
if(jQuery.cookie('page_views') === '2' && jQuery.cookie('num_visits') === '1') { | |
jQuery.facebox("<a href='#' id='close' class='close'>X</a><img src='/images/3things.png'></img>"); | |
jQuery('#facebox .popup').css('width', '800px'); | |
} | |
//if the user has now been to tanga 2 times, on the 2nd page load | |
//show the newsletter popup form | |
else if(jQuery.cookie('page_views') === '2' && jQuery.cookie('num_visits') === '2' && !jQuery.cookie('on_first_visit')) { | |
jQuery.facebox("<div class='newsletter-popup'><a href='#' id='close' class='close'>X</a><form action='/mailchimp/subscribe' id='newsletter' method='post'><input type='hidden' name='newsletter[alert_type]' value='Daily Product Alert'></input><input type='text' name='newsletter[email_address]' size='30'></input><input type='submit'></input></form></div>"); | |
jQuery('#facebox .popup').css('width', '593px'); | |
} | |
//close the facebox when the user clicks the background or the X | |
jQuery('#facebox_overlay').click(function(){jQuery(document).trigger('close.facebox');}); | |
jQuery('#close').click(function(){jQuery(document).trigger('close.facebox');}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment