zsajjad / react-facebook-pixel

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

I have Query Regarding react-facebook-pixel #2

Closed Rupeshn73 closed 7 years ago

Rupeshn73 commented 7 years ago

I have created global file for pixel function and then deriving those function into my components

ex

import ReactGA from 'react-ga'
import ReactPixel from 'react-facebook-pixel';

export const initGA = () => {
  console.log('GA init')
  ReactGA.initialize('XXXXXXXXXXX')
}
export const logPageView = () => {
  ReactGA.set({ page: window.location.pathname })
  ReactGA.pageview(window.location.pathname)
}

export const initFB = () =>{
  console.log('Facebook Init')
  ReactPixel.init('XXXXXXXXXXXXXX');
}

export const pageViewFB = () =>{
  ReactPixel.pageView();
}

export const trackPurchaseFB = (price,name) =>{
  ReactPixel.track('Purchase', {
          value: price,
          currency: 'USD',
          content_name:name
  });
}

Component.js

import {initFB,pageViewFB,trackPurchaseFB} from "../components/Analytics"

var price ="";
            if (this.props.productDetails.discount_price > 0) {
                        price = this.props.productDetails.discount_price;
            } else {
                price = this.props.productDetails.actual_price;
            }

            initFB();
            pageViewFB();
            trackPurchaseFB(price,this.props.productDetails.product_name);

As per the above code my pageView pixel are getting tracked but ,unfortunately facebook pixel is not able to track Purchase Event.Will you please suggest that I have done anything wrong or there might be some additions are needed.

zsajjad commented 7 years ago

I cannot see any particular issue with the code. Please check this.props.productDetails.product_name & price have some value assigned to them.

Rupeshn73 commented 7 years ago

Ya they have value assigned.I am also able to see purchase event in Facebook Pixel Helper.But not able to see it in developer account of Facebook.

Rupeshn73 commented 7 years ago

It is working .My mistake facebook took some time to show details regarding custom Event.Thanks for react facebook pixel plugin.

zsajjad commented 7 years ago

Glad that it helped you :)