I have been sent some html pixels by an outside company we are partnering with. There is 6 of them, each going on a different url (or multiple urls). Originally I thought I could put these pixels in the theme.liquid file, and while they did fire, and the company was able to see them, they fired on every page and not those specified by them.
Is there a way to code this in the theme.liquid file to be able to separate the specific pixels to their specific pages?
I’ve created some code for you that should hopefully solve this issue.
I’ve added comments to describe what to do, but in short:
Paste this code into your theme.liquid.
Where you see assign pixel1pages etc., replace my placeholders (e.g., ‘auckland,page-one’) with the handles of the pages you want that pixel to appear on.
Then just add the appropriate pixel code into each of the scripts, replacing the // Placeholder for Pixel script comments.
{%
# This Liquid code snippet manages pixel tracking based on page handles.
# Each pixel's visibility is determined by its associated page handles specified below.
# To add your pixel code, replace the "Placeholder for Pixel X script" comment
# with your actual tracking code within the respective script tags.
#
# Custom created by Ollie from [autoBlogger](https://apps.shopify.com/autoblogger)
%}
{% assign pixel1pages = 'auckland,page-one' | split: ',' %}
{% assign pixel2pages = 'page-three,page-four' | split: ',' %}
{% assign pixel3pages = 'page-five' | split: ',' %}
{% assign pixel4pages = 'page-six' | split: ',' %}
{% assign pixel5pages = 'page-one,page-three' | split: ',' %}
{% assign pixel6pages = 'page-four,page-five' | split: ',' %}
{% if pixel1pages contains page.handle %}
{% endif %}
{% if pixel2pages contains page.handle %}
{% endif %}
{% if pixel3pages contains page.handle %}
{% endif %}
{% if pixel4pages contains page.handle %}
{% endif %}
{% if pixel5pages contains page.handle %}
{% endif %}
{% if pixel6pages contains page.handle %}
{% endif %}
Remember to make this post as solved/useful if this is what you were after.