Created
August 16, 2018 20:02
-
-
Save acoyfellow/e474a09bc4f9689755712e7d3144d518 to your computer and use it in GitHub Desktop.
PhoneSites affiliate script
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
<script> | |
function getParameterByName(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
}; | |
function createCookie(name, value, days, domain) { | |
var expires; | |
if (days) { | |
var date = new Date(); | |
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
expires = "; expires=" + date.toGMTString(); | |
}else{ | |
expires = ""; | |
}; | |
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"+"; domain="+domain; | |
}; | |
var affiliate = getParameterByName('affiliate'); | |
if(affiliate){ | |
console.log('Affiliate ID:', affiliate); | |
createCookie('partner_id', affiliate, 30, 'phonesites.com'); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment