zsajjad / react-facebook-pixel

React JS wrapper for Facebook's Pixel
MIT License
241 stars 85 forks source link

[Question] Multiple Pixel IDs #14

Closed skube closed 4 years ago

skube commented 6 years ago

Is it possible to implement more than one Pixel per site?

aejay-rs commented 5 years ago

Stumbled across this question and it happened to be something that came up before when we were researching pixel implementations for our site. I hope you aren't still waiting for an answer, but in case there are others that have this concern:

From what I understand, you can initialize the Facebook pixel multiple times, once for each pixel ID, and follow up calls for tracking will submit events for each pixel ID. They have mentioned this in some blog posts, but the multiple trackers behavior isn't covered well in their documentation. In theory, you should be able to do the same with this library for that behavior:

ReactPixel.init('FIRST_PIXEL_ID');
ReactPixel.init('SECOND_PIXEL_ID');

However, if you want to use the "trackSingle" or "trackSingleCustom" methods to track events to a particular pixel ID tracker, that behavior is not implemented by this library, so you'll have to do it yourself.

You should be able to do that by hitting the fbq object exposed by the type:

ReactPixel.fbq('trackSingle', 'FIRST_PIXEL_ID', 'PageView');

Hope this helps. My company will be doing something around these lines soon, so if I run into any snags with this I will be sure to mention those here.

Edit: Oh, and here's one of FB's blog posts talking about the single track behavior: https://developers.facebook.com/ads/blog/post/2017/11/28/event-tracking-with-multiple-pixels-tracksingle/

mattgenious commented 5 years ago

https://github.com/zsajjad/react-facebook-pixel/pull/13 is a pull request from https://github.com/jasondecastro with the functionality asked for

zsajjad commented 4 years ago

Merged #24