Created
May 30, 2012 20:20
-
-
Save bcj19/2838677 to your computer and use it in GitHub Desktop.
Using Test&Target HTML offers instead of Redirect offers
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
<!-- | |
html offer: builds referrer cookie and forces redirect via javascript | |
--> | |
<script type="text/javascript"> | |
//destination url | |
var recipeURL="testPage.html"; | |
/* | |
setCookie() - //logic to build cookie b/c other custom js files may not load/execute before the redirect is required | |
- c_name - what you want to name the cookie | |
- value - what you want to put in the cookie | |
- expiredays - how long you want to keep the cookie; [blank]=session | |
*/ | |
function setCookie(c_name,value,expiredays) { | |
var exdate=new Date(); | |
var h=window.location.hostname; | |
h=h.split('.');h=h.splice(h.length-2,2); | |
h=h.join('.'); | |
exdate.setDate(exdate.getDate()+expiredays); | |
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? ";path=/" : ";path=/;expires="+exdate.toGMTString())+";domain="+h; | |
} | |
//stick the referrer in the cookie, 1 day expiration (will force expire on destination page) | |
setCookie('test_referrer',document.referrer,1); | |
//force the redirect; include any querystring parameters (will be processed, along with referrer, on destination page) | |
window.location=recipeURL+window.location.search; | |
</script> | |
<!-- | |
s_code/on-page logic: retrieves referrer info from cookie (cookie populated via t&t html offer) | |
--> | |
<script type="text/javascript"> | |
/* ..... preceeding s_code logic .... */ | |
//get the cookie | |
var theReferrer=getCookie('test_referrer'); | |
//if the cookie is found... | |
if(theReferrer) { | |
//define rurl (referring url) variable using data from cookie | |
var rurl=theReferrer.toLowerCase(); | |
//manually change sitecatalyst referrer value | |
s.referrer=rurl; | |
//delete (force expire) cookie | |
setCookie('test_referrer','',-1); | |
} else { | |
//if no test_referrer cookie, pull referrer from document object | |
var rurl=document.referrer.toLowerCase(); //define rurl from dom | |
} | |
/* ..... trailing s_code logic .... */ | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment