Created
August 30, 2016 15:36
-
-
Save NickDeckerDevs/a6ea560213ccce1dc5d35fa01ca85e5c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var trackOutboundLink = function(url, category) { | |
ga('send', 'event', category, 'click', url, { | |
'transport': 'beacon', | |
'hitCallback': function() { | |
document.location = url; | |
} | |
}); | |
} | |
function addClickOnOutboundLink(link, category) { | |
var href = link.attr('href'); | |
link.on('click', function(e) { | |
e.preventDefault(); | |
trackOutboundLink(href, category); | |
}); | |
} | |
var clientDomain = document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]; | |
jQuery('a').each(function() { | |
var linkElement = jQuery(this); | |
var href = linkElement.attr('href'); | |
if(href != null) { | |
if(href.indexOf('mailto:') > -1) { | |
addClickOnOutboundLink(linkElement, 'Email'); | |
} | |
if((href.indexOf('http://') > -1 || href.indexOf('https://') > -1) && href.indexOf(clientDomain) == -1) { | |
addClickOnOutboundLink(linkElement, 'Outbound'); | |
} | |
if(href.indexOf('tel:') > -1) { | |
addClickOnOutboundLink(linkElement, 'Phone Call'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment