Shopify6 min read1 view

Shopify GA4 view_item tracking with GTM

Map Shopify product views to GA4 view_item with a theme data layer, exact GTM event names and checks for the initial variant and price.

Watch on YouTube

Jump to the code

The short answer

Track Shopify product detail views by pushing product data from the storefront theme and sending GA4 view_item through GTM. Google's ecommerce guidedevelopers.google.com requires an item ID or item name in each item. This guide is for implementers maintaining a theme data layer and checking the initially viewed product variant.

  • If Google & YouTube already sends view_item, inspect it before adding another tag.
  • Use custom_view_item in GTM and view_item in GA4.
  • This snippet reads the initial product variant, not later selector changes.
  • Steps and settings checked against Google and Shopify documentation 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

What does GA4 view_item measure on Shopify?

Keep a product-list selection separate from the detail page it opens. Google's ecommerce guidedevelopers.google.com uses select_item for the selection and view_item for viewing the product details.

The video shows the older tag setup; use the current written steps for the exact event names and Google tag configuration.

When should I use this theme-based setup?

Use it when you maintain a storefront data layer and need a custom product mapping. If Google & YouTube already sends the right product views, another tag is the wrong fix.

This walkthrough uses GTM installed in the storefront theme. It does not feed a GTM container loaded inside a custom pixel; Shopify's migration tutorialhelp.shopify.com uses a subscription or an explicit published custom event to cross that boundary. Keep these theme snippets with the storefront container.

Shopify defines variant.price in the customer's presentment currencyshopify.dev, while shop.currency is the store currencyshopify.dev. Use cart.currencyshopify.dev, which follows presentment currency, and its iso_codeshopify.dev to label the rendered prices. The snippet still reads the variant selected when the page renders. For dynamic variant changes, adapt the mapping before using it.

Where do I find the GA4 destination?

Use the Measurement ID of the intended web stream. Google's event-tag instructionssupport.google.com use that ID to select the Analytics destination.

1. Confirm the stream

  1. Open the store's GA4 property.
  2. Open its web stream.
  3. Record the stream's Measurement ID.

Done when you have recorded its Measurement ID and checked that it belongs to the intended store.

Can I reuse the Measurement ID in GTM?

Yes. A Constant variablesupport.google.com stores a value you can reuse in tags.

2. Save the ID variable

  1. Create a Constant variable named GA4 Measurement ID.
  2. Enter the copied Measurement ID as its value.

Done when reopening it shows the same ID as the web stream.

Which base tag should I use for GA4?

Use the Google tag connected to that stream, as described in Google's current setup guidesupport.google.com.

3. Check the Google tag

Google's setup guidesupport.google.com documents the Google Analytics destination and the alternate Google tag method.

  1. Reuse the store's Google tag and GA4 web stream.
  2. If you use Google's alternate methodsupport.google.com, enter the stream's Measurement ID as Tag ID.
  3. With that method, use an Initialization trigger.

Done when the saved ID matches the intended stream.

What is the correct view_item trigger name?

The snippet pushes custom_view_item; use that exact name in the trigger. Google's ecommerce guidedevelopers.google.com names the GA4 product-detail event view_item.

4. Save the trigger

  1. Create a Custom Event trigger.
  2. Enter custom_view_item as the event name.
  3. Leave regular-expression matching off and save the trigger.

Done when its saved name matches the snippet exactly.

Where should I add the product-view snippets?

Create the two snippets in the development theme and render the head snippet once.

5. Prepare the theme

  1. Work on a development store.
  2. Duplicate the theme before editing, as Shopify's code-editing guidehelp.shopify.com advises.
  3. Confirm the storefront has the intended test GTM container.

Done when Preview connects to that container in the development theme.

What Liquid code sends product details to GTM?

The first snippet selects product pages; the second reads the initial variant and pushes custom_view_item.

6. Create head-datalayer.liquid

  1. In the development theme, create snippets/head-datalayer.liquid.
  2. Paste the code below into it and save.
liquid
<script>
  window.dataLayer = window.dataLayer || [];
</script>
 
{%- if template contains 'product' -%}
  {%- render 'datalayer-product', product: product -%}
{%- endif -%}

Done when the saved snippet renders datalayer-product only for product templates.

7. Create datalayer-product.liquid

Shopify's product referenceshopify.dev defines selected_or_first_available_variant, which the snippet reads.

  1. Create the datalayer-product.liquid snippet.
  2. Paste the product snippet below into it and save.
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 saved file uses that variant and pushes items, value and currency.

8. Render the head snippet once

  1. Open theme.liquid.
  2. Insert the line below once, after the data layer is initialized, and save.
liquid
{% render 'head-datalayer' %}

Done when the development product page's source contains the generated product payload once.

Which parameters should the GA4 view_item tag send?

Map the ecommerce items, currency and value from the product push.

9. Configure the GA4 Event tag

Data Layer Variablessupport.google.com read named values from the data layer. A trigger is the condition that runs a tag.

  1. Create a Data Layer Variable for each row in the table below.
  2. Choose Version 2 for nested fieldssupport.google.com.
  3. Enter the path from the table.
  4. Create a Google Analytics: GA4 Eventsupport.google.com tag with the intended Measurement ID.
  5. Set Event Name to view_item.
  6. Map each table row in Event Parameters.
  7. Attach the custom_view_item Custom Event trigger.

items

Data Layer Variable path
ecommerce.items
Check
The initially viewed variant

currency

Data Layer Variable path
ecommerce.currency
Check
Currency matching that price

value

Data Layer Variable path
ecommerce.value
Check
The item price for this one-item view
These paths must match the event payload.

Done when each saved variable has the correct path and reopening the tag shows that event name, stream, parameters and trigger.

10. Test the product view

Google's Preview guidesupport.google.com explains how to inspect fired tags and their data.

  1. Connect GTM Preview.
  2. Open a product page.
  3. Inspect custom_view_item and its ecommerce payload, and check that the expected GA4 tag fires with the product fields from this visit.
  4. Enable debug modesupport.google.com for the test session.
  5. Open GA4 Admin > Data display > DebugView.
  6. Select view_item and compare its event name, parameters, items, currency and amounts with your test action.
  7. Switch the development storefront to a second presentment currency different from the shop currency.
  8. Reload the product page and compare the event currency, item currency, rendered unit price and event value in GTM Preview and the fresh GA4 DebugView event.

Keep debug_mode out of the final non-test configuration.

Done when the expected GA4 tag fires with the product fields from this visit, the DebugView event name, products, currency and amounts agree with your test action, and in the second currency the event currency, item currency, rendered unit price and event value agree in GTM Preview and the fresh GA4 DebugView event.

Why does view_item show the wrong product?

Check the page-load data and the item identifier before changing the GA4 tag.

  • A trigger named custom view item will not match custom_view_item. Copy the snippet's exact name.
  • A variant selected after page load is not read by this snippet. Test the initially loaded variant and use an event-time mapping if later changes matter.
  • Sending item-level currency alone is not the same as mapping the event currency. Google's ecommerce guidedevelopers.google.com requires event-level currency when value is sent.

What should I check after the product view?

Verify Shopify add_to_cart and begin_checkout with the same item-ID convention.

What changed in this guide

  • 25 October 2026: Corrected space-separated event names to custom_view_item/view_item, added explicit GA4 parameters and completion checks, and documented the retained theme snippet's initial-variant and currency scope. Corrected both Liquid currency mappings to presentment currency and added a second-currency completion check while retaining the initial-variant limitation. Replaced the repeated opening with an event-specific test instruction.

Sources

13 sources
  1. 1Google's ecommerce guide↩
  2. 2Shopify's migration tutorial↩
  3. 3Shopify defines variant.price in the customer's presentment currency↩
  4. 4shop.currency is the store currency↩
  5. 5cart.currency↩
  6. 6iso_code↩
  7. 7Google's event-tag instructions↩
  8. 8Constant variable↩
  9. 9Google's current setup guide↩
  10. 10Shopify's code-editing guide↩
  11. 11Shopify's product reference↩
  12. 12Google's Preview guide↩
  13. 13debug mode↩