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.