Search code examples
javascripttrackingfacebook-pixel

Multiple Facebook Pixels, errors in pixel helper


I need to use our own pixel as well as our customers pixel when tracking a conversion with the new pixel event: fbq('track', 'Purchase', {value: '0.00', currency: 'SEK'});

According to pixel-helper the pixel events are loaded. But then the same pixel gives error: "Facebook Pixel did not load"

Can I ignore thees errors since the pixel-events already seem to have loaded once. I've attached an image showing our pixel helper messages.

This is the messages I get from pixel-helper: Pixel Helper Messages

Here's the code that I've used in the head-tag on our thank you page:

<!-- Facebook Pixel Code -->
<script>
!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','//connect.facebook.net/en_US/fbevents.js');

fbq('init', 'Pixel_ID_1');
fbq('track', "PageView");
fbq('track', 'Purchase', {value: '{{ subtotal_price | money_without_currency }}',currency: '{{ shop.currency }}'});

</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=Pixel_ID_1&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->


<!-- Facebook Pixel Code -->
<script>
!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', 'Pixel_ID_2');
fbq('track', 'Purchase', {value: '{{ subtotal_price | money_without_currency }}',currency: '{{ shop.currency }}'});</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=Pixel_ID_2&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code —>

Solution

  • Initializing a second pixel calling fbq('addPixelId', '0123456789'); right after fbq('init', '9876543210'); did the trick for me.

    So the right way to include two pixels in your code would be like this:

    <!-- Facebook Pixel Code -->
    <script>
    !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','//connect.facebook.net/en_US/fbevents.js');
    
    fbq('init', 'Pixel_ID_1');
    fbq('addPixelId', 'Pixel_ID_2');
    fbq('track', "PageView");
    fbq('track', 'Purchase', {value: '{{ subtotal_price | money_without_currency }}',currency: '{{ shop.currency }}'});
    
    </script>
    <noscript>
    <img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=Pixel_ID_1&ev=PageView&noscript=1"
    />
    <img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=Pixel_ID_2&ev=PageView&noscript=1"
    />
    

    Checkout this question and answer as well