Ash Vardanian
Ash Vardanian

Reputation: 1

"Why might the 'PageView' action sometimes work if I only enabled the 'AddToCart' action on adding facebook pixel manually?"

const FacebookPixelScript:FC<{facebookPixels: IPixels}> = ({facebookPixels: { pixelId = "", pageViewTrack } = {}}) => {
    if (!pixelId) return null
    return <script
        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', ${pixelId});
        ${Number(pageViewTrack) ? `fbq('track', 'PageView');` : ""}
      `}}
    />
}

export default FacebookPixelScript;

"My pageViewTrack variable is always equal to 0, and this ${Number(pageViewTrack) ? fbq('track', 'PageView'); : ""} condition always returns false, but sometimes the 'page view' action still works. What could be causing this?

I tried to delete this line: (${Number(pageViewTrack) ? fbq('track', 'PageView'); : ""}) at all, but somtimes the pageView action still works...

In my project, everywhere there is an "addToCart" button, I import the code (see the screenshot below), and sometimes when clicking "addToCart," I don't know why the pageView also works. What could be causing this?

screenshot

Upvotes: 0

Views: 11

Answers (0)

Related Questions