Shopify6 min read1 view

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.

Watch on YouTube

Jump to the code

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.

Ask an assistant

ChatGPTClaudePerplexity

FREE CALL

30 MIN

Meta stopped counting your leads? Get them counted again.

  1. Pick a time
  2. Check your Meta account with Hassan
  3. 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.

Book my free recovery callFree 30-minute call with Hassan.

Not ready to talk? Run a free check

How 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.

When 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.

How 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.

  1. Use a development store and a duplicate theme.
  2. From the test GTM container, copy both snippets.
  3. Place the script high in the head, following Google's installation placementsupport.google.com.
  4. Place the noscript block after the opening body tag.

Done when GTM Preview connects to the intended container on the test storefront.

How 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

  1. Create a tag from the Meta Pixel templategithub.com with your pixel ID.
  2. Choose standard event PageView.
  3. Fire it on All Pages, subject to the store's consent controls.
  4. 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.

What 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

  1. Create the head-datalayer snippet.
  2. Paste the first block below.
  3. If this helper already exists, merge the product condition into it instead of overwriting its other event code.
liquid
<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.

  1. Paste the product block below into the datalayer-product snippet.
liquid29 lines
{%- 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.

We email you a copy.

Done when the file is saved with custom_view_item and the original item fields intact.

5. Render the helper from theme.liquid

  1. Place the render statement below once in the test theme, after the GTM loader.
liquid
{% 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.

How 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.

  1. Download its template.tplraw.githubusercontent.com.
  2. In the test container, go to Templates > Variable Templates > New.
  3. Use More actions > Import.
  4. 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.

  1. Create Version 2 Data Layer Variablessupport.google.com for ecommerce.items and the other paths in the table.
  2. Use the Facebook Parameter Generatorraw.githubusercontent.com with the items variable, ID key item_id, name key item_name, price key price and quantity key quantity.
  3. Create its contents, IDs and name outputs.
  4. In the ViewContent tag, add the properties below.
  5. Enter your pixel ID.
  6. Leave automatic ecommerce mapping off.
  7. 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
These mappings use the original Liquid payload shown above.

Done when the saved tag reads the intended fields and uses only the custom_view_item trigger.

How 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

  1. Open a product page in the test theme.
  2. Select custom_view_item in Preview.
  3. Inspect the variables and confirm the event tag fires there.
  4. In the intended pixel's Test Events, find ViewContent from that visit.
  5. Compare its variant ID, currency and price with the initial product selection.
  6. Record the consent state.
  7. Repeat with the other consent choice.
  8. Switch the development storefront to a second presentment currency.
  9. Reload the same product in GTM Preview.
  10. 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.

Why 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.

What 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.

What 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
  1. 1Shopify's selected_or_first_available_variant↩
  2. 2Facebook and Instagram by Meta↩
  3. 3Shopify's legacy checkout script locations are retired↩
  4. 4Google's Preview mode↩
  5. 5Google's installation placement↩
  6. 6Meta Pixel template↩
  7. 7variant.price↩
  8. 8shop.currency↩
  9. 9cart.currency↩
  10. 10iso_code↩
  11. 11Meta Pixel template↩
  12. 12Facebook Parameter Generator repository is archived↩
  13. 13Google's template import instructions↩
  14. 14template.tpl↩
  15. 15Data Layer Variables↩