This is a snippet you can use in Google Analytics to track phone number clicks. The code looks slightly different depending on if you use analytics.js or the older ga.js tracking code.
Note that I prefer to use the click event handler as opposed to inline onclicks. This makes for cleaner code and also it’s much easier than having to remember to add the onclick every single time you use a telephone link.
The reason that I start with a preventDefault() is that in my testing, I found that the ga(‘send’…) line wasn’t pushing the event trigger to google analytics. Thus, I first send the message to google analytics, then manually trigger the phone number dialing action.
If you use analytics.js
1 2 3 4 5 6 7 |
//track phone clicks with this snippet if you use analytics.js jQuery("a[href^='tel:']").click(function(e){ e.preventDefault(); ga('send', 'event', 'yourcategory', 'phone number link clicked', jQuery(location).attr('href')); phonenumber = jQuery(this).attr("href"); window.location = phonenumber; }); |
If you use ga.js
1 2 3 4 5 6 7 |
//track phone clicks with this snippet if you use ga.js jQuery("a[href^='tel:']").click(function(e){ e.preventDefault(); _gaq.push(['_trackEvent', 'yourcategory', 'phone number link clicked',jQuery(location).attr('href'),, 'true']); phonenumber = jQuery(this).attr("href"); window.location = phonenumber; }); |
Hope it comes in handy. Would be happy to hear from you.