`shopify:page:view` fires when `history.replaceState` changes only the query, as a variant selection does
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 53/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- react, typescript
Research direction
Start with packages/hydrogen/src/core/shopify-scripts/page-view.test.ts and compare its existing navigation tests with the provided query-only replaceState reproduction. Then read packages/hydrogen/src/core/shopify-scripts/page-view.ts and utils/navigation.ts to trace both observer paths. First determine the intended behavior from the conflicting docs and recipes; done means the behavior is documented and covered by tests for the relevant navigation cases.
Written by the indexing model from the issue text.
Description
What is the location of your example repository?
None. The test below reproduces it in page-view.test.ts.
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
2026.10.3
What version of React Router 7 are you using?
Not applicable: the core entry's initializeShopifyScripts.
Steps to Reproduce
- On a page that has called
initializeShopifyScripts(), listen for the standard event:document.addEventListener('shopify:page:view', (event) => console.log(event.page.url)); - Write a selected option into the URL in place, as a product form does for a variant selection:
history.replaceState(history.state, '', '?Size=m');
As a test beside the others in packages/hydrogen/src/core/shopify-scripts/page-view.test.ts:
it("ignores a query replaced in place", async () => {
initialize();
await flushPageViews();
pageViews.length = 0;
window.history.replaceState({}, "", "/?Size=m");
await flushPageViews();
expect(pageViews).toHaveLength(0);
});
Expected Behavior
No page view, since the buyer is still on the same page. #3917 describes one shopify:page:view for the initial page and one for each SPA navigation, and #4376 notes that variant changes belong to shopify:product:select.
Actual Behavior
A shopify:page:view for ?Size=m on the next animation frame, in both of the observer's paths:
- With the Navigation API, the observer listens to
currententrychange, whichhistory.replaceStatefires too (navigation.tsL17–L22). - Without it, the observer patches
history.replaceState(L24–L25).
Either way, page-view.ts counts any change of the path or the query (L48–L60). The existing tests cover a push, a currententrychange, and changes to the state or the hash only. None covers a query replaced in place.
So a product page that writes its selected variant into a bare URL after initializeShopifyScripts has run sends two page views for one visit, and one more for each selection after that. Tools that read Standard Events, such as PerfKit (#4376), see each of them as a new page.
Hydrogen's skills count a selection the same way in their React Router and Next.js recipes. There, PAGE_VIEWED is keyed by the path and the query, and the variant form writes the selection with a router replace. But the analytics skill's framework-neutral rule publishes PAGE_VIEWED "on each page transition".
This may be intended: the initializeShopifyScripts docs say it "sends a page view event on load and after each navigation that changes the path or query", and the Navigation API reports history.replaceState as a replace navigation. Possible directions, depending on the intended semantics:
- Skip a replacement that keeps the path, which is how storefronts write UI state into the URL, and key the recipes'
PAGE_VIEWEDthe same way. Keep counting pushes, traversals and replacements to another path, such as a redirect. - Let the storefront decide: an option to
initializeShopifyScriptsthat turns off the automatic event, and a function that dispatches it from the same route boundary that publishesPAGE_VIEWED. - If every change of the path or the query should count, say so in the docs and in the analytics skill's framework-neutral rule.
- Dominant language
- TypeScript
- Stars
- 2.2k
- Forks
- 466
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 59
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Shopify/hydrogen
-
ShopifyPrivacyBanner.showBanner()/showPreferences() types declare zero args, but headless stores require storefrontAccessToken (and domains) at runtimePossibly taken @minwookshin claimed this 53 days ago. Openinactive
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Shopify/hydrogen#4069 · 1 comment ·
Maintainers usually reply within 3 days
-
Remix 3: running Hydrogen 2026-10's core without a bindingPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 5/5 Over a week Newbie friendliness 12/100
Maintainers usually reply within 3 days
-
`runWithCache` starts a background refresh for every stale hit, where 2025.7 started one per keyPossibly taken @debojyoti10CC claimed this 6 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Maintainers usually reply within 3 days
-
`gql check` and the TS plugin still fail on Windows when schema paths are absolutePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
Shopify/hydrogen#4371 · 2 comments ·
Maintainers usually reply within 3 days
-
`hydrogen gql check` fails on Windows: absolute schema path is parsed as a URL by gql.tadaPossibly taken @Roshan931 claimed this 12 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 30/100
Shopify/hydrogen#4359 · 1 comment ·
Maintainers usually reply within 3 days
All issues in Shopify/hydrogen
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 66/100
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
prometheus/docs#3198 ·
Maintainers usually reply within 3 days
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capturePossibly taken @jianyx1 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
volcengine/OpenViking#8354 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
Maintainers usually reply within 1 day
-
Chat: Copying a selection that includes the end of a message also copies the actions menu labelsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
suitenumerique/hub#176 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day