Integrate Trustpilot Product Reviews with Shopify Hydrogen
This guide is for Shopify Hydrogen storefronts. Building on Next.js? See the Next.js overview.
- A browser TrustBox widget for Trustpilot-managed rendering and interactions.
- An optional server-side API request for aggregate ratings used in initial HTML, product cards, or structured data.
What you will build
Prerequisites
- Trustpilot Product Reviews enabled for the business account.
- A TrustBox template configured for product reviews.
- The Trustpilot business unit ID.
- A stable Shopify SKU mapping.
- A Trustpilot API key if server-side Product Reviews API access is required.
Load the TrustBox script once
Add the bootstrap script to the document head using Hydrogen’s CSP nonce:Render a product-rating widget
Map Shopify products to Trustpilot SKUs
Trustpilot matches product reviews by SKU. A Hydrogen product can expose several candidate values:- Product-level custom metafield.
- Selected variant SKU.
- A normalized group SKU shared by variants.
- Multiple SKUs for an aggregate widget, when supported by the selected template or API.
Reinitialize after client-side navigation
Hydrogen can replace the product without reloading the TrustBox bootstrap script. The component above callsloadFromElement() when the SKU changes and gives the widget a SKU-specific React key.
Test product A → product B → product A repeatedly. Also test quick-shop dialogs that mount after the initial document load.
Optional: fetch aggregate ratings on the server
Use the Product Reviews API when the initial HTML needs a rating summary or when the same data feeds JSON-LD.Cache read-only summaries
Product-review summaries change less often than product inventory. Cache successful API responses with a stable key derived from the business unit and sorted SKUs. Do not cache upstream failures as valid zero-review results. A useful Hydrogen policy is:- Long cache for product-card summaries.
- Shorter cache when a just-submitted review must appear quickly.
- Stale-while-revalidate to avoid blocking the storefront during Trustpilot latency.
nullfallback when the API is unavailable.
Configure CSP
Allow the TrustBox bootstrap host inscript-src:
Use Trustpilot with Weaverse
A Weaverse product section can expose public presentation settings:- Business unit ID.
- TrustBox template ID.
- Locale and theme.
- Height, width, and alignment.
- Empty-review behavior.
Add structured data safely
When server-side summary data is available, it can feed the product’sAggregateRating JSON-LD. Emit it only when:
- The summary belongs to the current product’s mapped SKU.
reviewCountis greater than zero.- The rating scale matches the schema output.
- Another app or widget is not already emitting duplicate rating markup.
Test the integration
- Verify SKU mapping against products in Trustpilot Business.
- Test products with reviews, no reviews, and missing SKUs.
- Navigate repeatedly between products and open quick-shop views.
- Confirm the TrustBox uses the expected template and locale.
- Verify server summaries match the visible widget.
- Simulate API failure and confirm product pages still render.
- Check CSP and script errors on mobile and desktop.
- Validate structured data with the rendered page source.
Production checklist
- Shopify-to-Trustpilot SKU mapping is documented and reused everywhere.
- Public widget IDs are separated from the private API key.
- The TrustBox script loads once.
- Widgets reinitialize after SPA navigation.
- Server summaries are cached and fail closed to
null. - Structured data is current and not duplicated.
- CSP allows only required Trustpilot hosts.