Overview
Add your Invent AI assistant to websites powered by Contentful. Perfect for headless CMS architectures using React, Next.js, Gatsby, or any other framework.Installation Methods
Since Contentful is a headless CMS, the implementation depends on your frontend framework.React / Next.js
1
Create Assistant Component
Create a new component for the Invent assistant:
2
Add to Layout
Import and use in your layout component:
Gatsby
1
Install React Helmet
2
Add to gatsby-browser.js
3
Add Component
Vue.js / Nuxt
Static HTML
For static site generators that output HTML:Passing Contentful Data
You can pass Contentful content data to provide context to your assistant:Environment Variables
Store your assistant ID in environment variables: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 or generate the hash in frontend code.- Generate a secret key in your assistant settings
- On your backend, generate an HMAC-SHA256 hash of the user ID
- Pass the hash along with user information to the assistant
Framework-Specific Tips
Next.js
Use in _app.jsx or layout.tsx for global availability
Gatsby
Add to gatsby-browser.js for all pages
Nuxt
Create as a plugin in plugins/ directory
SvelteKit
Add to root +layout.svelte
Troubleshooting
Component not rendering in React
Component not rendering in React
Solutions:
- Ensure script loads after component mounts
- Check for hydration issues in SSR
- Verify custom element support in your build
SSR/SSG issues
SSR/SSG issues
Solutions:
- Load script only on client side
- Use useEffect or mounted lifecycle
- Check for window object availability