Put an agent on your website
Put an Insurge agent on your website, identify visitors, and receive browser events.
Add an Insurge agent to your website with one script tag. A workspace admin switches the agent on for your sites and copies its install code; your developer pastes it into the site and tests it.
Get the install code
In the Insurge dashboard, open Agents, choose the agent, then open Sharing → On your site. For a Copilot, Onboarding, or Training agent the tab is called Install.
At the top, under How it appears, choose Floating button (a button in the corner opens the agent over the page) or Inside the page (an iframe you place where the agent should sit). Then work through the steps:
- Turn it on for websites. Switch on Allowed on websites. Optionally change the Button text, and under More options the Corner, Icon, Button colour (blank uses your brand colour), and Teaser, a short line beside the button. For a Copilot, Onboarding, or Training agent, choose How it appears (always on the page, or opens on a click or Command/Ctrl +
/) and Where. - Choose the sites it can appear on. Add each website origin, such as
https://www.yoursite.comorhttps://staging.yoursite.com, including the scheme and hostname. Addhttps://*.yoursite.comto allow its subdomains, orhttp://localhost:3000(with your port) while you develop locally. The list is shared by every agent in the workspace. Saving it also switches embedding on for the workspace; if your sites are already saved and embedding is off, select Switch embedding on. - Copy the install code. If the agent has no code yet, select Create install code, then Copy code.
- Check it is on your site. After your developer adds the tag, open a page that has it, then select Check again. Each site where the tag has loaded is listed. A site marked as not in your sites needs adding in step 2. Pages that send no referrer (
Referrer-Policy: no-referrer) are not listed.
Use Copy under Then send it to whoever runs the site to send your developer ready-made instructions with the exact values for this agent.
The code belongs to that agent and does not expire. Editing the agent does not require a new tag. Use the tag from On your site rather than a sharing link. Changes to the allowed sites take up to one minute to apply; appearance changes reach pages within seconds.
To stage a rollout, switch on Testers only in step 1. The agent then shows only in browsers that have opened a page of your site with ?insurge_preview=1 added to its address; ?insurge_preview=0 clears that.
Add the launcher
Paste the tag before your page's closing </body> tag, replacing your_embed_code with the code from the dashboard:
<script
src="https://demo.insurgeai.com/embed/your_embed_code.js"
async
></script>On an allowed site, visitors see a launcher in the corner set in step 1, bottom-right by default. Selecting it opens the agent over the page. If the agent's visitor form is on, visitors fill it in before the meeting starts, unless your page identifies them first. On a site that is not on the allowed list, the launcher still appears, but the overlay shows the browser's "refused to connect" message instead of the agent.
Serve the page over HTTPS. Keep the tag outside your single-page application's router so route changes do not restart a meeting.
If your page sends a Content-Security-Policy header, allow https://demo.insurgeai.com in script-src and frame-src. If it sends a Permissions-Policy header, allow the microphone for the agent: microphone=(self "https://demo.insurgeai.com"). Without it, visitors can only type.
Choose a display mode
Data attributes on the script tag override the settings from step 1 for that page.
| Attribute | Accepted values | Purpose |
|---|---|---|
data-mode | launcher (default), inline, modal | Floating launcher, an in-page container, or no launcher so you open it from your own button |
data-target | CSS selector | Container for inline mode; without a match, the tag's parent element is used |
data-position | bottom-right, bottom-left, bottom-center | Launcher corner; bottom-center is for Copilot, Onboarding, and Training agents |
data-color | Six-digit hex colour, such as #2563eb | Launcher colour; other formats are ignored |
data-label | Text | Launcher text; empty uses the dashboard setting |
data-greeting | Text | Teaser beside the launcher; an empty value hides it |
data-presence | pill, bar | Copilot, Onboarding, and Training only: a small button, or a bar always on the page |
The default launcher mode needs no attributes; the tag in Add the launcher is a complete example. This one moves it to the left with your own colour, text, and teaser:
<script
src="https://demo.insurgeai.com/embed/your_embed_code.js"
data-position="bottom-left"
data-color="#2563eb"
data-label="Take the tour"
data-greeting="See the product in two minutes"
async
></script>For an in-page agent, give the container at least 900 pixels of width:
<div id="insurge-agent"></div>
<script
src="https://demo.insurgeai.com/embed/your_embed_code.js"
data-mode="inline"
data-target="#insurge-agent"
async
></script>On phones, inline mode falls back to the launcher, and opening the agent takes over the full screen.
Modal mode shows no launcher. Open the agent from your own button:
<button id="open-agent" type="button">See the demo</button>
<script
src="https://demo.insurgeai.com/embed/your_embed_code.js"
data-mode="modal"
async
></script>
<script>
document.querySelector("#open-agent").addEventListener("click", () => {
window.InsurgeDemo?.open();
});
</script>If your Content Security Policy blocks inline scripts, put the click handler in one of your own script files instead. The retired data-flow attribute is ignored.
Use the JavaScript API
The tag adds window.InsurgeDemo to the page:
window.InsurgeDemo.open(); // open the agent
window.InsurgeDemo.close(); // hide it; the meeting keeps its state
window.InsurgeDemo.start(); // the same as open()
window.InsurgeDemo.ask("How do I export a report?"); // open it and ask for the visitorInsurgeDemo is ready once the tag has loaded. If your code may run before that, add this line before the tag; calls made earlier then run as soon as it loads. It is an inline script, so a strict Content Security Policy blocks it.
<script>window.InsurgeDemo=window.InsurgeDemo||{_q:[]};["open","close","start","identify","ask","context","event","on"].forEach(function(m){var d=window.InsurgeDemo;d[m]=d[m]||function(){d._q.push([m,arguments])}});</script>Identify a signed-in visitor
Call identify() any time before the meeting starts to supply a visitor who is already signed in to your site:
window.InsurgeDemo.identify({
email: "jane@example.com",
name: "Jane Doe",
company: "Example Labs",
role: "Operations",
fields: { "Phone Number": "+91-98765-43210" }
});When the details are valid, the agent skips its visitor form and starts the meeting with that person as the lead. Limits:
- A valid email is required.
namedefaults to the part of the email before@. - Every other field your workspace's visitor form requires must be present. Put custom fields under
fields, named exactly as on the form. - Invalid or incomplete details leave the form visible.
- A call made after the meeting has started is ignored.
- Returning visitors are matched by email within the workspace; non-empty values update their profile.
Give the agent page context
window.InsurgeDemo.context({ plan: "pro", page: "billing" }); // what your page knows
window.InsurgeDemo.context({}); // clear it
window.InsurgeDemo.event("order.saved", { total: 120 }); // something that just happenedevent() accepts:
- Name: 1 to 64 characters. It must start with a lowercase letter (
a–z), followed only by lowercase letters, digits,_, and.. Uppercase letters, hyphens, and spaces are refused, soorder.savedandstep_2.donework butOrder.saved,order-saved, and2fa.donedo not. - Data: optional, a JSON object of at most 2,048 bytes when encoded as UTF-8 JSON. Leave it out, or pass anything that is not an object, to send
{}. Data that cannot be turned into JSON is refused.
event() returns false when it refuses the name or data, and true when it sends the event. After that, Insurge rejects an event whose data is an array, and accepts at most 10 events a second for each meeting; neither changes the value event() already returned.
Listen for milestones
Subscribe to milestones, and remove the subscription when your component unmounts:
const unsubscribe = window.InsurgeDemo.on("demo_completed", (event) => {
console.log("Insurge milestone:", event.type);
});
unsubscribe();The milestones are lead_submitted, meeting_started, support_started, and demo_completed. Copilot, Onboarding, and Training agents also send guide with the status of the guide in progress. If window.dataLayer exists, the four milestones are also pushed to Google Tag Manager as insurge_demo_<type>, such as insurge_demo_meeting_started. Milestones contain no personal information; use webhooks for lead and meeting records.
Place the agent inside the page with an iframe
Choose Inside the page in On your site to get a ready iframe. If you build it yourself:
<iframe
src="https://demo.insurgeai.com/s/your_embed_code#inline=1"
title="Insurge product guide"
allow="microphone; autoplay; clipboard-write"
referrerpolicy="strict-origin"
loading="lazy"
style="width:100%;height:min(720px,85vh);border:0"
></iframe>allow="microphone": without it, the browser blocks the microphone inside the frame before any prompt appears, so the visitor can only type.- A fixed height: an iframe without one is only 150 pixels tall, which shows a narrow strip instead of the product screen.
#inline=1: the meeting waits for the visitor to select Join. Without it, a meeting starts on every page view.
The website must still be on the allowed list from step 2.
Open a meeting from a native app
For a WebView or a system browser tab, create the lead first, then open the meeting with it. Lead creation uses the agent's sharing code as X-Demo-Token; it is a different endpoint from the API, which uses an API key:
curl --fail-with-body -X POST \
'https://api.insurgeai.com/api/leads' \
-H 'Content-Type: application/json' \
-H 'X-Demo-Token: your_share_code' \
-d '{"email":"jane@example.com","name":"Jane","language":"hi-IN"}'Include any other fields your visitor form requires, under fields; a missing required field returns 422, as does an unsupported language. A successful response contains lead_id, is_returning, and the resolved language when you sent one. Open the meeting with that lead ID in the link's fragment:
https://demo.insurgeai.com/s/your_share_code#lid=your_lead_id&lang=hi-INUse the sharing link the dashboard shows for the agent; if your workspace has its own link address, its host differs from the example.
The lead ID stays in the fragment, so it is not sent to the server in the URL. A missing or other-workspace lead ID is ignored and the visitor form appears. A supported lang on the link overrides the lead's saved language. If the link's language is unsupported, the meeting uses the lead's saved language when supported, and otherwise the workspace default.
Label where meetings come from with ?src=, for example ?src=android or ?src=website; utm_source is also accepted. Analytics records device, source, website, and agent.
A native WebView must grant microphone capture, allow audio playback without a gesture, enable JavaScript and DOM storage, and stay mounted for the whole meeting. Test on the Android and iOS versions you support. A system browser tab uses the browser's normal permission prompt.
Prepare the product the agent demonstrates
Embedding the launcher and letting the agent use your product are separate steps. A Tour guide or Help desk shows your app in one of two ways, set up with your Insurge contact:
- Your app in a frame on the meeting page. Install the
browser-control-helper.jstag supplied by your Insurge contact on the demo product, and allow framing in itsContent-Security-Policy: frame-ancestors: includehttps://demo.insurgeai.com, your workspace's own link address if it has one, and every website that embeds the agent, because the browser checks each page that contains the frame. Remove conflictingX-Frame-Optionsheaders. - Your app streamed from a browser Insurge runs. Insurge opens the app with the sign-in saved for it and adds the helper itself, so the app needs no tag or framing change.
Either way, use a sandbox instance with sample data. Do not send anonymous visitors to a production account.
Copilot, Onboarding, and Training
These agents work inside your own app, in your user's existing session. They use the same On your site steps (on the Install tab) and the same kind of tag: paste it before </body> in your app's base layout. The tag adds the helper they need, so your app needs no framing change. They rest as a small button or a bar in the corner you choose, and open over your page; data-mode and data-target do not apply. On phones, a bar falls back to the button.
If your app sends a Content-Security-Policy header, allow https://demo.insurgeai.com and https://api.insurgeai.com in script-src, and https://demo.insurgeai.com in frame-src. See Which agent do I need?.
Test the website integration
Open the page in a fresh browser session and check:
- The agent is set to Live, and Check it is on your site lists your site.
- The launcher or inline container appears on every allowed site, and opening it starts the intended agent.
- The microphone prompt appears and spoken input works; the visitor can also type.
- On a phone, the launcher opens the agent full screen.
- Changing pages on your site does not restart the meeting.
- The visitor form, or
identify(), behaves as your workspace requires. - Your listener receives the expected milestone.
Troubleshoot an embed
| Symptom | What to check |
|---|---|
| Launcher does not appear | Open the browser console and look for a message starting Insurge embed:; it names the cause. Check that the tag is the one from On your site, that data-mode is not modal (modal has no launcher), that the agent is Live, that Testers only is off, and that your Content Security Policy allows https://demo.insurgeai.com in script-src and frame-src. |
| Console: unknown or expired demo code | Copy the current tag from On your site. |
| Console: the agent is not switched on for websites | Switch on Allowed on websites in step 1 and save your sites in step 2. |
| Console: temporarily unavailable, retrying on next page load | Reload the page later. |
| "Refused to connect" inside the overlay or frame | The site is not on the allowed list. Add its exact origin, including https:// and any www., in step 2, wait one minute, and reload. If the agent shows your app in a frame, also check that app's frame-ancestors policy. |
| No microphone prompt; voice unavailable | Include allow="microphone" on a custom iframe and check your page's Permissions-Policy. If the visitor blocked the microphone earlier, they must allow it again in the browser's site settings. |
| The agent appears as a narrow strip | Give the iframe a fixed height. |
| The agent restarts when the visitor changes page | Keep the tag outside route changes in your single-page app. |
Continue with the API reference and webhooks guide.