Last active
August 29, 2015 14:07
-
-
Save tfayyaz/a5b5d1ec7de2e9612296 to your computer and use it in GitHub Desktop.
This file contains 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
// Turn all links to have # to test link click Tracking | |
$('a').each(function() { | |
var link = $(this).attr('href') | |
$(this).attr('href', '#'+ link) | |
}); |
This file contains 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
// dedupe logic | |
var channelSource = getQuery('utm_campaign') | |
if (channelSource === 'AffiliateWindow') { | |
// Check if channel utm_campaign equals AffiliateWindow | |
// create cookie called awinChannel with value aw that lasts for 3 days | |
createCookie('awinChannel','aw',3) | |
} else if (document.referrer === '' && readCookie('awinChannel') === 'aw' ) { | |
// Check if channel is direct and awinChannel aw exists equals true | |
// do nothing | |
} else { | |
// if not any of above set channel to other for 3 days | |
createCookie('awinChannel','other',3) | |
} | |
// create functions | |
function createCookie(name,value,days) { | |
if (days) { | |
var date = new Date(); | |
date.setTime(date.getTime()+(days*24*60*60*1000)); | |
var expires = "; expires="+date.toGMTString(); | |
} | |
else var expires = ""; | |
document.cookie = name+"="+value+expires+"; path=/"; | |
} | |
function readCookie(name) { | |
var nameEQ = name + "="; | |
var ca = document.cookie.split(';'); | |
for(var i=0;i < ca.length;i++) { | |
var c = ca[i]; | |
while (c.charAt(0)==' ') c = c.substring(1,c.length); | |
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | |
} | |
return null; | |
} | |
function eraseCookie(name) { | |
createCookie(name,"",-1); | |
} | |
function getQuery(key) { | |
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment