Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
zsajjad authored Dec 11, 2019
2 parents 89fffca + 16aecf1 commit 970aedd
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 308 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# React Facebook Pixel
[![npm](https://img.shields.io/npm/dm/react-facebook-pixel.svg)](https://www.npmjs.com/package/react-facebook-pixel)

> React JS wrapper for [Facebook's Pixel](https://developers.facebook.com/docs/ads-for-websites/pixel-events/v2.9)
> React JS wrapper for [Facebook's Pixel](https://developers.facebook.com/docs/facebook-pixel)

## Install
Expand All @@ -15,6 +15,11 @@ yarn add react-facebook-pixel
```

**Typescript**

Type definitions are included in this repository in the types/index.d.ts file.


## How to use
```js
import ReactPixel from 'react-facebook-pixel';
Expand All @@ -27,9 +32,11 @@ const options = {
};
ReactPixel.init('yourPixelIdGoesHere', advancedMatching, options);

ReactPixel.pageView(); // For tracking page view
ReactPixel.track( event, data ) // For tracking default events, more info about events and data https://developers.facebook.com/docs/ads-for-websites/pixel-events/v2.9
ReactPixel.trackCustom( event, data ) // For tracking custom events
ReactPixel.pageView(); // For tracking page view
ReactPixel.track( event, data ) // For tracking default events, more info about events and data https://developers.facebook.com/docs/ads-for-websites/pixel-events/v2.9
ReactPixel.trackSingle( 'PixelId', event, data ) // For tracking default events, more info about events and data https://developers.facebook.com/docs/ads-for-websites/pixel-events/v2.9
ReactPixel.trackCustom( event, data ) // For tracking custom events
ReactPixel.trackSingleCustom( 'PixelId', event, data ) // For tracking custom events
```
**if you're bundling in CI**
```js
Expand All @@ -43,8 +50,6 @@ ReactPixel.trackCustom( event, data ) // For tracking custom events
otherwise CI will complain there's no `window`.




## Dev Server
```
npm run start
Expand Down
2 changes: 1 addition & 1 deletion dist/fb-pixel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"babel-preset-react": "6.23.0",
"chai": "3.5.0",
"chai-jquery": "2.0.0",
"eslint": "3.19.0",
"eslint": "4.18.2",
"eslint-config-airbnb": "14.1.0",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "4.0.0",
Expand Down
32 changes: 32 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ export default {
}
},

trackSingle(pixel, title, data) {
if (!verifyInit()) {
return;
}

fbq('trackSingle', pixel, title, data); // eslint-disable-line no-undef

if (debug) {
log(`called fbq('trackSingle', '${pixel}', '${title}');`);

if (data) {
log('with data', data);
}
}
},

trackCustom(event, data) {
if (!verifyInit()) {
return;
Expand All @@ -106,6 +122,22 @@ export default {
}
},

trackSingleCustom(pixel, event, data) {
if (!verifyInit()) {
return;
}

fbq('trackSingle', pixel, event, data); // eslint-disable-line no-undef

if (debug) {
log(`called fbq('trackSingleCustom', '${pixel}', '${event}');`);

if (data) {
log('with data', data);
}
}
},

fbq(...args) {
if (!verifyInit()) {
return;
Expand Down
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ export function init(pixelId: string, advancedMatching?: AdvancedMatching, optio
export function pageView(): void;
export function track(title: string, data?: Data | any): void;
export function trackCustom(title: string, data?: Data | any): void;
export function trackSingle(pixel: string, title: string, data?: Data | any): void;
export function trackSingleCustom(pixel: string, title: string, data?: Data | any): void;
export function fbq(...args: Array<unknown>): void;
Loading

0 comments on commit 970aedd

Please sign in to comment.