zsajjad / react-facebook-pixel

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

Is there anyway to call ReactPixel methods without initializing first? #17

Closed cezarcarvalhaes closed 4 years ago

cezarcarvalhaes commented 5 years ago

Is there anyway to call ReactPixel methods without initializing first?

The reason I ask is because we have a React app that we're using within other larger sites that have their own fb tracking. We'd like to keep the app modular, and with its own tracking but also not mess up our tracking data by initializing twice on the same page (larger site, plus smaller react component). I tried calling ReactPixel.track() without initializing and got an error. Hoping maybe I can call it and pass in our app ID without initializing and therefore sending in duplicate data to FB.

zsajjad commented 5 years ago

Can you please share the error you got that will make it easier to move forward on this. It is really an interesting scenario.

cezarcarvalhaes commented 5 years ago

Sorry for the delay in getting back to you. Yeah, it's definitely an odd scenario. Here's the error we get if we try to fire a ReactPixel event without initializing ReactPixel itself: "fb-pixel.js:1 Pixel not initialized before using call ReactPixel.init with required params"

zsajjad commented 5 years ago

It's because of the extra precaution we have taken in our code. I wish if you can provide a small code-base where we can test the fix.

zsajjad commented 5 years ago

Can you please try from this branch. I have altered code to check if PIXEL is already available in the window object.

viniciuscr commented 5 years ago

Is this branch already merged? I would like to initialize the pixel on my index once and use it all over my app just importing react-facebook-pixel

zsajjad commented 5 years ago

We haven't merged it yet, have you tested it with your system?

mihailistov commented 5 years ago

I'd like to do something similar now, is this merged in?

zsajjad commented 5 years ago

You can install from given branch

houmark commented 5 years ago

It would be great to be able to .init() multiple times without worrying about if this was already done, so we can just ensure we init correctly once, but don't have to safeguard another init later on. useEffect and useReducer can sometimes fire more than we really want and safeguarding that can be somewhat of a job.

zsajjad commented 4 years ago

Merged #38