Recommendations API
Reference for fetching recommendation sections and sending attribution events. For a guided walkthrough, see Loading Recommendations.useRecommendations()
React hook that fetches recommendation sections for the current page. Must be used within a<GloodProvider> whose client has the recommendations app registered.
Signature
Parameters
params is a GetSectionsParams — pageType is required; pageUrl, locale, and clientId default to browser values in the browser. options accepts a single skip?: boolean (default false) to hold fetching until required params are ready.
Returns — UseRecommendationsResult
Basic Usage
With All Options
Standalone Functions
Isomorphic functions for the v2/v3 headless suite. Use them in Hydrogen route loaders (SSR) or anywhere you need the API without a React component. Every function takesoptions: HeadlessRequestOptions as its first argument.
Endpoints
Each function POSTs to a path under the client’s main endpoint (defaulthttps://storefront.glood.ai), versioned by options.version (default 3):
v3-only functions throw if
options.version is explicitly 2 (they will not silently upgrade). v3 requests send Authorization: Bearer <apiKey> + x-shop; v2 authenticates by the x-shop header alone (no bearer token).HeadlessRequestOptions
The first argument to every standalone function —apiKey (required for v3) and myShopifyDomain are required; endpoint, version (default 3), and debug are optional. See the full field table in Signatures → HeadlessRequestOptions.
fetchRecommendationSections()
Fetch recommendation sections with full product data (v3). Works server-side and in the browser; theuseRecommendations hook uses this internally.
GetSectionsParams as the hook, except pageUrl and locale are required outside the browser (there are no defaults on the server).
fetchHeadlessInit()
Bootstrap a headless session (v3 only): server-issuedvisit_id/user_id, visitor history, shop config and storefront token. In the browser, clientId and pageUrl default from the cookie/window. GloodProvider calls this automatically on mount — use it directly only for custom bootstrapping.
InitParams: userId?, clientId?, customerId?, pageType?, pageUrl? — all optional.
sendHeadlessEvent()
Send a single interaction event to the events ingestion endpoint (v3 only). In the browser,channel ('hydrogen'), sessionId and clientId are filled in when omitted; the server requires session_id and one of client_id/user_id.
HeadlessEventParams centers on the event object ({ id, name, type: 'standard' | 'custom', timestamp, data? | customData? }) plus optional channel, sessionId, clientId, userId, customerId, experience, pageType, pageUrl. Any extra fields (cart, customer, customer_privacy, …) pass through in the API’s snake_case wire format. Returns { ok: boolean, ... }.
fetchRecommendations()
Version-aware dispatch: routes to v2 or v3 byoptions.version (default 3). Prefer fetchV2Recommendations / fetchV3Recommendations when you want the concrete return type without narrowing.
fetchV3Recommendations()
Multi-query, anchor-based recommendations (v3). Each query inparams.queries is a RecommendationQuery ({ id, recommendationType, productIds, view, maxRecommendations?, creationType? }, up to 10 anchor product ids per query). Results are keyed by each query’s id.
RecommendationsParams: queries: RecommendationQuery[], plus optional clientId, userId, customerId.
fetchV2Recommendations()
Multi-query similar-products recommendations (v2 — shop-header auth only, no bearer token).V2RecommendationsParams: { queries: RecommendationQuery[] }. Response data is keyed by query id: { serve_id, products }.
fetchAutomaticRecommendations()
Single-anchor, cursor-paginated similar-products recommendations (v3 only).AutomaticRecommendationsParams: productIds: number[], view: RecommendationView, optional recommendationType (only 'similar_products'), maxRecommendations, filter, pagination: { cursor?, limit? }. Returns { status, serve_id, pagination: { cursor, hasMore? }, products }.
fetchTopRecommendations()
Anchorless, strategy-ranked, faceted catalog recommendations (v3 only).TopRecommendationsParams: strategy: 'BESTSELLERS' | 'NEW_ARRIVALS' (uppercase), view: RecommendationView, optional strategyOptions: { salesTimePeriod?: 7 | 15 | 30, bestsellerMetric? }, query (full-text catalog search), filter, facets: TopFacet[] ('vendor' | 'product_type' | 'tag' | 'price'), pagination. Returns { status, serve_id, strategy, pagination, products, facets? }.
runHeadlessInit()
Session-bootstrap helper used internally byGloodProvider: runs fetchHeadlessInit from a GloodClient, persisting/replaying the visitor id cookies. No-op (resolves null) for v2 clients.
headlessRequest()
Low-level POST primitive. Builds${endpoint}/api/storefront/v{version}/headless/{resource}, applies the per-version auth headers, and throws GloodApiError on a non-2xx response. The higher-level functions above are built on it.
Errors — GloodApiError
Thrown by every standalone function on any non-2xx response:RecommendationsApp
The app instance registered viaclient.use(recommendations()). Retrieve it from the client for advanced usage:
Methods
AlongsidegetSections, the app exposes getInit, getRecommendations,
getAutomaticRecommendations, getTopRecommendations, sendEvent, and the
trackRender / trackView / trackClick / trackAddToCart attribution
helpers. See the full method list with signatures in
App Modules → RecommendationsApp Methods.
Attribution events respect the app’s pixel configuration: if
pixel.enabled is false, they are not sent.SectionTrack Object
Links an attribution event to the exact section render it came from. PasssectionServeId (the section_serve_id from the sections response) to tie the event to a specific render. See the full field table in Signatures → SectionTrack.
Response Shape — SectionsResponse
RecommendationSection and SectionProduct definitions.
Example Response
See Also
- Loading Recommendations Guide - Walkthrough with rendering patterns
- Recommendations Example - Complete working page
- TypeScript Types - All type definitions
- Event System - How attribution events are transmitted