Skip to content

Instantly share code, notes, and snippets.

@Michaelcgn
Created October 12, 2016 08:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Michaelcgn/ddd3aa50dde6d0d33780e4cce5e85330 to your computer and use it in GitHub Desktop.
Save Michaelcgn/ddd3aa50dde6d0d33780e4cce5e85330 to your computer and use it in GitHub Desktop.
JS Delete Referral for Google Tag Manager
function deleteReferral(referrer) {
// More info: go.zedwoo.de/deleteReferral
// To specifically mean the dot, use \\.
// It should start with regex: Add ^ at beginning
// It should end with regex: Add $ at end
// Optional character: Add ? after character
var referrals = [
'slashless.com$',
'referrer1\\.com$',
'referrer2\\.com$',
'referrer3\\.com$',
'referrer4\\.com$',
'^mail\\.',
'^deref-\\.',
// only checks when it starts with it
'^3d-?secure\\.',
// checks anywhere in the string
'3d-?secure\\.',
];
var hname = new RegExp('https?://([^/:]+)').exec(referrer);
if (hname) {
for (var i = referrals.length; i--;) {
if (new RegExp(referrals[i]).test(hname[1])) {
return null;
}
}
}
return referrer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment