4

I have a little problem with the Facebook pixel package. I need it only for page view. I consulted the official documentation here and it seems to be pretty easy to use. However, it still doesn't work. I wrote the following code:

import ReactPixel from 'react-facebook-pixel'

const advancedMatching = { em: '[email protected]' }
const options = {
  autoConfig: true,
  debug: false,
}

function MyPage(){
  // other delarations
    useEffect(() => {
      ReactPixel.init('123456', advancedMatching, options)
      if (hasMarketingPreference) {
        console.log("I've just viewed the page!")
        ReactPixel.pageView()
      } else {
        ReactPixel.revokeConsent()
      }
    }, [])

  return (<>{/*the page code*/}</>)
}

It looks like it reaches the console.log() statement, but it still doesn't work. Did I do something wrong? Thank you very much!

7
  • 1
    Doesn't work how - do you get a script error in the console, or just can't see the request tracked, or something else? I'd try changing debug to true for starters and see if that tells you anything, or removing the advanced matching email address (are you using a real address, or just the one you copy & pasted from the example?) If you add a console.log after ReactPixel.pageView() does that also get reached?
    – Rup
    Commented Mar 15, 2021 at 9:25
  • If I change to true the debug it tells me [react-facebook-pixel] called fbq('track', 'PageView');. And yeah It reaches the console log after the ReactPixel.PageView()
    – user3001286
    Commented Mar 15, 2021 at 9:36
  • It sounds like the script thinks it's working then. If you look in your browser's network tab do you see the PageView track request? Does it have a success error code, and does the content in the response body (if any) look like it was success or failure?
    – Rup
    Commented Mar 15, 2021 at 9:38
  • There's nothing in the network tab. Should it call an api or something? But I have a n error in the console: GET https://connect.facebook.net/en_US/fbevents.js net::ERR_BLOCKED_BY_CLIENT Maybe the facebook pixel is wrong? And btw the email is fake, I don't need it
    – user3001286
    Commented Mar 15, 2021 at 9:44
  • From this question I'd guess ERR_BLOCKED_BY_CLIENT is either a CORS-type error (but I'd expect Facebook to have that all set up correctly) or an ad block plugin or an anti-spam plugin from your anti virus. Can you try this on another PC that doesn't have any ad block plugins, or in a different browser?
    – Rup
    Commented Mar 15, 2021 at 9:50

1 Answer 1

3

Worked for me !!!

We get the error ERR_BLOCKED_BY_CLIENT on chrome if ad blocker is active. Just disable the ad blocker and it will do the work.