Is there any way to run custom code when a specific custom event is fired?

Hello guys,

Is it possible to execute custom code only when a specific custom event is triggered?

Hi,

This is not something that could be directly covered in the triggers section, however, you could set up the same trigger for your custom event and your custom code tag and both of the events would launch on the same trigger. Also, if you would like one of your events to fire before another, then you would have to set a condition for that in the Tag Priority section.

Also, you could send a custom event in your custom code tag by introducing a _paq.push("trackEvent") method. This would allow you to define your custom code script and custom event in just a single tag, which would have a joint trigger.

Thank you for your quick reply!
If the custom event comes from Backend(API) it would be better to use _paq.push(“trackEvent”) method, right?
Thank you!

It depends on what you mean by backend, if by that you are referring to a JS file that is connected to your site, then the trackEvent method could be easily incorporated into your site’s source code should there be the Piwik PRO installation code available.

If it is something that it is handled through external site or file that is not connected to the site, which has your Piwik PRO installation code incorporated directly, then it would be best to use HTTP API tracking.