Utilities
The SDK exports a small set of utilities for advanced usage: consent management, session bootstrap, the pixel queue, and shared constants.Consent Management
checkConsent()
Checks if all required consent types have been granted by the customer.requiredConsents- Array of consent types that must be grantedcanTrack- Hydrogen’s canTrack function from analyticsanalytics- Hydrogen’s analytics instance
true if all required consents are granted, false otherwise
Usage:
Session Bootstrap
runHeadlessInit()
Bootstraps a session for a Glood client. Called automatically byGloodProvider on mount, but exposed for advanced use (e.g. running init yourself in a route loader).
client- TheGloodClientcreated bycreateGlood(...).use(recommendations())
/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_idcookie so returning visitors are recognized), - creates a per-visit
visit_id(_glood_visit_id, a session cookie), - returns
visitorhistory (browsed / cart / purchased), shopconfig, and the storefronttoken.
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).DEFAULT_PIXEL_CONFIG
Default pixel configuration settings.CONSENT_TYPES
Constants for all consent types.DEFAULT_PIXEL_CONSENT
Default consent requirements for the recommendations app.API_VERSIONS / DEFAULT_API_VERSION
Supported headless API versions and the default used whenversion is omitted from createGlood.
PAGE_TYPES
Page types accepted by the sections API (getSections / useRecommendations).
Pixel Queue
getPixelQueue()
Gets the global pixel queue instance for sending events.debug- Enable debug logging for pixel transmission
resetPixelQueue()
Resets the pixel queue (mainly for testing).Advanced Usage Examples
Consent Validation
Report exactly which required consents are missing, built on the exportedcheckConsent:
See Also
- Event System - How utilities are used in event processing
- Types Reference - TypeScript types for utilities
- App Modules - How apps use these utilities
- Components - React components using utilities