Skip to content

Instantly share code, notes, and snippets.

@ambercouch
Last active October 8, 2018 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ambercouch/4645afb8ba8d7c1ffe59 to your computer and use it in GitHub Desktop.
Save ambercouch/4645afb8ba8d7c1ffe59 to your computer and use it in GitHub Desktop.
Track tel: and mailto: click with Google Analytics and jQuery
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