Skip to content

Instantly share code, notes, and snippets.

@tomfuertes
Created June 2, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfuertes/f6e0c048a9bec0b888b8a1170170b35a to your computer and use it in GitHub Desktop.
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
(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';
})();
(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