Facebook Pixel Standard Events tracking

New Member
13 0 0

I have a question about the new facebook pixel and how the code should look and how it should be placed. 

<!-- 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', '#################');
fbq('track', "PageView");
fbq('track', 'ViewContent');
fbq('track', 'Search');
fbq('track', 'AddToCart');
fbq('track', 'AddToWishlist');
fbq('track', 'InitiateCheckout');
fbq('track', 'Purchase', {value: '1.00', currency: 'EUR'});</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=##############&ev=PageView&noscript=1";
/></noscript>
<!-- End Facebook Pixel Code -->

 

Above is my code with things i want to track. Would I simply add the standard event codes to the same code i put into the theme.liquid file? Or would i have to seperate the invididual standard events to to those pages:AddToCart - does that go in cart.liquid code and not my theme.liquid code?  fbq('track', 'Search'); into search.liquid?

 

I have added  fbq('track', 'Purchase', {value: '1.00', currency: 'EUR'});</script> to my additional checkout scripts and its not in my theme.liquid code.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
370 0 32

Hello Nic, Ben here - your Shopify Guru! 

  You just place your new code in theme.liquid the same as you did with the old code. Facebook explains this in their documentation:

https://www.facebook.com/business/help/952192354843755

Keep your conversion tracking pixel where it is in the additonal contents and scripts and you should be all good. 

I hope this helps! Feel free to reach out if you have any further questions :)

Cheers,
Ben C - Shopify Guru
Support@Shopify.com

0 Likes
Highlighted
New Member
13 0 0

Hello Ben, 

Thanks for the answer! 

 

My question is a more about these 4 "Standard Events": AddToCart, Search, Initiate Checkout, and AddToWishlist. 

Would I be right in thinking that these 4 events should be placed in the global theme.liquid code as these events could be initiated from EVERY page? 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
370 0 32

Hey Nic, 

 As per their documentation, it looks as if you can simply update your code with those events. Having them in theme.liquid would do the trick as they can be intiated from any page. 

I hope this helps! Feel free to reach out if you have any further questions :)

Cheers,
Ben C - Shopify Guru
Support@Shopify.com

0 Likes
Highlighted
Shopify Expert
463 0 75

You should hook up certain FB events to fire only when the event actually happens, not merely when the page loads. The AddToCart event should be fired when the "Add to Cart" button is clicked and the InitiateCheckout event should be fired when the Checkout button is clicked, etc. On the search.liquid template you could paste the event script inside a {% if search.performed %} statement.

{% if search.performed %}
  <script>fbq('track', 'Search');</script>
{% endif %}

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
370 0 32

Hey Gina,

  That is great information, this would be theme dependent though. Some themes have add to cart buttons on the collection pages for example. Placing all the code on theme.liquid but wrapping it in conditional statements is a great idea. 

I hope this helps! Feel free to reach out if you have any further questions :)

Cheers,
Ben C - Shopify Guru
Support@Shopify.com

0 Likes
Highlighted
New Member
13 0 0

Thanks to both of you guys! Some great info here.

 

So having Initiate Checkout in the theme liquid code will fire InitiateCheckout event simply by loading the page? - and to avoid this they need to be wrapped in if then statements? 

 

0 Likes
Highlighted
New Member
13 0 0

Is there a resource where I can find the if/then variables? like {% if search.performed %} but for other actions such as add to cart?

0 Likes
Highlighted
New Member
5 0 0

Hi to all,

an official information/guide of how to place the code for Facebook standard events it seems to be missing in Shopify. At least i could not find it. I guess is very important since Facebok Ads is becoming more and more popular.

I also need a list of conditional variables.

Thank you everybody that can a help!
Simone

0 Likes
Highlighted
New Member
5 0 0

I opened a new post here regarding this topic because I got no answer.

https://ecommerce.shopify.com/c/shopify-discussion/t/facebook-standard-event-tracking-from-the-new-p...

0 Likes