Skip to main content

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

Security Requirement: When using any user-* attributes (user-id, user-name, user-avatar), you must also provide user-hash. Both user-id and user-hash must be provided together, or neither should be provided. The user-hash must be generated on your backend using HMAC-SHA256 with your assistant’s secret key. Never expose the secret key to the client.

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

Solutions:
  • Check gatsby-browser.js for duplicate script logic
  • Use conditional to prevent duplicate loads
  • Clear .cache and public folders: gatsby clean
Solutions:
  • Prefix public variables with GATSBY_
  • Restart development server
  • Check .env files exist
  • Verify gatsby-config.js is reading variables
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 window before accessing it
  • Store secret keys in .env files (never commit)
  • Use GATSBY_ prefix only for public variables
  • Test both development and production builds