Skip to content

Instantly share code, notes, and snippets.

@imajes
Created August 26, 2014 00:35
Show Gist options
  • Save imajes/fd4b8822beea2d56a938 to your computer and use it in GitHub Desktop.
Save imajes/fd4b8822beea2d56a938 to your computer and use it in GitHub Desktop.
// Code will instantiate putting everyone in segment L. Mobile check will put users into I; zip code check will put people into seg A if in Chicago,
// Iteration 2 - Windy City pilot with MSA tracking
// Seg A - Outside of Windy City
// Seg B - blank seg
// Seg C - Windy City test area (carrover of previous seg C)
// Seg D = mobile users
// Seg E = technical issues
// Seg F = default segment for all users
var windyCityCookieCutter = new UniversalCookieCutterWindyCity("windyCity2014pilot","mktUniversalPersist","WindyCity2014_PILOT_Seg","windycity","0-0-0-0-0-100","41","","WindyCity2014_PILOT_SegF");
// ZIP code checking - run everywhere BUT shopping bag, checkout, secure pages
if( location.protocol == 'http:' && location.pathname != '/buy/shopping_bag.do' && location.pathname != '/buy/shopping_bag_delete_item.do' && location.pathname != '/buy/shopping_bag_save_item.do' && location.pathname != '/buy/shopping_bag_move_item.do' && location.pathname != '/buy/edit_shipping_method_bag.do' && location.pathname != '/checkout/order.do' && location.pathname != '/checkout/orderConfirm.do' ) {
var windyCityTestSegmenter = {
windyCityChecksRun: false,
init: function() {
// Wrap to ensure Omniture code happens AFTER Windy City checks, if the checks haven't already occurred
reportingService.controller.reportingManager.transmitRequest = reportingService.controller.reportingManager.transmitRequest.wrap( function(om) {
//console.info('trasmit firing');
// If the checks haven't run, delay the Omniture fire until Windy City checks are done
var windyCitySegmentCheck = gidLib.getCookieVar("mktUniversalPersist","windyCity2014pilot");
if( windyCitySegmentCheck.indexOf('WindyCity2014_PILOT_SegF') > -1 ) {
Event.observe( document,'wcdWindyCityCheck:ready', function() {
//console.info('firing wrapped Omni call');
reportingService.controller.reportingManager.setABTestingOverrideVariables();
om();
});
}
// Else, the checks have run already, fire the normal Omni transmit
else {
//console.info('firing normal Omni call');
om();
}
});
// Ensure Windy City checks only run once on a given page and only if user in seg E (unsegmented)
var windyCitySegment = gidLib.getCookieVar("mktUniversalPersist","windyCity2014pilot");
// TEMP TAKEDOWN OF TEST - IF IN SEG C, FORCE TO SEG A
if( windyCitySegment.indexOf('WindyCity2014_PILOT_SegC') > -1 ) {
windyCityTestSegmenter.forceIntoSeg('A');
}
else if( windyCitySegment.indexOf('WindyCity2014_PILOT_SegF') > -1 ) {
// Delay Omniture data post until personalization is ready; fire wcdWindyCityCheck:ready following
if( window['personalizationService'] ) {
Event.observe(document,"personalizationData:ready", function() {
//console.info('personalization ready');
// Mobile check - push users on mobile devices into segment C
var userAgentCheck = navigator.userAgent.toLowerCase();
if( location.hostname.indexOf('m.') > -1 || responsiveService.api.isMobileBrowser() || /webos|iphone|ipod|blackberry|iemobile|opera mini/i.test( userAgentCheck ) || ( userAgentCheck.indexOf('android') > -1 && userAgentCheck.indexOf('mobile') > -1 ) ) {
windyCityTestSegmenter.forceIntoSeg('D');
windyCityTestSegmenter.windyCityChecksRun = true;
document.fire('wcdWindyCityCheck:ready');
}
// If user not a mobile user, check zip code
else {
windyCityTestSegmenter.zipCodeCheck();
}
});
}
// personalizationService not available = problem; seg D
else {
windyCityTestSegmenter.forceIntoSeg('E');
windyCityTestSegmenter.windyCityChecksRun = true;
document.fire('wcdWindyCityCheck:ready');
}
}
// Else, checks have already run so fire event
else {
windyCityTestSegmenter.windyCityChecksRun = true;
document.fire('wcdWindyCityCheck:ready');
}
},
// Forces user into an AB test segment
forceIntoSeg: function( segToForce ) {
windyCityCookieCutter.QuickSegment = segToForce.toUpperCase();
windyCityCookieCutter.UserSegment = windyCityCookieCutter.CookieValueBase + windyCityCookieCutter.QuickSegment;
gidLib.setCookieVar( windyCityCookieCutter.CookieUsed, windyCityCookieCutter.CookieVariableName, windyCityCookieCutter.UserSegment );
windyCityCookieCutter.setABTestVariable( windyCityCookieCutter.UserSegment );
},
// Checks whether zip code data is available and, if so whether a user is in the Chicago area
zipCodeCheck: function() {
// Check whether marketingMessageInfo data is available; if not problem; put in seg K
if( personalizationService.model.personalizationData && personalizationService.model.personalizationData.personalizationInfoV1 && personalizationService.model.personalizationData.personalizationInfoV1.marketingMessageInfo ) {
// Personaliztion data/marketMessageInfo available, check whether geo-location is.
// If not, we are not on page with this data [and should NOT force segment change]
if( personalizationService.model.personalizationData.personalizationInfoV1.marketingMessageInfo.geoLocation ) {
// Check whether user is outside Chicago area and, if so, force into seg B
var geoString = personalizationService.model.personalizationData.personalizationInfoV1.marketingMessageInfo.geoLocation;
var forceIntoChicago = gidLib.getQuerystringParam('inchicago',true);
if( forceIntoChicago == 'true' ) { geoString +=',zip=46001'; }
else if( forceIntoChicago == 'false' ) { geoString +=',zip=94102-94105'; }
// Check whether geo-location includes zip code
if( ( geoString.indexOf('zip=') > -1 ) ) {
var zipCompleteCode = geoString.substr( geoString.indexOf('zip=')+4,5 );
var zipArray = ["46001","46036","46044","46301","46303","46304","46307","46308","46310","46311","46312","46319","46320","46321","46322","46323","46324","46327","46340","46341","46342","46350","46352","46356","46360","46361","46366","46368","46371","46373","46374","46375","46382","46383","46384","46385","46391","46392","46394","46402","46403","46404","46405","46406","46407","46408","46409","46410","46411","46504","46506","46507","46514","46516","46517","46526","46528","46531","46532","46534","46536","46538","46539","46540","46542","46550","46552","46555","46562","46563","46565","46567","46570","46573","46574","46580","46581","46582","46595","46702","46703","46705","46706","46711","46714","46721","46723","46725","46733","46737","46738","46740","46741","46742","46747","46750","46755","46761","46763","46767","46770","46773","46774","46779","46783","46785","46791","46792","46793","46795","46799","46801","46802","46803","46804","46805","46806","46807","46808","46809","46814","46815","46816","46818","46819","46825","46835","46845","46860","46865","46866","46895","46914","46919","46928","46933","46952","46953","46962","46970","46975","46986","46989","46992","47320","47336","47338","47348","47359","47371","47978","60002","60004","60005","60006","60007","60008","60009","60010","60012","60013","60014","60015","60016","60017","60018","60019","60020","60021","60022","60025","60026","60029","60030","60031","60033","60034","60035","60038","60039","60040","60041","60042","60043","60044","60045","60046","60047","60048","60050","60051","60053","60055","60056","60060","60061","60062","60064","60065","60067","60068","60069","60070","60071","60072","60073","60074","60076","60077","60078","60079","60081","60082","60083","60084","60085","60087","60088","60089","60090","60091","60093","60094","60095","60096","60097","60098","60099","60101","60102","60103","60104","60106","60107","60108","60110","60115","60116","60118","60119","60120","60121","60122","60123","60124","60125","60126","60128","60130","60131","60132","60133","60134","60135","60136","60137","60138","60139","60140","60141","60142","60143","60146","60148","60150","60153","60154","60155","60156","60157","60159","60160","60162","60163","60164","60165","60168","60169","60170","60171","60172","60173","60174","60175","60176","60177","60178","60179","60181","60184","60185","60186","60187","60188","60189","60190","60191","60192","60193","60194","60195","60196","60197","60199","60201","60202","60203","60204","60209","60290","60301","60302","60304","60305","60399","60401","60402","60403","60404","60406","60408","60409","60411","60412","60415","60417","60419","60422","60423","60425","60426","60428","60429","60430","60431","60432","60433","60434","60435","60436","60438","60439","60440","60441","60442","60443","60444","60445","60446","60447","60448","60449","60451","60452","60453","60454","60455","60456","60457","60458","60459","60461","60462","60463","60464","60465","60466","60467","60468","60469","60471","60472","60473","60475","60476","60477","60478","60480","60481","60482","60484","60487","60490","60491","60499","60501","60502","60503","60504","60505","60506","60507","60510","60511","60513","60514","60515","60516","60517","60519","60520","60521","60522","60523","60525","60526","60527","60532","60534","60538","60539","60540","60542","60543","60544","60545","60546","60548","60554","60555","60558","60559","60560","60561","60563","60564","60565","60566","60567","60570","60585","60586","60597","60598","60599","60601","60602","60603","60604","60605","60606","60607","60608","60609","60610","60611","60612","60613","60614","60615","60616","60617","60618","60619","60620","60621","60622","60623","60624","60625","60626","60628","60629","60630","60631","60632","60633","60634","60636","60637","60638","60639","60640","60641","60642","60643","60644","60645","60646","60647","60649","60651","60652","60653","60654","60655","60656","60657","60659","60660","60661","60664","60666","60668","60669","60670","60673","60675","60677","60678","60680","60681","60682","60684","60685","60686","60687","60688","60689","60690","60691","60693","60694","60695","60696","60697","60699","60701","60706","60707","60712","60714","60803","60804","60805","60827","60901","60911","60913","60914","60915","60917","60918","60919","60921","60922","60924","60927","60928","60929","60930","60931","60932","60933","60936","60938","60940","60941","60942","60948","60949","60950","60951","60952","60953","60954","60955","60957","60959","60960","60962","60963","60964","60966","60968","60970","60973","61006","61008","61010","61011","61012","61015","61016","61019","61020","61021","61024","61032","61047","61049","61051","61052","61054","61061","61063","61064","61065","61068","61071","61072","61073","61080","61081","61084","61088","61101","61102","61103","61104","61105","61107","61108","61109","61111","61112","61114","61115","61126","61132","61240","61244","61250","61256","61265","61270","61277","61301","61310","61318","61341","61342","61348","61353","61354","61356","61364","61367","61376","61401","61438","61443","61523","61603","61604","61607","61611","61614","61724","61741","61764","61771","61801","61802","61803","61811","61812","61813","61814","61816","61817","61820","61821","61822","61824","61825","61826","61832","61833","61834","61840","61841","61842","61843","61844","61846","61847","61849","61850","61852","61853","61854","61856","61857","61858","61859","61862","61864","61865","61866","61870","61873","61874","61876","61877","61878","61880","61883","61910","61911","61912","61913","61917","61919","61920","61924","61930","61931","61932","61933","61938","61940","61942","61943","61944","61951","61953","61956","62474","62703","60303","60674","46065","46302","46345","46347","46348","46349","46376","46377","46381","46390","46393","46511","46530","46544","46545","46546","46554","46556","46561","46590","46601","46613","46614","46615","46616","46617","46619","46628","46635","46637","46660","46701","46923","46926","46929","46947","46978","46985","46988","46996","47906","47907","47917","47918","47923","47926","47932","47944","47946","47950","47951","47959","47960","47963","47970","47971","47977","47991","47995","47996","60109","60111","60112","60113","60145","60147","60151","60407","60410","60416","60420","60421","60424","60437","60450","60460","60470","60474","60479","60512","60518","60530","60531","60536","60537","60541","60549","60550","60551","60552","60553","60556","60557","60910","60920","60935","60945","60958","60961","60969","61007","61013","61014","61018","61027","61030","61031","61037","61038","61039","61042","61043","61046","61048","61050","61053","61060","61062","61067","61070","61078","61087","61089","61091","61201","61231","61232","61233","61234","61235","61236","61238","61239","61241","61242","61243","61252","61254","61258","61259","61261","61262","61263","61264","61266","61273","61274","61275","61278","61281","61282","61284","61311","61312","61313","61314","61315","61316","61317","61319","61320","61321","61322","61323","61324","61325","61326","61327","61328","61329","61330","61331","61333","61334","61335","61336","61337","61338","61340","61344","61345","61346","61349","61350","61358","61359","61360","61361","61362","61363","61368","61369","61370","61372","61373","61375","61377","61378","61379","61410","61413","61414","61418","61419","61421","61422","61423","61424","61427","61430","61431","61432","61433","61434","61437","61439","61441","61447","61449","61451","61455","61462","61465","61467","61469","61470","61473","61474","61477","61479","61483","61486","61488","61489","61490","61491","61516","61517","61519","61520","61524","61525","61526","61528","61529","61530","61531","61532","61533","61534","61535","61536","61537","61539","61540","61541","61542","61544","61545","61547","61548","61550","61552","61553","61554","61559","61560","61561","61562","61564","61565","61567","61568","61569","61570","61571","61572","61601","61602","61605","61606","61610","61612","61613","61615","61616","61625","61651","61652","61701","61702","61704","61705","61709","61710","61723","61725","61726","61727","61728","61729","61733","61734","61735","61736","61738","61739","61740","61742","61743","61744","61745","61747","61748","61751","61752","61754","61755","61756","61760","61761","61772","61776","61777","61790","61791","61815","61871","61884","61929","62301","62471","62521","62522","62523","62525","62526","62531","62532","62535","62537","62539","62544","62548","62549","62554","62561","62563","62601","62615","62629","62634","62635","62642","62643","62644","62650","62651","62656","62664","62666","62668","62675","62682","62684","62693","62701","62702","62704","62705","62706","62707","62708","62711","62712","62715","62791","60075","60086","60092","60663","46355","46372","46379","46401","46604","46612","46620","46624","46626","46629","46634","46680","46699","60912","60926","60939","60956","60967","60974","61831","61848","61941","61949","61955","60037","60049","60105","60152","60180","60183","60129","60144","60723","61057","61058","61077","61204","61276","61299","61332","61371","61374","61402","61416","61426","61468","61543","61555","61558","61628","61629","61630","61632","61633","61634","61635","61636","61637","61638","61639","61640","61641","61643","61644","61650","61653","61654","61655","61656","61750","61758","61799","62324","62519","62659","62713","62716","62719","62721","62722","62723","62726","62736","62739","62746","62756","62757","62761","62762","62763","62764","62765","62766","62767","62769","62776","62777","62781","62786","62794","62796","60117","60568","60572","60208","46209","46325","46850","46851","46852","46853","46854","46855","46856","46857","46858","46859","46861","46862","46863","46864","46867","46868","46869","46885","46896","46897","46898","46899","46971","61106","61110","61125","61130","61131"];
// If ZIP code is in array, you are in ChicagoLand; put in seg A
if ( jQuery.inArray( zipCompleteCode, zipArray ) > -1 ) {
....
ad infinitum, for another couple thousand lines....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment