Tracking clicks on button doesn't work

Hi there,
I’m a new user of Matomo. It seems that the configuration of click tracking is done in 3 steps:

  1. create de trigger, that matches when id = btn-id ;
  2. create a tag that is linked to the trigger ;
  3. add a Js code onclick=“_paq.push(…)”, with tag parameters.

In my case, everything seems to be configured as desired, but no event is tracked when I clicked on the button. How to debug my configuration, to detect what is wrong? I’ve seen some docs, video, examples, but nothing helped me.
Other thing: Doing these 3 steps are tedious to track a single click “button ‘Hello’ clicked”.

Thanks

Please publish your onclick=“_paq.push(…)”, respectivelly the full <button ... code.

Hi,

This is the HTML code:

<a href="#" class="btn btn-primary" data-bs-toggle="modal" 
  data-bs-target="#massagesModal" id="btn-modal-massages"
   onclick="_paq.push(['trackEvent', 'Prestations', 'Massages', 'Tarifs']);">...</a>

About the trigger, I’ve tried these 2 cases:

  • “click Id” “matches the CSS selector” button[id=“btn-modal-massages”]
  • “click Id” “equals” btn-modal-massages

About the tag, I’ve configured:

  • Tracking type = Event
  • Event Category = Prestations
  • Event Action = Massages
  • Event Name = Tarifs
  • Event Value = {{ClickButton}}

Where is the mistake?

OK. Its also an a(nchor) HTML element and not a button. The a element has not a value="", that is needed by {{ClickButton}}. The value="" must be a number: 9 or 1.23.

_paq.push([‘trackEvent’, ‘Prestations’, ‘Massages’, ‘Tarifs’]
Category: (string) Prestations
Action: (string) Massages
Name: (string) Tarifs
Value: (number) [autmatically added if a value exist]

difficult to find an error.

Maybe the quotes are not correct. You use and correct is '.

You can add a value manually:
_paq.push(['trackEvent', 'Prestations', 'Massages', 'Tarifs', myvalue]

Is the matomo tracking code embeeded and is the matomo.js loaded?
Use the browser inspector console to check errors.

1 Like

Hello (I replied to the email, but I don’t see my reply in the forum).

Thanks for your answer.

I’ve changed the “a” tag by a “button” tag, with a value “1”. So the code becomes
button class=“btn btn-primary” data-bs-toggle=“modal”
data-bs-target=“#massagesModal” id=“btn-modal-massages” value=“1”
onclick=“_paq.push([‘trackEvent’, ‘Prestations’, ‘Massages’, ‘Tarifs’, 1]);”

I also checked that the embedded js code (calling the “container_NUV5Cei9.js” file) is loaded as required by the doc “as high as possible into the “head” part of the page”. The matomo.js is called at the end (I also tried to put it at first).
There is no JS error in the page, or when I clicked the button.

The click does nothing in Behavior / Events tracking.

I’ve activated the debug mode, but I don’t understand the result:

  • Fired tag: none
  • Not Yet Fired Tags: there is my event!!!

You can check with this URL:
http://estelle-serenity.fr/?mtmPreviewMode=NUV5Cei9

I don’t understand where is the misconfiguration…

Julien

You seem to be mixing manual _paq.push commands AND the tag manager.
Use EITHER OR, not both.
If you’re having problem with the tag manager a tip is to make a generic click event that triggers on all clicks (you can do a custom HTML tag with a small javascript that outputs “testing” in the console) and then do the preview mode and then check the variables. Matomo tag manager is a little pain in the a** to debug and the variables doesn’t always reflect what you thought they would.

1 Like

Ok, thanks a lot for this advice.
I removed the configuration of the tag manager an used only the js code. That’s better and simpler for my needs.

Hi @Julien_Coron
Did you finally track the click event?

Hi @heurteph-ei !
Yes, it worked with the javascript code only.
(I’ve checked the “Solution” checkbox on the @Feldon 's answer)

1 Like