Shopify9 min read

Shopify collection tracking for Google Ads remarketing

Send Shopify collection views to Google Ads with GTM. Map product variants to feed IDs and test view_item_list dynamic remarketing data.

The short answer

Map Shopify collection views to view_item_list in GTM and send product IDs that match your Google Ads retail feed. Shopifyshopify.dev provides the collection ID, title and product variants in the collection_viewed payload. This guide is for store owners and implementers maintaining a custom pixel.

Ask an assistant

ChatGPTClaudePerplexity

Jump to the code

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 is a collection view different from a product view?

A collection viewshopify.dev covers a product list, while a product viewshopify.dev covers a product details page. Test the list first, then open one product and check its separate trigger.

How do I add the custom pixel in Shopify?

Prepare this walkthrough in a development store with a test GTM container. Shopify suggests testing pixels in a dev storehelp.shopify.com before adding them to a live store.

1. Open Customer events and check the loader

  1. In the test store, open Settings > Customer events > Add custom pixel.
  2. Name the pixel.
  3. Review its Customer privacy settings using Shopify's pixel instructionshelp.shopify.com, and use settings that match your consent plan.

Shopify's GTM tutorialhelp.shopify.com uses the container loader as JavaScript without script tags. The snippet below includes a loader.

  1. Replace the snippet's GTM placeholder with the ID of a test container that only your development store loads.
  2. If this pixel already loads GTM, keep that loader once and append only the event subscription and its helper.

Done when the editor is open, the privacy settings are recorded and the pixel contains one loader for the intended test container.

What code tracks Shopify collection views?

Subscribe to collection_viewed and push the mapped values into the data layerdevelopers.google.com, the object GTM reads for events. The Shopify event referenceshopify.dev documents the fields used below.

2. Add the event subscription

event.data.collection supplies id, title and productVariants, as listed in Shopify's payload referenceshopify.dev. The callback is the function that runs when Shopify delivers this event.

  1. Add the snippet below to the pixel's code.
  2. Save and connect the pixel in the test store following Shopify's connection stepshelp.shopify.com.
view_item_list.js89 lines
// Initialize the dataLayerwindow.dataLayer = window.dataLayer || [];(function (w, d, s, l, i) {  w[l] = w[l] || [];  w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });  var f = d.getElementsByTagName(s)[0],    j = d.createElement(s),    dl = l != "dataLayer" ? "&l=" + l : "";  j.async = true;  j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;  f.parentNode.insertBefore(j, f);})(window, document, "script", "dataLayer", "GTM-EXAMPLE");function logEventToConsole(dataLayerEvent) {  const customStyle01 =    "color: #FFFF00; background-color: #000000; font-size: 10px; font-weight: bold; padding: 2px 0;";  console.log("%cDataLayer Event: view_item_list ", customStyle01, {    event: dataLayerEvent.event,    event_id: dataLayerEvent.event_data.id,

71 more lines of JavaScript

  • 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 Customer events shows Connected and the saved code contains the collection_viewed subscription once.

Shopify's event referenceshopify.dev allows product and variant IDs to be null. The filter keeps only rows whose product and variant IDs are strings with non-empty trim() results before mapping items. It preserves each retained ID unchanged. The event and its value stay intact even when no valid item remains.

The snippet sums the listed variant prices for its existing value field. That is an illustrative list value, not cart value or revenue; this tag leaves optional Event Value empty.

This revision keeps page details in page_data without changing browser history. history.pushState requires a same-origin URLdeveloper.mozilla.org; the event push no longer depends on that extra operation succeeding.

Use Google Ads Remarketing for this event. Google's tag instructionssupport.google.com describe the ID and label fields.

3. Create the variables and event trigger

A Data Layer Variable reads a named value for a tag, and a trigger tells GTM when to run a tag.

  1. Create each Data Layer Variable in the table below, using Version 2, which reads dots as nested fieldssupport.google.com.
  2. Create a Custom Event triggersupport.google.com with event name view_item_list.
  3. Turn regular-expression matching off on that trigger.

