Dynamic events in facebook pixel

I remember that spent a lot of time to found a working script, that can be started by clicking a button on site.

Thus I decided to share my own script. You can use it on your website, as well as set a conversion campaign in Facebook ads

Here is an example of a working script at the click of a button:

<button id="button's id"> Текст на кнопке </button>
var button = document.getElementById('button's id');
    function() { 
      fbq('track', 'event name');          


‘event name’ – this is an event which will be sent to Facebook

«button’s id» – id of the button, after clicking which this event should work.

The script tracks clicks on any link or button with the relevant class.

    var btns = document.querySelectorAll('.fb-track');
        for (let i = 0; i < btns.length; i++) {
              btns[i].onclick = function () { 
                  fbq('track', btns[i].id); 





Arefyeu Aliaksandr

Digital Marketing Manager