Overview
Add your Invent AI assistant to any Gatsby site. Perfect for static websites built with React and GraphQL.Installation
1
Install React Helmet
2
Configure gatsby-config.js
Add the plugin to your
gatsby-config.js:3
Create Assistant Component
4
Add to Layout
5
Add Environment Variable
Create
.env.development and .env.production:User Authentication
Using Gatsby Functions (Serverless)
Gatsby Functions allow you to generate the hash server-side:Fetching User Data
GraphQL Integration
Pass content data to provide context:TypeScript Support
Add type declarations:Tips for Gatsby
Serverless Functions
Use Gatsby Functions for hash generation
GraphQL Context
Pass content data for better context
Static & Dynamic
Works with SSG and DSG builds
Plugin Ecosystem
Integrates with Gatsby plugins
Troubleshooting
Script loading multiple times
Script loading multiple times
Solutions:
- Check gatsby-browser.js for duplicate script logic
- Use conditional to prevent duplicate loads
- Clear .cache and public folders:
gatsby clean
Environment variables not working
Environment variables not working
Solutions:
- Prefix public variables with
GATSBY_ - Restart development server
- Check .env files exist
- Verify gatsby-config.js is reading variables
Build errors
Build errors
Solutions:
- Ensure typeof window checks for SSR
- Use dynamic imports if needed
- Check all dependencies are installed
- Clear cache:
gatsby clean
Best Practices
- Use Gatsby Functions for server-side operations
- Always check for
windowbefore accessing it - Store secret keys in
.envfiles (never commit) - Use
GATSBY_prefix only for public variables - Test both development and production builds