Content Security Policy Setup
To enable Glood pixel tracking, you need to configure your Content Security Policy (CSP) to whitelist Glood’s domains. This allows the SDK to send analytics events to Glood endpoints.Required CSP Configuration
Add the following Glood domains to yourconnectSrc
directive in your CSP configuration:
Glood Domains Explained
Required Pixel Endpoints
Domain | Purpose | Used By |
---|---|---|
https://events.glood.ai | Recommendations pixel tracking | Recommendations app |
https://s-pixel.glood.ai | Search analytics tracking | Search app |
https://w-pixel.glood.ai | Wishlist analytics tracking | Wishlist app |
Why These Domains Are Needed
- Event Transmission: The SDK sends analytics events to these endpoints via
fetch()
API calls - Privacy Compliance: Events are only sent when customer consent is granted
- Performance Tracking: Enables monitoring of user interactions and e-commerce metrics
- Personalization: Allows Glood to provide personalized recommendations and search results
Implementation in Hydrogen
1. Root Layout Configuration
Add the CSP configuration to your root layout file:2. Environment-Specific Configuration
Configure different endpoints for different environments:3. Custom Domain Configuration
If you’re using custom Glood endpoints:CSP Directives Explained
connectSrc
TheconnectSrc
directive controls which URLs can be loaded using script interfaces:
- fetch() - Used by the SDK to send pixel events
- XMLHttpRequest - Alternative HTTP request method
- WebSocket - Real-time connections (not used by Glood)
- EventSource - Server-sent events (not used by Glood)
Why Not Other Directives?
Directive | Not Required | Reason |
---|---|---|
scriptSrc | ❌ | Glood doesn’t load external scripts |
imgSrc | ❌ | Glood doesn’t load tracking pixels as images |
frameSrc | ❌ | Glood doesn’t embed iframes |
mediaSrc | ❌ | Glood doesn’t load media files |
Troubleshooting CSP Issues
1. Check Console Errors
CSP violations appear in the browser console:2. Verify Domain Configuration
Ensure all Glood domains are included:3. Test with Debug Mode
Enable debug mode to see pixel transmission attempts:4. Validate CSP Headers
Check that CSP headers are being sent:Advanced CSP Configuration
1. Strict CSP with Nonces
Use nonces for enhanced security:2. Report-Only Mode
Test CSP changes without blocking requests:3. Domain Wildcards
Use wildcards for subdomain flexibility:Security Considerations
1. Principle of Least Privilege
Only include domains that are actually needed:2. Environment Separation
Use different domains for different environments:3. Regular Review
- Review CSP regularly to ensure it’s still appropriate
- Remove unused domains when disabling Glood apps
- Monitor CSP violations in production
- Test changes in staging environments first
Integration Checklist
- Add Glood domains to
connectSrc
directive - Include all required pixel endpoints:
-
https://events.glood.ai
(recommendations) -
https://s-pixel.glood.ai
(search) -
https://w-pixel.glood.ai
(wishlist)
-
- Configure environment-specific domains if needed
- Test CSP with debug mode enabled
- Verify no CSP violations in browser console
- Monitor pixel transmission success in debug logs
- Deploy CSP headers correctly
- Test in production environment
Common Issues
Issue: CSP Blocking Pixel Requests
Symptoms: Network errors, no pixel events sent Solution: Add missing Glood domains toconnectSrc
Issue: CSP Header Not Applied
Symptoms: CSP violations not shown, headers missing Solution: Ensure CSP headers are returned from loader and applied in headers functionIssue: Wrong Environment Domains
Symptoms: 404 errors on pixel endpoints Solution: Verify correct domains for current environmentIssue: Wildcard Domain Issues
Symptoms: Inconsistent blocking behavior Solution: Use explicit domain lists instead of wildcardsExample Implementation
Complete working example:- ✅ All Glood pixel endpoints are whitelisted
- ✅ CSP headers are properly applied
- ✅ Pixel tracking works correctly
- ✅ Security is maintained with explicit domain lists
See Also
- Event System - Understanding pixel transmission
- App Modules - App-specific pixel endpoints
- Installation Guide - Complete setup instructions
- Hydrogen CSP Documentation - Official Shopify CSP guide