Tel: link tracking question

So I just installed Matomo on one of my wordpress sites. I was looking at how to track tel: link clicks and found this snippet of js on the forums:

$("a[href^='tel:']").on("click", function (e) {
    _paq.push(['trackEvent', 'contactform', 'called', this.href]);
});

Is this code something I just need to wrap in a script tag and put in the footer to start tracking tel link clicks?

If so, I’ve implemented that and it’s not tracking.

Lastly, my website lists several businesses and their phone numbers, should this script track any tel link click?

Hi,

The snippet assumes you are using jQuery on your website, so if you don’t it won’t work
(you can instead use the last one from Tracking tel: URLs (phone numbers))

You can always check the Javascript console of your browsers developer tools for errors if you think something isn’t working.

The CSS selector a[href^='tel:'] should target any <a> that has a href that starts with tel:. Again you can verify this by running just document.querySelector("a[href^='tel:']") in the JS console and see which elements it returns.

I have no experience with JS so please bear with me. So what I’ve done is put

document.querySelector("a[href^='tel:']").addEventListener('click', function (e) {
    _paq.push(['trackEvent', 'contact', 'called this phone number', this.href]);
});

in a js file and called the js from functions.php, console shows no errors.

My last question is do these link clicks show up in outlinks in the dashboard?

No, they will show up as events.

Alright, thanks so much for all the help!

Just an FYI for anyone else coming across this. WordPress runs jQuery in compatibility mode, so you will typically need to specify jQuery instead of $ as shown in the following example:

jQuery("a[href^='tel:']").on("click", function (e) {
    _paq.push(['trackEvent', 'contactform', 'called', this.href]);
});

If desired, you can enable the $ version by following this guide:
https://digwp.com/2011/09/using-instead-of-jquery-in-wordpress/

1 Like