Shopify Facebook Pixel ViewContent with GTM
Track Shopify product views with GTM and Meta ViewContent. Keep the Liquid data layer, map product fields and test the initial variant.
Shahzada Ali Hassan, founder of Crisperchecked against 15 sources
The short answer
Track Shopify product views by pushing custom_view_item from the product template and sending Meta ViewContent through GTM. The preserved Liquid snippet reads the selected or first available variant when the page renders. This guide is for implementers maintaining a theme-based product view setup and checking its initial product data.
- GTM trigger:
custom_view_item; Meta event:ViewContent. - The snippet records the initial variant and quantity 1.
- If you need checkout tracking, use Customer events separately.
- Steps and settings checked against linked documentation and tutorial files on 25 October 2026.
FREE CALL
30 MINMeta stopped counting your leads? Get them counted again.
- Pick a time
Check your Meta account with Hassan- See what to do next
On a free 30-minute call, Hassan checks your Meta account with you and shows you what to do next.
Not ready to talk? Run a free check
01How do I track Shopify product views with Facebook Pixel?
Use a product-page data-layer event for ViewContent. The snippet below reads Shopify's selected_or_first_available_variantshopify.dev when Liquid renders the page; it is an initial product view, not a listener for later variant changes.
02When should I use theme-based ViewContent tracking?
Use this path when you maintain a Liquid storefront and need its custom product mapping. Inspect Facebook and Instagram by Metahelp.shopify.com first to avoid overlapping pixel installations. Checkout tracking belongs in Customer events; Shopify's legacy checkout script locations are retiredshopify.dev.
03How do I load GTM on Shopify product pages?
Install one test container in the theme before adding its product data layer.
1. Install the container in a test theme
Reuse an existing theme installation if it is already correct.
- Use a development store and a duplicate theme.
- From the test GTM container, copy both snippets.
- Place the script high in the head, following Google's installation placementsupport.google.com.
- Place the noscript block after the opening body tag.
Done when GTM Preview connects to the intended container on the test storefront.
04How do I configure the base Facebook Pixel?
Use the intended pixel ID for the separate PageView tag and the product tag.
2. Check the storefront base pixel
- Create a tag from the Meta Pixel templategithub.com with your pixel ID.
- Choose standard event PageView.
- Fire it on All Pages, subject to the store's consent controls.
- Save the tag.
Keep this separate from the product or collection tag.
Done when the base tag is saved against the intended pixel and PageView appears in your test session.
05What Liquid code sends product details to GTM?
Keep these three snippets together in the test theme. The first initializes the data layer and renders the product snippet only on product templates.
3. Create head-datalayer.liquid
- Create the head-datalayer snippet.
- Paste the first block below.
- If this helper already exists, merge the product condition into it instead of overwriting its other event code.
<script>
window.dataLayer = window.dataLayer || [];
</script>
Â
{%- if template contains 'product' -%}
{%- render 'datalayer-product', product: product -%}
{%- endif -%}
Done when the file is saved and its render call names datalayer-product.
Shopify defines variant.priceshopify.dev in the customer's presentment currency, meaning the currency shown to that visitor. shop.currencyshopify.dev is the store currency, which can differ. cart.currencyshopify.dev matches the customer's presentment currency on multi-currency stores and the store currency otherwise. Use its iso_codeshopify.dev to label the rendered prices.
4. Create datalayer-product.liquid
The product block sends the initial product view when the document loads.
- Paste the product block below into the datalayer-product snippet.
{%- liquid assign current_variant = product.selected_or_first_available_variant -%}Â <script>console.log("datalayer-product snippet is loaded")var itemObject = { item_id: {{ current_variant.id | json }}, id: {{ current_variant.id | json }}, item_name: {{ product.title | json }}, currency: {{ cart.currency.iso_code | json }}, item_brand: {{ product.vendor | json }}, item_category: {{ product.type | json }}, item_variant: {{ current_variant.title | json }}, price: {{ current_variant.price }} / 100, google_business_vertical: 'retail', quantity: 1}Â document.addEventListener('DOMContentLoaded', () => {
11 more lines of Liquid
- Copy and download
- Emailed to you
Unlock this snippet
Two details, and the full code is yours
No account needed. Unlock once and every snippet on the blog opens.
Done when the file is saved with custom_view_item and the original item fields intact.
5. Render the helper from theme.liquid
- Place the render statement below once in the test theme, after the GTM loader.
{% render 'head-datalayer' %}
Done when Preview shows custom_view_item on a product page and its ecommerce fields describe that product.
This code fixes quantity at 1 because it describes a product view. It does not update when the visitor changes variants without another page load; test that case separately before using the payload as evidence of a later selection.
06How do I map ViewContent properties in GTM?
Create a Custom Event trigger for custom_view_item and a Meta Pixel templateraw.githubusercontent.com tag with Standard > ViewContent. A trigger tells GTM which event should run the tag.
The original Facebook Parameter Generator repository is archivedgithub.com. To retain this tutorial's mapping, import its template into the test container, following Google's template import instructionsdevelopers.google.com.
- Download its template.tplraw.githubusercontent.com.
- In the test container, go to Templates > Variable Templates > New.
- Use More actions > Import.
- Select the file and save.
Done when Facebook Parameter Generator appears as a variable template with the documented array and key fields.
6. Map the product fields
A variable reads a named field for the tag.
- Create Version 2 Data Layer Variablessupport.google.com for
ecommerce.itemsand the other paths in the table. - Use the Facebook Parameter Generatorraw.githubusercontent.com with the items variable, ID key
item_id, name keyitem_name, price keypriceand quantity keyquantity. - Create its contents, IDs and name outputs.
- In the ViewContent tag, add the properties below.
- Enter your pixel ID.
- Leave automatic ecommerce mapping off.
- Attach only the custom_view_item trigger and save the tag.
contents
- Value to map
- Generator contents output
content_ids
- Value to map
- Generator IDs output
content_name
- Value to map
- Generator name output
content_type
- Value to map
- Literal product
value
- Value to map
- ecommerce.value
currency
- Value to map
- ecommerce.currency
Done when the saved tag reads the intended fields and uses only the custom_view_item trigger.
07How do I test Shopify ViewContent?
Test the storefront in GTM Previewsupport.google.com, then compare the destination event in Meta Events Manager.
7. Follow the event from the theme to Meta
- Open a product page in the test theme.
- Select
custom_view_itemin Preview. - Inspect the variables and confirm the event tag fires there.
- In the intended pixel's Test Events, find
ViewContentfrom that visit. - Compare its variant ID, currency and price with the initial product selection.
- Record the consent state.
- Repeat with the other consent choice.
- Switch the development storefront to a second presentment currency.
- Reload the same product in GTM Preview.
- Record both currency runs.
Done when the source fields and Meta event match, any additional firing is explained, and in the second currency the item price and ecommerce.value match the displayed initial variant price, both currency fields use that currency's ISO code, and Meta Test Events shows the same value and currency.
08Why is ViewContent showing the wrong product?
Start with the initial page data. This snippet is the wrong fix when you need checkout events or dynamic variant-selection tracking.
- Using All Pages for ViewContent: ordinary pages get labeled as product views. Use custom_view_item.
- Mixing product and variant IDs: the snippet uses variant IDs. Compare the emitted format with the IDs used by your catalog before claiming a match.
- Loading two product snippets: the same visit can create two pushes. Keep one render statement and inspect the event timeline.
09What should I track after a product view?
Continue with Shopify Add to Cart to capture the variant and quantity actually added, rather than reusing the initial product view.
10What changed in this guide
- 25 October 2026: Documented the archived generator import path. Clarified initial-variant and quantity scope, added current checkout-location guidance and explicit event checks. Corrected item and event currency to cart.currency.iso_code and added a second-presentment-currency check.
Sources
15 sources
- 1Shopify's selected_or_first_available_variantshopify.dev↩
- 2Facebook and Instagram by Metahelp.shopify.com↩
- 3Shopify's legacy checkout script locations are retiredshopify.dev↩
- 4Google's Preview modesupport.google.com↩
- 5Google's installation placementsupport.google.com↩
- 6Meta Pixel templategithub.com↩
- 7variant.priceshopify.dev↩
- 8shop.currencyshopify.dev↩
- 9cart.currencyshopify.dev↩
- 10iso_codeshopify.dev↩
- 11Meta Pixel templateraw.githubusercontent.com↩
- 12Facebook Parameter Generator repository is archivedgithub.com↩
- 13Google's template import instructionsdevelopers.google.com↩
- 14template.tplraw.githubusercontent.com↩
- 15Data Layer Variablessupport.google.com↩

