zsajjad / react-facebook-pixel

React JS wrapper for Facebook's Pixel
MIT License
241 stars 85 forks source link

PageView? #41

Closed wootwoot1234 closed 4 years ago

wootwoot1234 commented 4 years ago

Do I need to call ReactPixel.pageView(); every time a page loads? If so do I call it in componentDidMount()? Is there a way to call it on each route change if I'm using "react-router-dom"?

BrodaNoel commented 4 years ago

You can fix it with a HOC:

In your Router files:

const withAnalytics = (Component) => (props) => {
  FacebookPixel.pageView();
  return <Component {...props} />;
};

// ...

<Route path='/signup' component={ withAnalytics(SignUp) } />

I implemented it in https://getnofilter.com and it's working