Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

react-facebook-pixel-ssr

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-facebook-pixel-ssr

Pixel Kit for React

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
83
31.75%
Maintainers
0
Weekly downloads
 
Created
Source

React Facebook Pixel

React JS wrapper for Facebook's Pixel

Install

npm install --save react-facebook-pixel-ssr

or

yarn add react-facebook-pixel-ssr

How to use

import ReactPixel from 'react-facebook-pixel-ssr';

const advancedMatching = { em: 'some@email.com' }; // optional, more info: https://developers.facebook.com/docs/facebook-pixel/advanced/advanced-matching
const options = {
  autoConfig: true, // set pixel's autoConfig. More info: https://developers.facebook.com/docs/facebook-pixel/advanced/
  debug: false, // enable logs
};
ReactPixel.init('yourPixelIdGoesHere', advancedMatching, options);

ReactPixel.pageView(); // For tracking page view
ReactPixel.track(event, data, eventData); // For tracking default events. More info about standard events: https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking#standard-events
ReactPixel.trackSingle('PixelId', event, data, eventData); // For tracking default events.
ReactPixel.trackCustom(event, data, eventData); // For tracking custom events. More info about custom events: https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking#custom-events
ReactPixel.trackSingleCustom('PixelId', event, data, eventData); // For tracking custom events.

if you're bundling in CI

  ...
  componentDidMount() {
    const ReactPixel =  require('react-facebook-pixel-ssr');
    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

Keywords

react

FAQs

Package last updated on 26 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts