Integrate Yotpo Reviews with Shopify Hydrogen
This guide is for Shopify Hydrogen storefronts. Building on Next.js? See the Next.js overview.
What you will build
Prerequisites
- Yotpo Reviews installed and connected to the Shopify store.
- The Yotpo app key.
- A configured Yotpo widget instance ID for each widget type.
- Products synchronized to Yotpo using the same numeric Shopify product IDs.
Extract the Shopify numeric product ID
Hydrogen returns GraphQL IDs such asgid://shopify/Product/1234567890. Yotpo’s Shopify catalog normally identifies the product by the trailing numeric ID.
Load the Yotpo widget script once
Render a star-rating widget
instanceId. Widget-specific attributes should come from the Yotpo widget configuration rather than another storefront’s markup.
Reinitialize after Hydrogen navigation
Yotpo scans the DOM when its script first loads. Hydrogen can replace one product route with another without reloading the document, so the new widget element may not be discovered automatically. The example above handles this in two ways:- The product ID is part of the React
key, forcing a fresh widget container. initWidgets()runs whenever the product ID changes.
Configure a strict CSP
Allow Yotpo’s widget loader inscript-src:
Make the widget editable in Weaverse
The app key and instance ID are public widget configuration, so they can be Studio settings when merchants need to switch widgets without a deployment.Optional: use the Reviews API
Choose server-side API access when you need custom review cards, server-rendered aggregate ratings, custom pagination, or review data outside Yotpo’s widgets. A safe API architecture should:- Keep private credentials in the Hydrogen server environment.
- Accept only a bounded product ID, page, and page size.
- Cache read-only review lists and aggregate ratings.
- Map upstream data into a small storefront response.
- Treat review submission as a separate, rate-limited write route.
- Return generic errors without exposing upstream payloads or tokens.
Add structured data carefully
Only emitAggregateRating or Review JSON-LD when the values were loaded for the current product and are visible or meaningfully represented on the page. Avoid combining stale cached counts with a different product after client-side navigation.
When Yotpo owns rich-snippet output, verify that your custom SEO layer does not emit duplicate aggregate-rating markup.
Test the integration
- Confirm Yotpo contains the current Shopify product ID.
- Verify star rating and review widgets on products with and without reviews.
- Navigate product A → product B → product A several times.
- Change variants without changing the product and confirm the widget stays stable.
- Test direct page loads and client-side navigation.
- Check CSP and script errors in the browser console.
- Verify mobile layout and review-submission dialogs.
- Confirm product IDs, app keys, and instance IDs differ correctly between environments.
Troubleshooting
The widget is empty
- Confirm the app key and widget instance ID belong to the same Yotpo account.
- Confirm the numeric Shopify product ID exists in Yotpo.
- Inspect CSP and network errors.
- Ensure the widget is enabled in Yotpo.
It works on hard refresh but not navigation
Callwindow.yotpoWidgetsContainer?.initWidgets?.() after the product ID changes and remount the widget container with a product-specific key.
Reviews appear under the wrong product
Verify the Shopify GID-to-numeric-ID conversion and Yotpo catalog mapping. Do not use a variant ID where Yotpo expects a product ID.Production checklist
- The Yotpo catalog uses the same Shopify product IDs as Hydrogen.
- Public widget IDs are separated from private API credentials.
- The loader is deduplicated.
- Widgets reinitialize after SPA navigation.
- CSP is restricted to required Yotpo hosts.
- Products with zero reviews have intentional fallback UI.
- Structured data is current and not duplicated.