Installation snippets
Copy-paste snippets for adding the Zoie website widget and form widget to plain HTML, Google Tag Manager, React, Next.js and other single-page apps, loading after cookie consent, passing ad consent and testing locally.
Each snippet below uses placeholder IDs. Replace them with the widget key from the widget’s Publish dialog and the form ID from the form’s Publish Form panel. Use the host shown in your own snippet, for example https://us.zoie.ai. What each attribute and option does is in Configuration.
Plain HTML
Website widget
Paste once per page, ideally in a shared footer template:
<!-- Zoie Widget -->
<script
src="https://us.zoie.ai/widget-bundle.js"
data-widget-id="3f6b2a9e-1c4d-4e8f-9a7b-5d2c1e0f4a6b"
defer>
</script>
Form widget
Put the container where the form belongs, then the script. The phone-field stylesheet is only needed if the form has a phone field.
<link rel="stylesheet" href="https://unpkg.com/react-phone-input-2/lib/style.css" />
<div id="static-form-widget-container"></div>
<script
src="https://us.zoie.ai/form-widget-bundle.js"
form_id="6f1c2d3e-8a4b-4c1d-9e2f-0a1b2c3d4e5f"
defer>
</script>
See Forms for why the React scripts in the copied snippet can be left out.
Google Tag Manager
Create a Custom HTML tag and fire it on All Pages. The tags below create the script element in code and use plain ES5, so they run in any browser.
Website widget
<script>
(function () {
if (document.getElementById('zoie-widget-bundle')) return;
var s = document.createElement('script');
s.id = 'zoie-widget-bundle';
s.src = 'https://us.zoie.ai/widget-bundle.js';
s.defer = true;
s.setAttribute('data-widget-id', '3f6b2a9e-1c4d-4e8f-9a7b-5d2c1e0f4a6b');
document.body.appendChild(s);
})();
</script>
Form widget
A tag-manager script usually runs after DOMContentLoaded, so start the form yourself when the bundle has loaded. The container still has to be in your page’s HTML.
<script>
(function () {
var FORM_ID = '6f1c2d3e-8a4b-4c1d-9e2f-0a1b2c3d4e5f';
if (!document.getElementById('static-form-widget-container')) return;
var s = document.createElement('script');
s.src = 'https://us.zoie.ai/form-widget-bundle.js';
s.onload = function () {
window.initFormWidget({ form_id: FORM_ID });
};
document.body.appendChild(s);
})();
</script>
Remove the early return if you’d rather have the form appended to the end of the page when the container is missing.
React and Next.js
The widget lives on document.body and survives client-side navigation, so load it once from the root of your app. See Single-page apps.
Next.js
In the App Router, add it to app/layout.tsx. next/script passes data- attributes through to the tag, and its id stops it being added twice.
import Script from 'next/script';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script
id="zoie-widget"
src="https://us.zoie.ai/widget-bundle.js"
data-widget-id="3f6b2a9e-1c4d-4e8f-9a7b-5d2c1e0f4a6b"
strategy="afterInteractive"
/>
</body>
</html>
);
}
lazyOnload also works if you’d rather load the widget once the browser is idle.
React
For a React app without a framework, inject the tag from an effect in a component that mounts once, such as your app shell:
import { useEffect } from 'react';
const WIDGET_KEY = '3f6b2a9e-1c4d-4e8f-9a7b-5d2c1e0f4a6b';
export function ZoieWidget() {
useEffect(() => {
if (document.getElementById('zoie-widget-bundle')) return;
const s = document.createElement('script');
s.id = 'zoie-widget-bundle';
s.src = 'https://us.zoie.ai/widget-bundle.js';
s.defer = true;
s.setAttribute('data-widget-id', WIDGET_KEY);
document.body.appendChild(s);
}, []);
return null;
}
Don’t remove the tag in the effect’s clean-up. Removing the <script> element doesn’t unload the widget, and adding it again would set it up twice.
Form widget in a single-page app
Render the container in your component, load the bundle once, and call initFormWidget when the container is on the page. The bundle stays loaded between routes, so later mounts only call the function.
import { useEffect, useRef } from 'react';
const FORM_ID = '6f1c2d3e-8a4b-4c1d-9e2f-0a1b2c3d4e5f';
const BUNDLE = 'https://us.zoie.ai/form-widget-bundle.js';
export function ZoieForm() {
const started = useRef(false);
useEffect(() => {
if (started.current) return; // React Strict Mode runs effects twice in development
started.current = true;
const start = () => window.initFormWidget({ form_id: FORM_ID });
if (window.initFormWidget) {
start();
return;
}
const s = document.createElement('script');
s.src = BUNDLE;
s.onload = start;
document.body.appendChild(s);
}, []);
return <div id="static-form-widget-container" />;
}
Show one ZoieForm per page, because the container ID is fixed.
Load after cookie consent
If your consent banner must approve the widget before it loads, leave the snippet out of the page and add it from your banner’s “accepted” callback. The widget starts as soon as the tag is added, however late that is.
function loadZoieWidget() {
if (document.getElementById('zoie-widget-bundle')) return;
const s = document.createElement('script');
s.id = 'zoie-widget-bundle';
s.src = 'https://us.zoie.ai/widget-bundle.js';
s.setAttribute('data-widget-id', '3f6b2a9e-1c4d-4e8f-9a7b-5d2c1e0f4a6b');
document.body.appendChild(s);
}
// Call loadZoieWidget() from your consent manager's accept handler.
To keep the widget but stop its product analytics, add data-analytics="off" to the tag instead. See Analytics.
Pass ad consent
When a lead is created, the widget and the form send the visitor’s consent for ad measurement, but only if your page states it. If your site already uses Google Consent Mode, you don’t need to do anything: the embeds read ad_user_data from your dataLayer.
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'default', { ad_user_data: 'denied', ad_personalization: 'denied' });
// Later, when the visitor accepts:
// gtag('consent', 'update', { ad_user_data: 'granted', ad_personalization: 'granted' });
</script>
Without Consent Mode, set the value directly before the visitor starts a chat or submits a form:
window.ZoieWidgetConsent = 'granted'; // or 'denied'
The order Zoie checks these in is under Ad consent.
Test locally
- Website widget.
localhostand127.0.0.1always pass the Allowed Domains check, so the production snippet works on your machine. - Form widget. The form’s API accepts browsers on a few common local development origins, for example
http://localhost:3000andhttp://localhost:5173. On other ports the form fails with a CORS error. See Where the form can run. - Debug logging. Set
window.__ZOIE_WIDGET_DEBUG__ = truebefore the widget snippet to log each start-up step.
Real leads and conversations are created while you test. Delete test leads afterwards, or test on a separate Zoie business.