React Facebook Pixel is a wrapper library for integrating Facebook's Pixel (now Meta Pixel) into React applications. It provides a straightforward API for initializing the pixel, tracking page views, and logging standard or custom events. The current stable version is 1.0.4, but the package has not seen any new releases to npm in over five years, with its last publication in December 2020. This indicates an abandoned maintenance cadence, suggesting potential compatibility issues with newer React versions, updated Facebook Pixel APIs, or modern web development practices like server-side rendering (SSR). Differentiators from actively maintained alternatives (like `react-facebook` or `react-use-facebook-pixel`) include its simplified, direct API for basic pixel functionalities, though it lacks modern React features such as hooks or built-in SSR safety measures.
npm install react-facebook-pixelVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Facebook Pixel, track a page view on component mount, and trigger a custom 'Purchase' event. It also includes the crucial `typeof window !== 'undefined'` check for SSR compatibility and shows how to use the GDPR consent features.
Conditionally import the library or wrap its initialization and usage in `typeof window !== 'undefined'` checks. For CommonJS `require()`, specifically use `require('react-facebook-pixel').default` in non-browser environments. For Next.js, consider dynamic imports with `ssr: false`.Call `ReactPixel.revokeConsent()` after initialization and then `ReactPixel.grantConsent()` only after the user explicitly accepts tracking cookies. This ensures no data is sent before consent is given.
Consider migrating to actively maintained alternatives like `react-facebook` (which includes pixel tracking) or `react-use-facebook-pixel` for ongoing support and features. These alternatives offer better SSR support, modern React patterns (hooks), and updated type definitions.
Wrap `ReactPixel` calls in `if (typeof window !== 'undefined') { ... }` blocks. For Next.js, dynamic imports with `ssr: false` are often the most robust solution. When using CommonJS `require()`, use `require('react-facebook-pixel').default`.Ensure you are using `const ReactPixel = require('react-facebook-pixel').default;` when importing via CommonJS. If using ES Modules, `import ReactPixel from 'react-facebook-pixel';` is correct.Add a global type declaration for `window.fbq` in your project (e.g., in a `global.d.ts` file) or use the `react-facebook-pixel` library's provided API which should have types. Example: `declare global { interface Window { fbq?: FacebookPixelFunction; } }`.No dependency data recorded yet.