0

How to enable Matomo to track clicks on mailto links and tel links made with Elementor?

The Matomo script is added to Wordpress with the plugin "WP-Matomo Integration". The Matomo goals are listening to clicks to external websites with the pattern mailto:(.*) respectively tel:(.*). Isn't the Matomo client script supposed to fetch the goals from the tracking server and listen to these events? Is there another way to trigger those events?

1 Answer 1

0

I've created a script to search for elements with the class "matomogoal" and send the id of a goal to Matomo. It will push the goal id from the attribute matomogoalid to matomo, which you can get from your Matomo instance under Goals -> Manage Goals.

function trackClickGoal() {
    var goalId = this.getAttribute("matomogoal");
    _paq.push(['trackGoal', goalId]);
}

if (typeof _paq != "undefined") {
    var elements = document.getElementsByClassName("matomogoal");
    for (var i = 0; i < elements.length; i++) {
        elements[i].addEventListener('click', trackClickGoal, false);
    }
} else { console.error('matomo client script is is not initialized'); }
<!-- HTML is supposed to look similar to this -->
<div class="matomogoal" matomogoal="goalid">
  <a href="mailto:[email protected]"></a>
</div>

You can set those attributes by editing the link in Elementor. In the left Elementor panel click on "Advanced and set the "CSS Classes" field to matomogoal:

Then click on "Attributes" and set the value of "Custom Attributes" to matomogoal|goalid (while using the goal's ID you want to track with this click):

This also works with multiple goals on one page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.