Skip to main content

Installation Guide

Complete guide to installing and setting up the Glood Hydrogen SDK in your Shopify Hydrogen project.

Prerequisites

Before installing the Glood SDK, ensure you have:
  • Node.js 18+ - Required for Hydrogen projects
  • React 18+ - Hydrogen uses React 18 features
  • Shopify Hydrogen 2024.10.1+ - Compatible Hydrogen version
  • TypeScript 5.4+ - Recommended for full type safety
  • Glood API Key - Contact Glood team to obtain your API key

Step 1: Install the Package

Install the Glood Hydrogen SDK using your preferred package manager:

npm

yarn

pnpm

Step 2: Environment Configuration

Add your Glood API key to your environment variables:

.env file

Environment Variables

Set up environment variables for different environments:

TypeScript Environment Types

Add environment types for TypeScript projects:

Step 3: Configure Content Security Policy

Add the Glood domain to your CSP configuration to enable recommendation fetches and event transmission:

Step 4: Initialize Glood Client

Create and configure the Glood client in your root layout:

Basic Setup

Environment-Specific Setup

Step 5: Verify Installation

Check Debug Logs

Enable debug mode and check browser console:
Expected console output:

Test Event Tracking

Navigate through your store and verify events are being tracked:
  1. Visit product page - Should see product_viewed events
  2. View a collection - Should see collection_viewed events
  3. View cart - Should see cart_viewed events
  4. Navigate pages - Should see page_viewed events

Verify Network Requests

In browser DevTools Network tab, look for requests to https://storefront.glood.ai:
  • POST /api/storefront/v3/headless/init (session bootstrap on load)
  • POST /api/storefront/v3/headless/sections (recommendation sections)
  • POST /api/storefront/v3/headless/events (analytics and attribution events)
(For a version: 2 client, events go to POST /api/storefront/event instead.)

Complete Implementation Example

Here’s a complete working example:

Common Setup Issues

Issue: CSP Violations

Symptoms: Console errors about blocked requests to the Glood domain Solution: Ensure the Glood domain is added to connectSrc:

Issue: Missing API Key

Symptoms: Console error “Glood: apiKey is required” Solution: Verify environment variable is set:

Issue: Invalid Shopify Domain

Symptoms: Warning about non-standard domain format Solution: Use your actual Shopify domain:

Issue: Analytics Not Working

Symptoms: No debug logs, no events tracked Solution: Verify Analytics wrapper and loaderData:

Issue: TypeScript Errors

Symptoms: TypeScript compilation errors Solution: Install type dependencies:

Next Steps

After successful installation:
  1. Configure Apps - Customize app settings
  2. Set Up CSP - Detailed CSP configuration
  3. Review Examples - Implementation patterns
  4. Load Recommendations - Fetch and display sections

Getting Help

If you encounter issues during installation:

Package Information