Integrations
Gatsby Integration
Integrate Ask0's AI search and chat into your Gatsby site. Add intelligent documentation assistance to Gatsby-based React apps.
Add Ask0 to your Gatsby static site or blog.
Installation
gatsby-browser.js
Add the script in your browser APIs file:
export const onClientEntry = () => {
const script = document.createElement('script');
script.src = 'https://assets.ask0.ai/scripts/ask.js';
script.dataset.projectId = process.env.GATSBY_ASK0_PROJECT_ID;
script.dataset.position = 'bottom-right';
script.dataset.theme = 'auto';
script.async = true;
document.body.appendChild(script);
};gatsby-ssr.js
For server-side rendering support:
import React from 'react';
export const onRenderBody = ({ setPostBodyComponents }) => {
setPostBodyComponents([
<script
key="ask0"
src="https://assets.ask0.ai/scripts/ask.js"
data-project-id={process.env.GATSBY_ASK0_PROJECT_ID}
async
/>,
]);
};React Component
Create a reusable component:
import { useEffect } from 'react';
export default function Ask0() {
useEffect(() => {
// Ask0 script is already loaded via gatsby-browser.js
if (window.ask0) {
console.log('Ask0 ready');
}
}, []);
const openWidget = () => {
window.ask0?.open();
};
return (
<button onClick={openWidget} className="ask-button">
Ask AI
</button>
);
}Layout Integration
Add to your layout component:
import React from 'react';
import Ask0 from './Ask0';
interface LayoutProps {
children: React.ReactNode;
}
export default function Layout({ children }: LayoutProps) {
return (
<>
<header>...</header>
<main>{children}</main>
<footer>...</footer>
<Ask0 />
</>
);
}gatsby-config.js
Configure using gatsby-plugin-env-variables:
module.exports = {
siteMetadata: {
title: 'My Site',
},
plugins: [
{
resolve: 'gatsby-plugin-env-variables',
options: {
allowList: ['GATSBY_ASK0_PROJECT_ID'],
},
},
],
};Custom Plugin
Create a custom Gatsby plugin:
import React from 'react';
export const onRenderBody = ({ setPostBodyComponents }, pluginOptions) => {
if (!pluginOptions.projectId) {
console.warn('Ask0 project ID is required');
return;
}
setPostBodyComponents([
<script
key="ask0"
src="https://assets.ask0.ai/scripts/ask.js"
data-project-id={pluginOptions.projectId}
data-position={pluginOptions.position || 'bottom-right'}
data-theme={pluginOptions.theme || 'auto'}
async
/>,
]);
};export const onClientEntry = (_, pluginOptions) => {
console.log('Ask0 widget initialized');
};Then use it:
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-ask0',
options: {
projectId: process.env.GATSBY_ASK0_PROJECT_ID,
position: 'bottom-right',
theme: 'auto',
},
},
],
};Environment Variables
GATSBY_ASK0_PROJECT_ID=your_dev_project_idGATSBY_ASK0_PROJECT_ID=your_prod_project_idGatsby Tips:
- Use
gatsby-browser.jsfor client-side loading - Use
gatsby-ssr.jsfor SSR support - Prefix env vars with
GATSBY_ - Compatible with Gatsby 4 and 5
- Works with all Gatsby themes and starters