Skip to main content

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.
To authenticate users from your application and provide personalized experiences:
  1. Generate a secret key in your assistant settings
  2. On your backend, generate an HMAC-SHA256 hash of the user ID
  3. Pass the hash along with user information to the assistant
See the Widget Authentication guide for complete authentication details.

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

Solutions:
  • Ensure script loads after component mounts
  • Check for hydration issues in SSR
  • Verify custom element support in your build
Solutions:
  • Load script only on client side
  • Use useEffect or mounted lifecycle
  • Check for window object availability