Skip to content

Instantly share code, notes, and snippets.

@bojangajic
Created July 12, 2018 15:43
Show Gist options
  • Save bojangajic/49e5c831773eda4a8dca04ebd1070fbf to your computer and use it in GitHub Desktop.
Save bojangajic/49e5c831773eda4a8dca04ebd1070fbf to your computer and use it in GitHub Desktop.
FT - CB email attribution
$(function() {
console.log( "ready!" );
var affnickname=getQueryStringParam('hop');
$("#cfAR").submit(function(e){
var email = $("input[type='email']").val();
var url = "https://ea.clickbank.net/?vendor=freedomtkt&affiliate=" + affnickname + "&custemail=" + email;
if(typeof affnickname != 'undefined')
{
console.log(url);
createCORSRequest('GET', url);
}
else {
console.log('affiliate not defined');
}
});
});
function getQueryStringParam(name)
{
var vars = [], hash;
console.log(parent.document.URL);
var q = parent.document.URL.split('?')[1];
if(q != undefined)
{
q = q.split('&');
for(var i = 0; i < q.length; i++)
{
hash = q[i].split('=');
vars.push(hash[1]);
vars[hash[0]] = hash[1];
}
}
return vars[name];
}
function createCORSRequest(method, url)
{
var xhr = new XMLHttpRequest();
if ('withCredentials' in xhr)
{
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
}
else if (typeof XDomainRequest != 'undefined')
{
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
}
else
{
// CORS not supported.
xhr = null;
console.log('CORS not supported');
}
return xhr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment