Skip to main content

Utilities

The SDK exports a small set of utilities for advanced usage: consent management, session bootstrap, the pixel queue, and shared constants.

checkConsent()

Checks if all required consent types have been granted by the customer.
Parameters:
  • requiredConsents - Array of consent types that must be granted
  • canTrack - Hydrogen’s canTrack function from analytics
  • analytics - Hydrogen’s analytics instance
Returns: true if all required consents are granted, false otherwise Usage:
Implementation Details:

Session Bootstrap

runHeadlessInit()

Bootstraps a session for a Glood client. Called automatically by GloodProvider on mount, but exposed for advanced use (e.g. running init yourself in a route loader).
Parameters:
  • client - The GloodClient created by createGlood(...).use(recommendations())
Returns: The /v3/headless/init response (InitResponse), or null for v2 clients (init is a v3-only endpoint, so it is a no-op there). For a v3 client it calls POST /api/storefront/v3/headless/init, which:
  • replays the persisted visitor id and returns/echoes user_id (persisted to the _glood_user_id cookie so returning visitors are recognized),
  • creates a per-visit visit_id (_glood_visit_id, a session cookie),
  • returns visitor history (browsed / cart / purchased), shop config, and the storefront token.
Usage:
It also saves the response on the client, so after it runs you can read it back synchronously with client.getInitData() (and reactively with useGloodInit()) — no need to hold the return value yourself.
Inside components, prefer the useGloodInit() hook, which returns the same InitResponse (or null until it resolves / for v2 clients) without re-running init. GloodProvider already calls runHeadlessInit for you on mount — call it directly only for manual/SSR bootstrap.

Constants

DEFAULT_ENDPOINTS

Default API and pixel endpoints for the recommendations app.
recommendations.pixel is legacy and no longer used to route events. Events are sent off the main endpoint by the client’s version (v3 → /api/storefront/v3/headless/events).
Usage:

DEFAULT_PIXEL_CONFIG

Default pixel configuration settings.
Constants for all consent types.
Usage:
Default consent requirements for the recommendations app.
Usage:

API_VERSIONS / DEFAULT_API_VERSION

Supported headless API versions and the default used when version is omitted from createGlood.
Usage:

PAGE_TYPES

Page types accepted by the sections API (getSections / useRecommendations).

Pixel Queue

getPixelQueue()

Gets the global pixel queue instance for sending events.
Parameters:
  • debug - Enable debug logging for pixel transmission
Returns: PixelQueue instance Usage:

resetPixelQueue()

Resets the pixel queue (mainly for testing).
Usage:

Advanced Usage Examples

Report exactly which required consents are missing, built on the exported checkConsent:

See Also