React Facebook Pixel

React JS wrapper for Facebook's Pixel
Install
npm install --save react-facebook-pixel
or
yarn add react-facebook-pixel
React Facebook Pixel is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial
How to use
import ReactPixel from 'react-facebook-pixel';
const advancedMatching = { em: 'some@email.com' };
const options = {
autoConfig: true,
debug: false,
};
ReactPixel.init('yourPixelIdGoesHere', advancedMatching, options);
ReactPixel.pageView();
ReactPixel.track(event, data);
ReactPixel.trackSingle('PixelId', event, data);
ReactPixel.trackCustom(event, data);
ReactPixel.trackSingleCustom('PixelId', event, data);
if you're bundling in CI
...
componentDidMount() {
const ReactPixel = require('react-facebook-pixel');
ReactPixel.default.init('yourPixelIdGoesHere');
}
...
otherwise CI will complain there's no window
.
GDPR Compliance
To be GDPR compliant, revoke the consent right after init and grant it when the user accepts to be tracked
...
ReactPixel.init('yourPixelIdGoesHere', advancedMatching, options);
ReactPixel.revokeConsent();
...
...
<button onClick={ReactPixel.grantConsent}>Accept cookies</button>.
...
Dev Server
npm run start
Default dev server runs at localhost:8080 in browser.
You can set IP and PORT in webpack.config.dev.js
Production Bundle
npm run bundle