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

**URL:** <https://community.piwik.pro/t/is-there-any-way-to-run-custom-code-when-a-specific-custom-event-is-fired/3906>\
**Category:** Data collection and tags\
**Created:** [April 17, 2024, 9:47am UTC](https://community.piwik.pro/t/is-there-any-way-to-run-custom-code-when-a-specific-custom-event-is-fired/3906 "2024-04-17T09:47:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladys](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@vladys](https://community.piwik.pro/u/vladys)\
**Post date:** [April 17, 2024, 9:47am UTC](https://community.piwik.pro/t/is-there-any-way-to-run-custom-code-when-a-specific-custom-event-is-fired/3906/1 "2024-04-17T09:47:12Z")

</div>

Hello guys,

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

---

<div class="post-metadata">

**Author:** ![asinior](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/asinior/32/1905_2.png) [@asinior](https://community.piwik.pro/u/asinior)\
**Post date:** [April 17, 2024, 10:33am UTC](https://community.piwik.pro/t/is-there-any-way-to-run-custom-code-when-a-specific-custom-event-is-fired/3906/2 "2024-04-17T10:33:09Z")

</div>

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](https://help.piwik.pro/support/tag-manager/how-to-fire-tags-in-a-specific-order/).

Also, you could send a custom event in your custom code tag by introducing a [`_paq.push("trackEvent")` method](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#_paq.push). This would allow you to define your custom code script and custom event in just a single tag, which would have a joint trigger.

---

<div class="post-metadata">

**Author:** ![vladys](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@vladys](https://community.piwik.pro/u/vladys)\
**Post date:** [April 17, 2024, 10:38am UTC](https://community.piwik.pro/t/is-there-any-way-to-run-custom-code-when-a-specific-custom-event-is-fired/3906/3 "2024-04-17T10:38:24Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![asinior](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/asinior/32/1905_2.png) [@asinior](https://community.piwik.pro/u/asinior)\
**Post date:** [April 17, 2024, 10:43am UTC](https://community.piwik.pro/t/is-there-any-way-to-run-custom-code-when-a-specific-custom-event-is-fired/3906/4 "2024-04-17T10:43:17Z")

</div>

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](https://developers.piwik.pro/en/latest/data_collection/api/http_api.html).
