Created
January 18, 2018 08:42
-
-
Save lmartins/c2f6a0b9a03b76fd8ca5c2b0c8d838e2 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
each(document.querySelectorAll('.entry-content'), (el) => { | |
delegate(el, 'a', 'click', (e) => { | |
processExternalLink(e); | |
}, false); | |
}); | |
function processExternalLink(e) { | |
const domainName = extractDomain(e.delegateTarget.href); | |
switch (domainName) { | |
case 'shopstyle.it': | |
case 'api.shopstyle.it': | |
case 'amazon.com': | |
case 'amzn.to': | |
console.log('Send FB Pixel event'); | |
fbq('track', 'ViewContent'); | |
default: | |
if (domainName !== window.location.host) { | |
console.log('Send GA event'); | |
ga('send', 'event', { | |
eventCategory: 'Outbound click', | |
eventAction: window.location.href, | |
eventLabel: e.delegateTarget.href | |
}); | |
} | |
break; | |
} | |
} | |
function extractDomain(input){ | |
var url = input; | |
var urlParts = url.replace('http://','').replace('https://','').split(/[/?#]/); | |
return urlParts[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment