Skip to content

feat(templates): send product view events in the template and examples - #4403

Open
Ji-One1 wants to merge 2 commits into
jb/hydrogen-product-view-eventfrom
jb/hydrogen-product-view-apps
Open

Ji-One1 wants to merge 2 commits into
jb/hydrogen-product-view-eventfrom
jb/hydrogen-product-view-apps

Conversation

@Ji-One1

@Ji-One1 Ji-One1 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #4376. Refs Shopify/developer-tools-team#1285

Part 2 of 4. Adds ProductView from #4376 to the React Router template and the examples.

TL;DR: The template and all five examples now send shopify:product:view on product pages and product cards.

Before

The template and examples send no product view event.

After

Product pages are wrapped in <ProductView context="page">, and each product card in <ProductView context="collection" | "search" | "recommendation">, with the context of the list that shows it.

What this changes

  • React Router template: ProductView on the product page, on product cards (home and collection pages use collection, search uses search, related products use recommendation), and in the search drawer. The product card fragment now asks for the product id.
  • Hydrogen, Next.js, and Nuxt examples: the same, using the React and Vue ProductView components.
  • SvelteKit and Solid examples: they render the shopify-product-view element with getProductViewAttributes(). Solid sets the attributes with attr:, because the element reads HTML attributes.
  • Product cards get a block class, so the visibility check can measure them.

Developer impact

No changeset: these are template and example changes only. They show the supported pattern for ProductView.

UX impact

No visible change. The new element wraps the existing markup, with a block class, and keeps the same layout, accessible names, and test IDs.

Risk

  • Cards that are keyed by product remount on sort or filter changes, so the same products can send a view again when they come back into view.

How to Test

  1. Run pnpm install && pnpm build:pkgs.
  2. In templates/react-router, run pnpm dev. With no .env, the template uses mock.shop.
  3. Open the local URL that the dev server prints. In DevTools, run document.addEventListener("shopify:product:view", (e) => console.log(e.context, e.product.handle, e.target.tagName), true).
  4. Scroll down the home page. Confirm one collection log for each card when it comes into view, and no duplicates.
  5. Click a product. Confirm one page log with that handle and the SHOPIFY-PRODUCT-VIEW target.
  6. Select a different variant. Confirm no new page log.
  7. Scroll to the related products. Confirm recommendation logs.
  8. Click a related product. Confirm exactly one new page log.
  9. Search for "shirt". Confirm search logs for the visible results.
  10. To check a full page load, add debug={{ standardEventsInspector: true }} to <ShopifyScripts> in app/root.tsx, reload a product page, and confirm that the inspector shows one shopify:product:view.

Wrap the product page in ProductView with context page, and each product
card with the context of its list: collection, search, or recommendation.
Add the product ID to the product card fragment.
Add ProductView to the product page and product cards of the Hydrogen,
Next.js, and Nuxt examples. The SvelteKit and Solid examples render the
shopify-product-view element with getProductViewAttributes. Solid sets
the attributes with attr:, because the element reads HTML attributes.
@Ji-One1
Ji-One1 force-pushed the jb/hydrogen-product-view-apps branch from d8bc01a to d2fbef4 Compare November 20, 2026 06:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant