Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window is not initialized issue #110

Open
jacobknighj12 opened this issue Mar 21, 2024 · 3 comments
Open

window is not initialized issue #110

jacobknighj12 opened this issue Mar 21, 2024 · 3 comments

Comments

@jacobknighj12
Copy link

jacobknighj12 commented Mar 21, 2024

This issue was fixed with a simple window !== 'undefined' check in a couple places. as this project seems dead to the owner I forked and updated my own version feel free to use it if you have the same problem:
https://github.com/jacobknighj12/react-facebook-pixel
yarn upgrade react-facebook-pixel@https://github.com/jacobknighj12/react-facebook-pixel.git

@f2016862
Copy link

f2016862 commented Apr 3, 2024

Thanks this fixed the issue

@prateeshg
Copy link

This issue was fixed with a simple window !== 'undefined' check in a couple places. as this project seems dead to the owner I forked and updated my own version feel free to use it if you have the same problem: https://github.com/jacobknighj12/react-facebook-pixel yarn upgrade react-facebook-pixel@https://github.com/jacobknighj12/react-facebook-pixel.git

only created this account to thank you for this fix.

@clemens
Copy link

clemens commented Jan 17, 2025

While your solution looks good on first sight, when you look closer, I think it does the wrong thing – namely it injects the script if it's initialized (as evidenced by the if (initialized) wrapper).

So if anything, I think you'd need to adapt it to handle the check for window separately of initialization:

init(pixelId, advancedMatching = {}, options = defaultOptions) {
  if (typeof window === undefined) return

  initialized = !!window.fbq;
  // ...
}

I'm not sure if this fixes issues, but at least it should make code behave sensibly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants