If your site is a Next.js project on Vercel, you can keep your agent's ID in an environment variable instead of in your code.
1. Allow your website
Open your agent, go to Guardrails and add your site under Allowed domains, for example https://your-project.vercel.app and your own domain. Then enable the widget on the Install tab.
2. Add the agent ID
- Copy the Agent ID from Agent settings.
- In your Vercel project, open Settings > Environment Variables.
- Add
NEXT_PUBLIC_ASKMAVIS_AGENT_IDwith the Agent ID as its value.
3. Load the messenger
Add this to app/layout.tsx, inside <body>. For src, use the address of messenger.js shown in the snippet on your agent's Install tab.
import Script from 'next/script';
const agentId = process.env.NEXT_PUBLIC_ASKMAVIS_AGENT_ID;
// In app/layout.tsx, inside <body>:
{agentId ? (
<Script
src="https://mavis.help/messenger.js"
data-messenger-config-id={agentId}
data-consent="granted"
referrerPolicy="strict-origin-when-cross-origin"
strategy="afterInteractive"
/>
) : null}
Then redeploy your project.