2

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: 'some@email.com' }
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!

Pejman Kheyri
  • 4,044
  • 9
  • 32
  • 39
  • 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 Mar 15 '21 at 09: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()` –  Mar 15 '21 at 09: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 Mar 15 '21 at 09: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 –  Mar 15 '21 at 09:44
  • [From this question](https://stackoverflow.com/questions/23341765/getting-neterr-blocked-by-client-error-on-some-ajax-calls) 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 Mar 15 '21 at 09:50
  • Yes you were right!! If I use the browser in incognito (so without adblock), It doesn't show any error. –  Mar 15 '21 at 10:02
  • @Rup Thank you btw man! Maybe the real problem is the configuration on the business facebook page. Which is not mine so I can't verify it in this moment –  Mar 15 '21 at 10:15

1 Answers1

1

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.

Udit
  • 129
  • 2
  • 6