0

I am working on a website build with NextJS. I have added the Pixel to my website, but the pixel is not working correctly. I have added the below code to my _app.tsx also tried placing the code in [[...pages ]]

<Script
        id="fb-pixel"
        strategy="afterInteractive"
        dangerouslySetInnerHTML={{
          __html: `
            !function(f,b,e,v,n,t,s)
              {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
              n.callMethod.apply(n,arguments):n.queue.push(arguments)};
              if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
              n.queue=[];t=b.createElement(e);t.async=!0;
              t.src=v;s=b.getElementsByTagName(e)[0];
              s.parentNode.insertBefore(t,s)}(window, document,'script',
              'https://connect.facebook.net/en_US/fbevents.js');
              fbq('init', '602606363244718');
              fbq('track', 'PageView');
          `,
        }}
/>

I have also tried with

useEffect(() => {
    import('react-facebook-pixel')
      .then((x) => x.default)
      .then((ReactPixel) => {
        ReactPixel.init('XXXXXXXXXXXXXXXXXXXXX') // facebookPixelId
        ReactPixel.pageView()

        router.events.on('routeChangeComplete', () => {
          ReactPixel.pageView()
        })
      })
  }, [router.events])

I have added Google Analytics and Messanger Chat plugins those are working fine, only the Facebook Pixel is not working.

But, sometimes the pixel activates, and sometimes not. Can Does anybody help me with that?

Minhaj Hasan
  • 45
  • 1
  • 8
  • The website where the pixel is added in, https://shop.rangs.com.bd, Google Analytics, and Facebook chat are working fine. Only the Pixel is not working. – Minhaj Hasan Sep 18 '22 at 04:52
  • 1
    Take a look to https://stackoverflow.com/questions/64792217/how-to-add-facebook-pixel-on-next-js-react-app – Maxi Sc Sep 30 '22 at 17:56

0 Answers0