Repository navigation
Conversation
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
frandiox
reviewed
Nov 13, 2026
frandiox
left a comment
Contributor
There was a problem hiding this comment.
FYI standard events exports createViewEventElement utility to create a web component hat emits view events, including product:view. Maybe that could be used here as well?
Collaborator
Author
Yep it definitely can and should be using |
Move the webpackIgnore CDN import from page-view.ts into a shared module so other emitters can load Standard Events classes from one place.
ProductView (React, Vue) renders the hydrogen-product-view element, built with createViewEventElement from the Standard Events module. The element sends shopify:product:view from itself: on render for the product page, when the closest dialog opens for dialogs, and when half of a card is visible for collection, search, and recommendation cards. The component sends the event again when the product ID changes. ShopifyScripts and initializeShopifyScripts register the element. Frameworks without a binding use PRODUCT_VIEW_TAG_NAME and getProductViewAttributes.
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 hydrogen-product-view element with getProductViewAttributes, keyed by product ID.
Ji-One1
force-pushed
the
jb/hydrogen-product-view-event
branch
from
November 17, 2026 04:49
66c84d3 to
97d95a4
Compare
Ji-One1
marked this pull request as ready for review
November 17, 2026 06:26
Keep className as the public prop and pass class to the custom element. Clarify view-event trigger counts and regenerate the API docs.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs Shopify/developer-tools-team#1285
TL;DR: Adds
ProductView, a component that sends theshopify:product:viewStandard Event for a product that the storefront shows, on the product page and on product cards. It is built oncreateViewEventElementfrom the Standard Events module, the same tool that Shopify's Liquid themes use.Standard Events let tools such as PerfKit, the Standard Events inspector, and agentic tests read what the buyer sees. Today Hydrogen sends only
shopify:page:viewand the cart events, so nothing tells these tools which products the buyer looked at.An earlier version of this PR sent the event from the product form store. Following the review, it now uses
createViewEventElement, and the storefront places it explicitly. This follows Hydrogen's "no magic" rule, and it works for cards too, which the store could not do.Before
Product pages and product cards send no product event.
After
The element sends:
What this changes
ProductView(React and Vue) renders ahydrogen-product-viewelement. It is made withcreateViewEventElement()fromhttps://cdn.shopify.com/storefront/standard-events.js. The element sends the event from itself, and the event bubbles todocument.contextis required, and it decides when the event fires:page: when the element appears.collection,search,recommendation: when half of the card is visible. Each card fires once.dialog: when the closest<dialog>opens.pageanddialoginclude the selected variant. Card contexts sendselectedVariant: nullandselectedOptions: [], as the Standard Events docs say for cards, and need only the productid,title, andhandle.ProductViewsends the event again. A variant change does not.ShopifyScriptsandinitializeShopifyScripts()register the element one time. If the CDN module fails to load, nothing breaks, and no event is sent.PRODUCT_VIEW_TAG_NAMEwith the attributes fromgetProductViewAttributes(). The SvelteKit and Solid examples show how.ProductViewto the product page and to every product card, with the context of each list. The card queries now ask for the productid.ProductView.Developer impact
Includes a minor changeset for
@shopify/hydrogen. New exports:@shopify/hydrogen/reactand@shopify/hydrogen/vue:ProductView,ProductViewProps.@shopify/hydrogen:PRODUCT_VIEW_TAG_NAME,getProductViewAttributes,defineProductView,ProductViewOptions,ProductViewProduct.Hydrogen doesn't send the event on its own. Existing storefronts must add
ProductViewwhere they show products to get the event. Nothing else changes for them.The element is inline by default. Card contexts need a box (for example
className="block"), because the element measures how much of itself is visible.UX impact
No visible change. The template and examples wrap the existing markup in the new element, with a
blockclass, and keep the same layout, accessible names, and test IDs.Out of scope
shopify:product:select,shopify:search:update,shopify:collection:view, andshopify:cart:view.data-*test attributes).Risk
ProductViewsends no product event. TypeScript can't catch this. The template, examples, and skills show it.classNameon custom elements was not tested.How to Test
pnpm install && pnpm build:pkgs.templates/react-router, runpnpm dev. With no.env, the template uses mock.shop.document.addEventListener("shopify:product:view", (e) => console.log(e.context, e.product.handle, e.target.tagName), true).collectionlog for each card when it comes into view, and no duplicates.pagelog with that handle and theHYDROGEN-PRODUCT-VIEWtarget.pagelog.recommendationlogs.pagelog.searchlogs for the visible results.debug={{ standardEventsInspector: true }}to<ShopifyScripts>inapp/root.tsx, reload a product page, and confirm that the inspector shows oneshopify:product:view.