Utilities
The SDK provides various utility functions for consent management, data transformation, browser context handling, and other common operations.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:
Constants
DEFAULT_ENDPOINTS
Default API and pixel endpoints for all apps.DEFAULT_PIXEL_CONFIG
Default pixel configuration settings.ALL_EVENTS
Array of all supported event types.CONSENT_TYPES
Constants for all consent types.DEFAULT_PIXEL_CONSENT
Default consent requirements for each app.Data Transformers
transformCartData()
Transforms Shopify cart data to Glood pixel format.shopifyCart
- Shopify cart object from analytics events
null
if cart is empty
Usage:
transformShopData()
Transforms shop data to Glood pixel format.shopData
- Shop data from analytics eventsmyShopifyDomain
- Your Shopify domain
createCustomerPrivacy()
Creates customer privacy object from analytics data.analytics
- Hydrogen analytics instance
getPageTitle()
Gets the current page title with fallback.fallback
- Fallback title if document.title is not available
getCurrentUrl()
Gets the current URL from window or event data.eventData
- Optional event data that might contain URL
ID Generators
generateEventId()
Generates a unique event ID.CookieStorage
Utility class for managing client IDs and session data.getOrGenerateClientId()
Gets or generates a persistent client ID.getOrGenerateSessionId()
Gets or generates a session ID.getOrGenerateRkUid()
Gets or generates a user ID for analytics.analytics
- Hydrogen analytics instance
extractCartIdentifier()
Extracts cart identifier from Shopify cart data.cart
- Shopify cart object
null
if not available
Usage:
Browser Context
browserContext
Utility object for getting browser environment information.getContext()
Gets comprehensive browser context information.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
Custom Consent Checker
Custom Event Transformer
Environment-Specific Constants
Error Handling Utilities
Safe Transformation
Consent Validation
Performance Utilities
Debounced Event Sending
Testing Utilities
Mock Analytics
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