# In-app install reference

Put a copilot, onboarding or training agent inside your signed-in product with one tag, tell it who the user is, and decide what it may do on the page.

An in-app agent lives inside your own product, beside the screens your users work in. It reads the page they're on, answers questions about it, points at controls and walks people through tasks. You install it once, with a script tag in the layout every page of your app shares. Edits you save to the agent reach your app with no change to the tag.

**Available when your workspace has Copilots, Onboarding or Training**

If you don't see these agents under **Agents**, ask your Insurge contact to turn them on for your workspace.

## Before you start

- A copilot, onboarding or training agent that is **Live**.
- Someone with the **Admin** role in your Insurge workspace.
- Access to your app's base layout: the HTML that wraps every page.
- Your app served over HTTPS. The list of sites takes only `https` addresses, apart from `http://localhost` while you develop.

## Install it

### Open the Install tab

In the dashboard, go to **Agents**, open the agent and select the **Install** tab. **On your site** is at the top.

An in-app agent always installs as a script, because it has to see your app. **Inside the page** isn't offered for it.

### Turn it on for websites

Switch on **Allowed on websites**, then choose:

- **How it appears**: **Always on the page** or **Opens on a click or ⌘/**. See the table below.
- **Where**: **Bottom centre**, **Bottom right** or **Bottom left**.

Select **Save changes**.

### Choose the sites it can appear on

Add your app's address, and your staging address if you test there, then save. Browsers show the agent only on these sites, and every agent in your workspace shares the list. The address rules are the same as for the website embed: see [Choose the sites it can appear on](/docs/developers/embed).

### Copy the code

The first time, select **Create install code**. After that, select **Copy code**. The code belongs to this agent and never expires.

### Send it to whoever runs the app

Under **Then send it to whoever runs the site**, select **Copy**. You get plain-text instructions with your tag and the exact headers to allow.

Paste the tag once, before `</body>`, in the layout every page shares:

```html title="In-app install tag"
<script src="https://demo.insurgeai.com/embed/YOUR_CODE.js" async></script>
```

| Framework | Where to paste it |
|---|---|
| React, Vue or Angular app | `index.html`, before `</body>` |
| Next.js | `app/layout.tsx`, with `next/script` and `strategy="afterInteractive"` |
| Google Tag Manager | A Custom HTML tag on All Pages |

## How it appears

| Setting | What your users see |
|---|---|
| **Always on the page** | A slim ask box at the bottom of every page. Nothing starts until someone asks. Ctrl+/ (⌘/ on a Mac) puts the cursor in it. |
| **Opens on a click or ⌘/** | A small pill in the corner. A click, or Ctrl+/ (⌘/ on a Mac), opens the box, and Esc closes it. |

On phones it is always the small pill. There is no chat bubble, so your own support widget keeps its corner. With **Always on the page**, Esc pressed in your app stays with your app.

To change one page, add an attribute to the tag:

| Attribute | Values | What it does |
|---|---|---|
| `data-presence` | `bar`, `pill` | `bar` is **Always on the page**; `pill` is **Opens on a click or ⌘/**. |
| `data-position` | `bottom-center`, `bottom-right`, `bottom-left` | Where it sits. |

An onboarding or training program set to **Offer it on first visit** shows its offer card on its own, with no code on your side. To limit what one tag offers, add `show` to the address in the tag:

| Tag address ends with | What it offers |
|---|---|
| `YOUR_CODE.js?show=copilot` | The ask box only. No program is offered by itself. |
| `YOUR_CODE.js?show=onboarding` | This agent's onboarding program: the one set to **Offer it on first visit**, else the first. |
| `YOUR_CODE.js?show=training` | The same, for a training program. |

## Tell it who the user is

Your users are already signed in, so there's no need for the agent to ask who they are. Call `identify()` once your app knows the user:

```js title="Identify the signed-in user"
InsurgeDemo.identify({
  email: currentUser.email,   // required
  name: currentUser.name,
  company: currentUser.companyName,
  role: currentUser.jobTitle,
});
```

- `email` is required. The other fields, and `fields` for your own visitor form questions, follow the same rules as on a website: see [Pass in a visitor you already know](/docs/developers/embed).
- Call it on each page load. It's held until the user first asks, and used once per browser tab.
- With the user identified, the visitor form is skipped and the agent knows their name.

The **Visitor form** switch is under **Links** on the same **Install** tab. On, the agent asks for the form's details inside its own box, once per visit, before its first answer. Leave it off when your app calls `identify()`, or when you don't need to know who asked. See [Visitor form](/docs/agents/visitor-form).

## Tell it what your app knows

The agent sees the screen. Your app knows things the screen doesn't show, such as the user's plan or how far they are through setup. Hand those over with `context()`:

```js title="Send context"
InsurgeDemo.context({
  plan: "Growth",
  role: "admin",
  setup_done: ["profile", "team"],
  trial_days_left: 9,
});
```

The latest object you send goes with each question the user asks. Call it again whenever something changes, for example on a route change. `InsurgeDemo.context({})` clears it.

| Limit | Value |
|---|---|
| Keys | Up to 24. Later keys are dropped. |
| Key length | Up to 48 characters |
| Values | Text, numbers, `true` or `false`, or lists of those. Nested objects are dropped. |
| Text value | Up to 300 characters. Longer text is cut. |
| List | Up to 12 items |
| Whole object | About 2,000 characters as the agent reads it. Anything past that is cut. |

The agent treats context as facts about the user, never as instructions to follow. Don't put secrets or anything you wouldn't show the user in it.

## Tell it what happened in your app

Call `event()` when something happens in your app that the agent should know about, such as a record being saved:

```js title="Report an event"
InsurgeDemo.event("invoice.created", { total: 4200, currency: "INR" });
```

- The name starts with a lowercase letter and uses lowercase letters, digits, `_` and `.`, up to 64 characters.
- The data is an object of up to 2 KB as JSON.
- It returns `false` when the name or data is refused.
- The agent reads it with the user's next question. A guide step can also wait for one of your events: ask your Insurge contact to set that up.
- Up to 10 a second are taken; more are dropped. Events sent before the agent has opened wait, up to the last 50.

## Ask on the user's behalf

`ask(text)` opens the agent and asks `text` as if the user had typed it, up to 1,000 characters. Use it for a "Show me how" button beside a feature:

```html title="A help button of your own"
<button type="button" onclick="InsurgeDemo.ask('How do I invite my team?')">Show me how</button>
```

## Start a guide from your own button

Every in-app agent can lead people through your workspace's guides. Programs with **Offer it on first visit** need no code. To start a guide from your own button or at a moment you choose, use `InsurgeDemo.guide`:

| Method | What it does |
|---|---|
| `guide.available` | `true` when this agent can lead guides on this page. |
| `guide.start(options)` | Starts a guide. Returns `false` when it can't: no guides here, no `flow`, or options over 8 KB. |
| `guide.stop()` | Stops the guide that is running. |
| `guide.open()` | Opens the guide's box: the checklist while a guide runs, otherwise where users ask a question or pick a guide. |
| `guide.prepare()` | Loads the part that reads your page ahead of time, without opening anything. |
| `guide.setLanguage(code)` | Sets the language for this and later guides, as a two-letter code such as `hi`. |
| `guide.offer(options)` | Shows the offer card for a guide, with a **Start** button. `guide.offer(null)` takes it down. |

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `flow` | `string` | Yes | The guide's key: the last part of the guide's address in the dashboard, under Knowledge, Guides. |
| `name` | `string` | No | The user's name, for the greeting. Up to 80 characters. |
| `lang` | `string` | No | A two-letter language code, used when the guide is written in that language. |
| `voice` | `"on" \| "off"` | No | Whether the guide speaks. |
| `visitor` | `string` | No | Your own id for the user, up to 128 characters. Keeps their place in the guide across browsers. Without it, their place is kept in this browser. |
| `workspace` | `string` | No | Your own id for the user's team or account, up to 128 characters, so one person's place is kept apart per account. |

`guide.offer()` takes the same options, plus `title` (the card's heading) and `sub` (a line under it).

```js title="Start a guide and follow it"
if (InsurgeDemo.guide.available) {
  InsurgeDemo.guide.start({
    flow: "YOUR_GUIDE_KEY",
    name: currentUser.firstName,
    visitor: currentUser.id,
  });
}

InsurgeDemo.on("guide", (state) => {
  if (state.status === "done") markOnboardingStepComplete();
});
```

`guide` isn't in the queue line that holds early calls, so call it after the tag has loaded.

**visitor and workspace are not checked**

Anyone who can run script on your page can change them. Use them to keep a user's place in a guide, never to grant access to anything.

### Guide events

`InsurgeDemo.on("guide", callback)` hears each change. The object has a `status`; while a guide is running it also has `flow`, `title`, `step` (counted from 0) and `total`.

| `status` | Meaning |
|---|---|
| `running` | A guide is going. |
| `held` | It's waiting: on a question, or the user chose **Not now**. |
| `rest` | No guide is running. The box is ready for a question. |
| `done` | The user finished the guide. |
| `stopped` | The guide was closed before the end. |
| `off` | This agent may not lead guides here. |
| `invalid` | The options passed to `guide.start()` were refused. |
| `dismissed` | The user closed the offer card. |

The website milestones (`lead_submitted`, `support_started`, `demo_completed`) reach your page from an in-app agent too, through `InsurgeDemo.on` and Google Tag Manager. See [Events](/docs/developers/embed).

## What the agent can and cannot do

You choose how much it may do on the agent's **Behaviour** tab, under **What it may do**, with **Actions**:

| **Actions** | What it does |
|---|---|
| **Guide only** | Points at things and explains. Never clicks. |
| **Act when asked** (recommended) | Can click and type to show the user, and asks before anything that saves, sends or deletes. It goes ahead only after **Yes, do it**, or a spoken or typed yes. |

Where your workspace has the guide, **Settings**, **Guide** has two more lists: **Ask before pressing** (controls it always asks about first) and **Never point at** (controls it keeps people away from).

**It can:**

- Read the page in the user's tab: its text, its controls and what's typed in ordinary fields.
- Follow the user as they move between pages and routes.
- Point at and highlight controls, and act on them as **Actions** allows.
- Notice whether your app sent a change to your server right after one of its presses, so it knows a press saved something. It keeps the kind of request and its path, not what was sent or returned.

**It can't:**

- Read what's in password fields, one-time-code fields, or card fields (`autocomplete` values that start with `cc-`).
- See inside frames from another site on your page.
- See other tabs, other windows or anything outside the page.
- Act outside a session. It works only in the tab of a user who is talking to it, with that user's own sign-in.

Users can see this for themselves: the guide's **What can it see?** explains it in plain words.

The part that reads your page loads from `https://api.insurgeai.com` the first time it's needed: when someone opens or asks the agent, or when it shows an offer. It isn't loaded on every page view before that.

## Single-page apps and page loads

- Put the tag once, in the shell that wraps every route. Route changes are followed with no code from you.
- If you report `context()`, send it again when the route changes what you report.
- After a full page load the conversation carries on in the same tab: it reconnects by itself.
- A guide that is running comes back after a reload, and in a new tab of the same browser. Otherwise a new tab starts fresh.

## Security headers

If your app sends these headers, add Insurge's addresses to them. The instructions you copied from the dashboard list the same values.

| Header | Add |
|---|---|
| `Content-Security-Policy`, `script-src` | `https://demo.insurgeai.com https://api.insurgeai.com` |
| `Content-Security-Policy`, `frame-src` | `https://demo.insurgeai.com` |
| `Permissions-Policy` | `microphone=(self "https://demo.insurgeai.com")`. Without it, users type instead of talking. |
| `Content-Security-Policy`, `img-src` | Optional: `https://api.insurgeai.com`. The pointer can use a picture from there; blocked, it's a plain arrow. |
| `Content-Security-Policy`, `font-src` | Optional: `https://demo.insurgeai.com`. The guide's typeface loads from there; blocked, it uses the system font. |

The agent draws its box and pointer with styles inside your page, so a `style-src` that refuses inline styles can break how it looks.

## Test it before your users see it

- **On your computer**: add `http://localhost:` and your port as a site in step 2, then load your app locally.
- **On staging**: add your staging address in step 2. The list is shared by every agent in the workspace.
- **On production, for testers only**: switch on **Testers only** and save. The agent shows only in a browser that has opened a page of your app with `?insurge_preview=1` at the end of the address; `?insurge_preview=0` forgets it.
- **Its answers, without installing**: the link under **Links** on the **Install** tab opens the ask box on its own page.

See [Preview and test](/docs/agents/preview-and-test).

## Turn it off or remove it

| To | Do this |
|---|---|
| Hide it everywhere at once, leaving the tag in place | Switch off **Allowed on websites** and select **Save changes**. |
| Stop the agent everywhere, links included | Switch it from **Live** to **Paused** at the top of its page. |
| Take every agent off one site | Remove that site from step 2 and save. |
| Remove it for good | Delete the tag from your layout. |

## Troubleshooting

Messages from the tag in your browser's developer console start with `Insurge embed:` or `Insurge copilot:`.

| What you see | Why | What to do |
|---|---|---|
| Nothing, and the console says `this agent isn't switched on for websites` | **Allowed on websites** is off or not saved, embedding is off for the workspace, or your workspace no longer has this kind of agent. | Switch it on in step 1 and save. If step 2 says **Embedding is off for the workspace**, select **Switch embedding on**. Otherwise ask your Insurge contact. |
| Nothing, and the console says `unknown or expired demo code` | The code in the tag is wrong. | Copy the tag again from the **Install** tab. |
| Nothing, and no console message | **Testers only** is on. | Open your app with `?insurge_preview=1`, or switch **Testers only** off. |
| The box or panel is blank, and the console mentions `frame-ancestors` | Your app's address isn't in step 2, was added less than a minute ago, or the agent is **Paused**. | Add the exact address, wait a minute and reload. Check the agent is **Live**. |
| It answers but never points or acts on the page | Your `script-src` blocks `https://api.insurgeai.com`. (If it points but never clicks, **Actions** is **Guide only**.) | Add the address to `script-src`. Check **What it may do**. |
| The console says the page `already loads browser-control-helper.js WITHOUT ?mode=ridealong` | An older Insurge tag from an earlier install is still on the page. | Remove the older tag. The install tag loads what it needs. |
| It can't find a control inside an embedded frame | The frame comes from another site. | Nothing to change on your side: the agent can't see into it. |
| `guide.start()` returns `false` | `guide.available` is `false`, `flow` is missing, or the options are over 8 KB. | Check `guide.available` first and pass a `flow`. |
| `on("guide")` hears `invalid` | An option has the wrong format, for example a `lang` that isn't two letters. | Check the options against the table above. |
| `on("guide")` hears `off` | This agent may not lead guides. | Ask your Insurge contact. |
| No mic button, or **The mic is blocked by the browser** | Your `Permissions-Policy` blocks the microphone, or the user refused the mic. | Allow the microphone as shown above. A user who refused can allow it from the browser's address bar. |
