Glood Hydrogen SDK
The Glood Hydrogen SDK is a TypeScript-first library designed specifically for integrating Glood’s product recommendations into Shopify Hydrogen storefronts. It provides React components, hooks, and utilities optimized for the Hydrogen framework. The SDK is recommendations-focused: it loads recommendation sections, powers the headless recommendation endpoints, and streams analytics and attribution events back to Glood.Key Features
🚀 Hydrogen-Optimized - Built specifically for Shopify Hydrogen with SSR support 🛍️ Recommendations - Load recommendation sections with full product data via a React hook or SSR loader 📡 Zero-Config Analytics - Standard events (page views, add to cart, …) sent out of the box 🎯 TypeScript First - Complete type safety with excellent developer experience ⚡ Performance Focused - Tree-shakeable exports and optimized pixel tracking 🔧 Zero Configuration - Works out of the box with sensible defaults 🛡️ Privacy Compliant - GDPR/CCPA compliant with automatic consent handling 📦 Lightweight - Minimal bundle impact with selective importsQuick Start
1. Installation
2. Basic Setup
Add your Glood API key to environment variables:3. That’s It! 🎉
No additional setup required. The SDK automatically:- ✅ Bootstraps a session on load (v3 clients call
POST /api/storefront/v3/headless/init) - ✅ Tracks user interactions via Shopify Analytics
- ✅ Sends analytics and attribution events to the versioned events API
- ✅ Respects customer privacy settings
- ✅ Provides debug logging in development
4. Load Recommendations
Display the recommendation sections configured in your Glood dashboard:Why loaderData is Required
TheloaderData prop is mandatory and enables the Glood recommendations app to:
- Access route-specific data from Hydrogen loaders for enhanced context
- Enhance analytics events with additional page-specific information
- Provide personalized recommendations based on current page data
useLoaderData() to the GloodProvider component.
Architecture Overview
React Context Integration
The SDK uses React Context to provide the Glood client throughout your application:Session Init
On mount,GloodProvider bootstraps a session for v3 clients by calling POST /api/storefront/v3/headless/init. It replays the persisted visitor id (_glood_user_id cookie), creates a per-visit id (_glood_visit_id), and returns the visitor’s history, shop config, and storefront token. For v2 clients init is a no-op. The response is exposed via the useGloodInit() hook.
Event Flow
- Shopify Analytics → Automatically tracks user interactions
- GloodProvider → Subscribes to analytics events via
useAnalytics() - Event Transformation → Converts Shopify events to the Glood event format
- Consent Checking → Verifies customer privacy permissions
- Event Transmission → Sends events to the versioned events API (v3 →
POST {endpoint}/api/storefront/v3/headless/events; v2 →POST {endpoint}/api/storefront/event)
App Module
The SDK exposes a single app module:- Recommendations (
recommendations()) - Product recommendations, personalization, sections, and event tracking
.use(recommendations()). It can be configured with a custom endpoint and pixel settings.
Configuration Options
Basic Configuration (Recommended)
- Zero configuration beyond API key and domain
- Automatic default endpoint for recommendations
- Pixel tracking enabled by default with appropriate consent requirements
- Perfect for getting started quickly
Advanced Configuration
Events route off the app’s main
endpoint and the client version (v3 → POST {endpoint}/api/storefront/v3/headless/events), not off pixel.endpoint. There is no separate events host to configure.- Custom endpoint URL for different environments
- Granular pixel tracking control
- Custom consent requirements for privacy compliance
- Environment-specific configurations
Privacy & Compliance
The SDK provides automatic privacy compliance through Shopify’s Customer Privacy API:Default Consent Requirements
- Recommendations:
['analytics', 'marketing']- Analytics and marketing consent
How Consent Works
- User visits site and sees Shopify privacy banner
- User grants specific consent types through the privacy interface
- Events are tracked by Shopify Analytics as usual
- For each event, Glood checks if user has granted all required consents for that app
- Only if all consents are granted, pixel data is sent to Glood
Default Endpoints
When using basic configuration, the recommendations endpoint is used automatically:Recommendations
- Main:
https://storefront.glood.ai- Product recommendations API and the full v3 headless suite (init, sections, events, recommendations variants)
POST {endpoint}/api/storefront/v3/headless/events and v2 events go to POST {endpoint}/api/storefront/event.
Content Security Policy Setup
To enable recommendation fetches and event transmission, add the Glood domain to your Content Security Policy:Debug Mode
Enable debug mode to see detailed logging during development:- Event subscriptions setup
- Received analytics events
- Consent checking results
- Pixel transmission status
- Error details
Next Steps
- Installation Guide - Detailed setup instructions
- Configuration - Basic and advanced configuration options
- Loading Recommendations - Fetch and display recommendation sections
- API Reference - Complete API documentation
- Examples - Implementation examples and patterns
- Content Security Policy - CSP configuration guide
Requirements
- Node.js 18+
- React 18+
- Shopify Hydrogen 2024.10.1+
- TypeScript 5.4+ (recommended)