Add monorail analytics proxy as virtual resource route #3243
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.
Fixes: https://github.com/Shopify/hydrogen-internal/issues/254
Summary
Adds
/.well-known/shopify/monorail/unstable/produce_batchas a virtual resource route that proxies Shopify analytics requests to the configured Shopify store domain, eliminating runtime errors in Multipass/Hybrid setups where users navigate between Hydrogen and Shopify theme subdomains.Why
Problem: In Multipass/Hybrid setups, Shopify theme analytics scripts persist after subdomain navigation and POST to the Hydrogen domain, causing runtime errors:
Affected setups: Any Hydrogen + Multipass configuration with subdomain redirects to Shopify themes (e.g., xyz.com)
Impact:
What
Implementation
Virtual Resource Route:
Implementation Details
Resource Route (no default export):
response.bodystream to preserve Shopify's exact responseRegistration:
Key Features
SHOPIFY_STORE_DOMAINenv varresponse.bodynotawait response.text()robots.txt SEO Fix
Removed:
Disallow: /.well-known/shopify/monorailRationale:
x-robots-tag: noindexheaderx-robots-tag: noindexheader prevent indexingReference: Google - Block Search Indexing with noindex
🎩 Top Hat
Prerequisites
SHOPIFY_STORE_DOMAINenvironment variable (optional)Testing Steps
Test 1: Verify Route Exists and Returns Raw Response
Test 2: Verify Proxy Functionality with Valid Payload
Test 3: Verify robots.txt Fix
Test 4: Run Unit Tests
Edge Cases to Test
SHOPIFY_STORE_DOMAIN(returns 204)SHOPIFY_STORE_DOMAINset (proxies correctly)Validation Checklist
npm test(445/445)npm run typecheck