Last active
October 8, 2018 16:29
-
-
Save ambercouch/4645afb8ba8d7c1ffe59 to your computer and use it in GitHub Desktop.
Track tel: and mailto: click with Google Analytics and jQuery
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
jQuery(document).ready(function(){ | |
//set up the vars | |
var eCat = 'contact', | |
eAct = '', | |
eLabel = window.location.pathname; | |
//target href attributes that begin tel: | |
jQuery(document).on('click','[href^="tel:"]', function(e) { | |
//set the action as tel | |
eAct = 'tel:'+ jQuery(this).attr('href'); | |
//track event | |
ga('send', 'event', eCat, eAct, eLabel ); | |
}); | |
//target href attributes that begin mailto: | |
jQuery(document).on('click','[href^="mailto:"]', function(e) { | |
//set the action as email | |
eAct = 'email:' + jQuery(this).attr('href'); | |
//track event | |
ga('send', 'event', eCat, eAct, eLabel ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment