Shoora
10/8/2018 - 4:29 PM

Track tel: and mailto: click with Google Analytics and jQuery

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 ); 
        
  });
  
});