Skip to content

Instantly share code, notes, and snippets.

@acoyfellow
Created August 16, 2018 20:02
Show Gist options
  • Save acoyfellow/e474a09bc4f9689755712e7d3144d518 to your computer and use it in GitHub Desktop.
Save acoyfellow/e474a09bc4f9689755712e7d3144d518 to your computer and use it in GitHub Desktop.
PhoneSites affiliate script
<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