Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi all. PageSpeed Insights is showing that the Facebook pixel is significantly slowing down my site by about .5 seconds. I found a suggested solution here suggesting that the pixel be placed in the footer and delayed by 3 seconds. My issue is that I am not able to find my FB pixel in theme.liquid. Any help is greatly appreciated.
Website is www.ploutone.com. Theme is Blackery
Hello @Ploutone,
I am Gina from flareAI app, and I am here to provide assistance.
It's possible that the Facebook pixel code is not located in the theme.liquid file, as it could have been added to the website in a different way. Here are a few steps you can follow to locate the Facebook pixel code in your Shopify store:
1. Check the theme.liquid file: Start by searching for "fbq" (the shorthand for the Facebook pixel) in the theme.liquid file. If it's not there, search for the entire pixel code, which starts with "!function(f,b,e,v,n,t,s)".
2. Check the checkout.liquid file: If the pixel code is not in the theme.liquid file, check the checkout.liquid file. Some Shopify stores add the pixel code to the checkout.liquid file instead of the theme.liquid file.
3. Check the theme's custom HTML section: If you still can't find the pixel code in the theme.liquid or checkout.liquid files, check the theme's custom HTML section. Some stores add the pixel code to this section in the theme editor.
4. Check the theme settings: Finally, check the theme settings for a "Facebook Pixel" section, which may contain the code.
Once you've located the pixel code, you can follow the suggestion you found and place it in the footer and delay it by 3 seconds. To do this, wrap the pixel code in a JavaScript function and use the "setTimeout" function to delay the execution of the function by 3 seconds:
<script>
setTimeout(function() {
<!-- Facebook Pixel Code -->
}, 3000);
</script>
Place this code in the footer of your theme, either in the theme.liquid file or in the theme's custom HTML section.
Hope this helps
Gina
Hi Gina. I appreciate your assistance. Unfortunately, I was unable to find any of those codes in my theme files.
Hi @Ploutone,
We have gone through the reference document that you have shared regarding how you can lazyload the Facebook pixel script, but the solution mentioned in the reference document would only work when you are adding the pixel code manually. This solution won't work when the Facebook pixel code is injected directly from the {{ content_for_header }} as in the case of your store.
In order to fix this in this scenario, you need to hire a developer who can lazyload the scripts coming directly from the {{ content_for_header }}.
Also, as I have checked your website, it contains some other very major speed issues such as CLS that can be worked on, and once this is fixed, it will give a significant boost to your website speed.
All the best,
CedCommerce
Hi CedCommerce. Thanks so much for sharing that advice.
Hi @Ploutone
Following Shopify's official Facebook pixel advice is the correct way to implement the fb pixel.
Putting the facebook pixel inside a timeout could make the pixel code malfunction (not tracking some behaviour / tracking it wrongly).
There are other unseen parts to the Fb Pixel (like conversions API tracking on the server side which shopify implements) that could be affected by non-standard implementations.
I would suggest sticking to the official way of implementing tracking codes like Google Analytics and Facebook Pixel and not changing too much the way they are implemented in Shopify.
If you have any questions you can drop me a message.
Regards,
Cristian
Thank you for your help!
Your site seems pretty quick... especially compared to mine (phoxwater.com) any tips?
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025