Matomo / Piwik – Track click onto link

How to track a click on a link in matomo / piwik:

 

Insert the following code at the end of the php / html file:

<script>
document.querySelector("a").addEventListener('click', function (e) {
    _paq.push(['trackEvent', 'Click auf Link', 'Anfrage senden']);
});
</script>

The javascript code selects the link element (in my case i have just one link on the landingpage) and activates an eventlistener, which triggers the connection to matomo when a click is detected. If you have multiple links you can give them an extra css class and with the queryselector function you are able to track just the specific link you want.

Check the matomo webinterface:

Matomo - Track click onto link

As you can see the click event works with the code. The normal folder icons are website visits / even if you reload the page. The other symbol is the click event onto the link.

 

With this solution you are able to track all of the button clicks onto a web page.

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.