DLV - Value

Data layer variable name
ecommerce.value
Purpose
Checkout or item amount

DLV - Currency

Data layer variable name
ecommerce.currency
Purpose
Currency from Shopify

DLV - Items

Data layer variable name
ecommerce.items
Purpose
Shopify items to map to feed IDs
These paths match this snippet. Creating a variable does not send it to Google Ads.

Done when the saved variable names and paths match the table and the trigger's saved event name is view_item_list.

4. Map the tag fields

For retail, Google requires an item id matching the feed's id, item_group_id or display_ads_id, and recommends google_business_vertical: "retail"support.google.com. The snippet's item_id and product_id are Shopify identifiers; neither is automatically your feed ID.

  1. Create a Custom JavaScript variable named JS - Ads items with the mapping below.
  2. Replace the placeholder entries using the exact Shopify variant IDs and feed IDs from your test products.
gtm-ads-items.js27 lines
function () {  var items = {{DLV - Items}};  // Replace these placeholders with verified IDs from your store and feed.  // Add an entry for every variant included in this test.  var feedIdsByVariant = {    "REPLACE_SHOPIFY_VARIANT_ID": "REPLACE_MERCHANT_CENTER_ID"  };  if (!Array.isArray(items)) {    throw new Error("Dynamic remarketing needs an item array");  }  // No identifiable products: keep the data-layer event, but do not fire the tag.  if (items.length === 0) return [];  return items.map(function (item) {    var variantId = String(item.product_id);    if (!Object.prototype.hasOwnProperty.call(feedIdsByVariant, variantId)) {      throw new Error("Missing verified feed ID for variant " + variantId);    }    var feedId = feedIdsByVariant[variantId];

9 more lines of JavaScript

  • Copy and download
  • Emailed to you

Unlock this snippet

One form opens every snippet on the blog

Missing or empty feed IDs raise an error; correct the mapping before testing the tag. An empty source array returns an empty mapping for the trigger to exclude.

Google recommends sending the most relevant items rather than the entire viewed product listsupport.google.com. Before using this mapping beyond your test collection, have your developer select the relevant variants from ecommerce.items; do not guess a universal item limit.

  1. Create another Custom JavaScript variable named JS - Ads item count with the code below. It counts the validated feed items returned by JS - Ads items.
gtm-ads-item-count.js
function () {
  var items = {{JS - Ads items}};
  return Array.isArray(items) ? items.length : 0;
}
  1. On the event trigger, choose Some Custom Events.
  2. Add the condition JS - Ads item count greater than 0, using GTM trigger filterssupport.google.com.
  3. Keep the exact event name and attach this filtered trigger to the remarketing tag.
  4. In the remarketing tag, enable Send dynamic remarketing event data.
  5. Fill the fields below. Google's GTM example uses Event Name, Event Value and Event Itemssupport.google.com; these mappings adapt that example to this snippet.
  6. Check the associated Google tag is present in the test container; Google's remarketing instructions require it for optimal browser compatibilitysupport.google.com. The Google tag IDsupport.google.com is distinct from your GTM- container ID.
  7. Save the event tag.

Conversion ID

Setting
Your Google Ads audience-source Conversion ID

Conversion Label

Setting
Leave empty for this example

Event Name

Setting
view_item_list

Event Value

Setting
Leave empty; optional for this collection example

Event Items

Setting
{{JS - Ads items}}

Trigger

Setting
view_item_list; JS - Ads item count greater than 0
Event Items uses the Google Ads retail schema, not the raw Shopify item array.

Done when each tested variant has a non-empty entry that matches the feed, the saved trigger contains the item-count condition, the tag has no additional unfiltered trigger, and the tag's fields, destination and trigger match your test plan.

How do I test collection views on Shopify?

Use Customer events > Test to inspect the event with Shopify Pixel Helperhelp.shopify.com, then inspect the Google request separately. Start with the test store and test container prepared above.

5. Publish the version in the test container

Changes saved in a workspace do not run yet. Google sayssupport.google.com you need to publish workspace changes to make them operational.

  1. Open the test container that only your development store loads.
  2. Select Submit.
  3. Choose Publish and Create Version.
  4. Name the version and publish.

Do not publish to a container your live store loads; move the tested setup there through your normal release process.

Done when the test container's Versions list shows your version as published and the pixel code loads that container's ID.

6. Follow one test action through the setup

  1. Open the connected custom pixel and choose Test using Shopify's testing stepshelp.shopify.com.
  2. Exercise the consent choice for your test, and check that Pixel Helper's consent status matches that choice.
  3. Open a collection page with known products in the test store.
  4. In Pixel Helper, check that collection_viewed is listed, and inspect the collection title and the variant IDs selected for the remarketing request.
  5. Inspect the pixel's console entry and data-layer push for view_item_list: the event name should match your saved GTM trigger and the expected fields should contain the test values.
  6. In browser developer tools, inspect the outgoing Google Ads remarketing request: its destination, view_item_list event and retail item IDs should match your test product feed.
  7. Record the test time, event ID, container version and observed request fields.
  8. Run the subscription locally with null, empty, whitespace-only and non-string values for each ID field.
  9. Test a mixed list with a valid item, then an all-invalid list.
  10. Repeat with amounts of 0 and a nonzero amount, passing retained items through any downstream formatter. The event, currency and value should stay intact, genuine IDs should remain unchanged, and no mapped ID should be blank or replaced by a product name.
  11. Resolve DLV - Items, JS - Ads items and JS - Ads item count by name in that order. The count should match the mapped feed items, an empty mapping should give 0 and exclude the tag, and missing or blank feed IDs should raise an error.

Done when every check above matches and your notes identify what passed and any missing or repeated request that still needs investigation.

When is this the wrong setup, and what can go wrong?

Use this guide when you need to maintain this custom event mapping. Shopify advises reviewing available apps before creating a custom pixelhelp.shopify.com; if an app already handles the job, inspect that integration first.

  • Treating the sum of collection prices as sales revenue: no sale occurred. Leave Event Value empty for this remarketing example.
  • Adding a second sender without checking the first: Shopify warns overlapping pixel installations can count events twicehelp.shopify.com. Inventory the existing event sender before adding this one.
  • Saving a tag without checking the actual request: a filled-out tag is only a configuration. Match the request fields to your recorded test action.

If you also need storefront coverage, the Shopify Google Ads page-view guide walks through the separate page-view trigger.

What changed in this guide

  • 25 October 2026: Added the Shopify event explanation, Google Ads tag mappings and test checks; preserved existing event names and corrected payload handling. Added explicit Merchant Center feed-ID mapping for retail remarketing. Removed the history update before the event push. Added the isolated test-container publication procedure and published-version check. Filtered items missing either product or variant IDs and added null-item checks without changing event values. Added an empty-items trigger condition and validation for blank feed IDs. Replaced the repeated introduction with the next event-specific check. Rejected whitespace-only and non-string item IDs while preserving genuine IDs, and added formatter checks for mixed and invalid items. Corrected the Ads items input to DLV - Items while retaining the mapped-item count and greater-than-zero trigger.

Sources

16 sources
  1. 1collection_viewed↩
  2. 2Remarketing labels are optional↩
  3. 3product view↩
  4. 4Shopify suggests testing pixels in a dev store↩
  5. 5Shopify's pixel instructions↩
  6. 6Shopify runs custom pixels in a sandbox↩
  7. 7Shopify's GTM tutorial↩
  8. 8data layer↩
  9. 9history.pushState requires a same-origin URL↩
  10. 10Version 2, which reads dots as nested fields↩
  11. 11Custom Event trigger↩
  12. 12Google requires an item id matching the feed's id, item_group_id or display_ads_id, and recommends google_business_vertical: "retail"↩
  13. 13GTM trigger filters↩
  14. 14Google's GTM example uses Event Name, Event Value and Event Items↩
  15. 15Google tag ID↩
  16. 16Google says↩