Facebook Pixel Snippet, add to snippets/script-tags

<!-- 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_HERE');

 document.addEventListener('appropo:pageview', function(e) {
    console.log("appropo:pageview", e.data);
    fbq('track', 'PageView');
 }, true);

  document.addEventListener('appropo:productview', function(e) {
    console.log("appropo:productview", e.data);
    fbq('track', 'ViewContent', {
        content_name: e.data.name,
        content_category: e.data.tag_path,
        content_ids: [e.data.id],
        content_type: 'product',
        value: e.data.unit_price,
        currency: 'NZD'
   });
 }, true);

  document.addEventListener('appropo:addtocart', function(e) {
    console.log("appropo:addtocart", e.data);
    fbq('track', 'AddToCart', {
        content_name: e.data.name,
        content_category: e.data.tag_path,
        content_ids: [e.data.id],
        content_type: 'product',
        value: e.data.unit_price,
        currency: 'NZD'
    });
 }, true);

  document.addEventListener('appropo:purchased', function(e) {
    console.log("appropo:purchased", e.data);
    fbq('track', 'Purchase', {
      value: e.data.total,
      currency:  e.data.currency,
      content_ids: e.data.order_items.map( function(oi) { return oi.id  } )
    } );
 }, true);

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

Ready to get started? Get in touch.

Contact