Created
June 2, 2016 18:32
-
-
Save tomfuertes/f6e0c048a9bec0b888b8a1170170b35a to your computer and use it in GitHub Desktop.
Exclude people via Optimizely Custom Audience based on landing page or pages visited
This file contains 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
(function() { | |
// exclude people who have visited /activity-monitor/ | |
function setCookie(name, value, optDays) { | |
'use strict'; | |
var expires = ''; | |
if (optDays) { | |
var date = new Date(); | |
date.setTime(date.getTime() + (optDays * 24 * 60 * 60 * 1000)); | |
expires = '; expires=' + date.toGMTString(); | |
} | |
document.cookie = name + '=' + value + expires + '; path=/'; | |
}; | |
function getCookie(name) { | |
'use strict'; | |
var nameEQ = name + '='; | |
var ca = document.cookie.split(';'); | |
for (var i = 0; i < ca.length; i++) { | |
var c = ca[i]; | |
while (c.charAt(0) === ' ') c = c.substring(1, c.length); | |
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); | |
} | |
return null; | |
}; | |
var cookieName = 'landed-on-am'; | |
// check cookie | |
var landedOnActivityMonitor = getCookie(cookieName); | |
// when no cookie get/set yet set one | |
if (landedOnActivityMonitor === null) { | |
landedOnActivityMonitor = /activity-monitor/i.test(location.pathname) ? 'true' : 'false'; | |
// wonkey value b/c needs to get domain since across www and shop | |
setCookie(cookieName, landedOnActivityMonitor + '; domain=.whistle.com'); | |
} | |
// if they didn't land on activity monitor then they should be bucketed | |
return landedOnActivityMonitor === 'false'; | |
})(); |
This file contains 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
(function() { | |
// exclude people who have visited /activity-monitor/ | |
function setCookie(name, value, optDays) { | |
'use strict'; | |
var expires = ''; | |
if (optDays) { | |
var date = new Date(); | |
date.setTime(date.getTime() + (optDays * 24 * 60 * 60 * 1000)); | |
expires = '; expires=' + date.toGMTString(); | |
} | |
document.cookie = name + '=' + value + expires + '; path=/'; | |
}; | |
if (/activity-monitor/i.test(location.pathname)) { | |
// wonkey b/c needs to get domain since across www and shop | |
setCookie('exp4-exclude', 'true; domain=.whistle.com'); | |
} | |
return !/exp4-exclude/.test(document.cookie); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment