Shopify GA4 view_cart tracking with GTM
Track Shopify cart-page views with GA4 view_cart, use the cart's currency and item prices, and test the data layer before adding checkout events.
Shahzada Ali Hassan, founder of Crisperchecked against 13 sources
The short answer
Track a Shopify cart-page view by sending GA4 view_cart with the cart's items, currency and value through GTM. Google's ecommerce guidedevelopers.google.com distinguishes viewing a cart from starting checkout. This guide is for implementers maintaining a storefront theme data layer and testing a full cart-page load, not a cart drawer.
- If Google & YouTube already sends view_cart, inspect it before adding a tag.
- Use
custom_view_cartfor the trigger andview_cartfor GA4. - Run the Liquid snippet only on the cart template.
- Steps and settings checked against Google and Shopify documentation 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
01What does GA4 view_cart measure?
Load a test cart whose products and quantities you can recognize, then record those values before testing. Compare that snapshot with the items in Google's view_cart exampledevelopers.google.com.
The video shows the older snippet; the written version adds a cart-template guard and corrects the currency and line-price fields.
02When should I use this cart-page setup?
Use it when the store has a full cart page and a storefront GTM data layer you maintain. Google's current Shopify guidesupport.google.com includes view_cart in the app integration, so inspect the native GA4 setup first.
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.
This is the wrong fix for a cart drawer or cart updates without a page reload. The Liquid payload below is a snapshot of the cart at page render; those interfaces need a mapping that runs when the cart is displayed or updated.
03How do I connect the cart tag to GA4?
Reuse the Google tag for the intended GA4 web stream.
1. Check the destination
Google's setup guidesupport.google.com documents the Google Analytics destination and the alternate Google tag method.
- Reuse the store's Google tag and GA4 web stream.
- For Google's alternate methodsupport.google.com, enter the stream's Measurement ID as Tag ID.
- Give that Google tag an Initialization trigger.
Done when the saved ID matches the intended stream.
04Where should the cart data layer run?
Run it only on the full cart template. Shopify's template referenceshopify.dev provides template.name, including the cart type.
05What should I give the developer?
Give them this page, the development theme, the intended GTM container ID and the test cases below. Ask them to confirm that the storefront container reads the same data layer as the snippet.
06How do I add the cart snippet to the theme?
Create a cart snippet in the development theme and render it once.
2. Prepare the theme
- Work on a development store.
- Duplicate the theme before editing, as Shopify's code-editing guidehelp.shopify.com advises.
- Confirm the storefront has the intended test GTM container.
Done when Preview connects to that container in the development theme.
3. Save and render the snippet
- Save the code below as snippets/datalayer-cart.liquid.
- Place
{% render 'datalayer-cart' %}once in theme.liquid. The snippet contains its own cart-page guard.
Done when the development cart page source contains custom_view_cart and a product page does not.
07What code sends the cart items to GTM?
The code reads Shopify's cart and sends one cart snapshot with its item amounts.
Shopify's cart referenceshopify.dev exposes the cart's presentment currency, and its line-item referenceshopify.dev defines final_price as the unit price including line-level discounts. The sample uses those fields so the currency label and prices agree.
{% if template.name == 'cart' %}<script type="text/javascript"> window.dataLayer = window.dataLayer || []; console.log("datalayer-cart snippet is loaded") const cart_data = {{ cart | json}}; var product_details = cart_data.items.map((item, index)=>{ return { item_id: item.id, id: item.id, item_name: item.product_title, item_brand: item.vendor, item_category: item.product_type, quantity: item.quantity, currency: {{ cart.currency.iso_code | json }}, google_business_vertical: 'retail', price: parseFloat(item.final_price / 100.0) }
17 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.
08How do I configure the GA4 view_cart tag?
Map the cart fields into a GA4 Event tag and fire it on custom_view_cart.
4. Create the variables and trigger
- Create Data Layer Variablessupport.google.com, which read named values from the data layer.
- Choose Version 2 for nested fieldssupport.google.com.
- Enter the paths below.
- Save an exact-match Custom Event trigger for custom_view_cart.
- Create a Google Analytics: GA4 Eventsupport.google.com tag.
- Enter the intended Measurement ID.
- Set Event Name to
view_cart. - Map each table row in Event Parameters.
- Attach the
custom_view_cartCustom Event trigger. A trigger is the condition that runs a tag. - Save the tag.
items
- Data Layer Variable path
- ecommerce.items
- Check
- Products and quantities in the rendered cart
currency
- Data Layer Variable path
- ecommerce.currency
- Check
- The cart's presentment currency
value
- Data Layer Variable path
- ecommerce.value
- Check
- Sum of item unit price times quantity
Done when each saved variable has the correct path, the trigger's saved name matches the snippet, and reopening the tag shows that event name, stream, parameters and trigger.
09How do I test the cart event?
Compare the rendered cart, GTM payload and received GA4 event.
5. Check the cart snapshot
Google's Preview guidesupport.google.com explains how to inspect fired tags and their data.
- Open GTM Preview.
- Load a cart containing a known product and quantity.
- Inspect
custom_view_cartand its ecommerce payload. - Check that the expected GA4 tag fires with the product fields from this visit.
- Enable debug modesupport.google.com for the test session.
- Open GA4 Admin > Data display > DebugView.
- Select
view_cartand compare its parameters and items with your test action. - Change the quantity, then reload.
- Test a line-level discount.
- Switch the development storefront to a second presentment currency different from the shop currency.
- Reload the cart page.
- Keep debug_mode out of the final non-test configuration.
Done when the event name, products, currency and amounts agree in DebugView; after the quantity change and discount the payload matches the new cart and the calculated value matches the item prices it sends; and in the second currency the event currency, item currencies, rendered unit prices and calculated cart value agree in GTM Preview and the fresh GA4 DebugView event.
Google's event referencedevelopers.google.com defines value as the sum of price times quantity without shipping or tax.
10Why does view_cart contain stale or wrong values?
Check where the snippet runs and when its Liquid data was rendered.
- Placing an unguarded snippet in every page counts non-cart visits. Keep the template.name cart guard.
- Reading shop currency can mislabel local-currency amounts. Use the cart currency with its presentment prices.
- A cart drawer can change after the Liquid snapshot. Use a cart event from the current interface instead of assuming this snippet updates itself.
11What should I test after the cart page?
Check Shopify checkout entry and purchase tracking. Compare item IDs and quantity definitions across each step.
12What changed in this guide
- 25 October 2026: Added a cart-template guard and data-layer initialization, corrected cart currency and discounted unit prices, fixed the purchase-event wording and added full-page scope and GA4 tests. Added a second-presentment-currency completion check in Preview and DebugView. Replaced the repeated opening with an event-specific test instruction.
Sources
13 sources
- 1Google's ecommerce guidedevelopers.google.com↩
- 2Google's view_cart exampledevelopers.google.com↩
- 3Google's current Shopify guidesupport.google.com↩
- 4Shopify's migration tutorialhelp.shopify.com↩
- 5Google's setup guidesupport.google.com↩
- 6Shopify's template referenceshopify.dev↩
- 7Shopify's code-editing guidehelp.shopify.com↩
- 8Shopify's cart referenceshopify.dev↩
- 9its line-item referenceshopify.dev↩
- 10Data Layer Variablessupport.google.com↩
- 11Google Analytics: GA4 Eventsupport.google.com↩
- 12Google's Preview guidesupport.google.com↩
- 13debug modesupport.google.com↩


