Onclick event tracking in markdown

Hello again!

Question, I’d like to add a MixPanel tracking event on a file download link on a Kirby page.

(file: some.pdf text: Please download this pdf. popup: yes)

onclick="window.mixpanel.track('Yes!! clicked on the button')

Is there a way to merge them so Kirby knows that the onclick part needs to be triggered on click.


Using the onclick HTML attribute is not recommended as that can lead to quite much unmaintainable spaghetti code. You can use the following though:

(file: some.pdf text: Please download this pdf. popup: yes class: track)

In your JavaScript code, you can then listen to the onclick event on all links with that class and fire the tracking handler from there.

I never liked spaghetti!

Used the bind event and it worked out nicely. Thanks for your response.