> For the complete documentation index, see [llms.txt](https://docs.spara.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.spara.com/developers/installation/iframe-and-cookies.md).

# iFrame & Cookies

How the Spara chat widget loads on your site, what data it stores, and how it interacts with cookie consent policies.

This page explains how the Spara chat widget works from a technical perspective, what data it stores in the browser, and how it relates to your website's cookie consent policies.

## How the Spara widget loads

When you add the Spara JavaScript snippet to your website, it creates an **iframe** (inline frame) that loads the [Chat](https://docs.spara.com/build/channels/chat) interface. An iframe is a standard web technology that embeds one webpage inside another — similar to how a YouTube video embed works.

The iframe approach means:

* **Spara's code runs in isolation** from your website's code. It cannot access your page's JavaScript variables, DOM, or other data unless explicitly passed through the embed snippet.
* **Your website's code runs in isolation** from Spara. Your scripts cannot access the contents of the Spara iframe.
* **Styling is independent.** Spara's styles do not conflict with your website's CSS, and vice versa.

## What Spara stores in the browser

Spara stores a small amount of data in the visitor's browser, mostly in **localStorage** and **sessionStorage**, plus one security cookie. Each item belongs to one of the consent categories described in [#how-spara-groups-what-it-collects](#how-spara-groups-what-it-collects "mention"):

* localStorage and sessionStorage data is **not sent to servers** with every HTTP request (unlike cookies)
* localStorage persists until it's cleared; sessionStorage is cleared when the tab closes
* Storage written on your site is **scoped to your website's domain** and can't be read by other websites. The chat widget's own storage belongs to its iframe on `app.spara.co`; modern browsers keep it separate for each website it's embedded on.

### On your website

| Key                                             | Where          | Purpose                                                                                                                                                                                              | Category   |
| ----------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| **Prelead UUID** (`{appId}-spara-prelead-uuid`) | localStorage   | A random identifier that recognizes a returning visitor, so they can pick up an earlier conversation. Also holds a random browser identifier used only for emailed identity links.                   | Functional |
| **Prelead UUID**, tab-only                      | sessionStorage | Used instead of the above when the visitor hasn't consented to Functional. A random identifier that keeps the conversation going between pages in the same tab and is forgotten when the tab closes. | Essential  |
| **Page visit tracking** (`spara_visit_*`)       | localStorage   | A per-day, per-URL marker that prevents counting the same page view twice in a day.                                                                                                                  | Analytics  |
| **Navigator closed** (`isNavigatorClosed`)      | localStorage   | Remembers that the visitor closed the chat launcher. Contains a timestamp, no identifier.                                                                                                            | Essential  |

### In the chat widget (`app.spara.co`)

| Key                                                                                     | Where                                                      | Purpose                                                                                                                                                                                                 | Category                         |
| --------------------------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| **Thread and lead IDs** (`{appId}-spara-thread-id`, `{appId}-spara-prospect-user-uuid`) | localStorage, or sessionStorage without Functional consent | Reopens the visitor's conversation.                                                                                                                                                                     | Functional (tab-only: Essential) |
| **Widget state** (`spara-float-state`, `spara-float-closed-at`)                         | localStorage, or sessionStorage without Functional consent | Whether the chat window was open, minimized, or closed. No identifier. Kept alongside the thread ID so a chat never reopens onto a conversation that's gone.                                            | Essential                        |
| **Page context** (`currentUrl`, `client-facts`)                                         | sessionStorage                                             | The current page URL, and any fields your page code passed to Spara, kept for the current tab so a new conversation starts with them.                                                                   | Essential                        |
| **`fastapi-csrf-token`**                                                                | Cookie on `app.spara.co`                                   | A security token that protects the widget's requests from cross-site request forgery. It's a random signed value, not tied to the visitor, marked `HttpOnly` and `Secure`, and isn't used for tracking. | Essential                        |

Spara does **not** store:

* Names, email addresses, or other personally identifiable information it collects itself. Fields your own page code passes to Spara (see [#what-the-widget-sends-to-spara](#what-the-widget-sends-to-spara "mention")) are kept in the widget's sessionStorage for the current tab.
* Cross-site identifiers

### Cookies

The only cookie Spara sets is the `fastapi-csrf-token` security cookie above. It's set on `app.spara.co` by the chat widget, not on your website's domain. Spara doesn't set any cookies on your website. Depending on the visitor's consent, the embed snippet reads (but never writes) these existing cookies on your site:

* **Google Analytics cookies** (`_ga`, `_ga_*`), Analytics: Spara reads the GA4 client ID and session ID so that Spara lead activity can be correlated with your Google Analytics data
* **Google Click ID cookies** (`_gcl_aw`, `_gcl_au`), Marketing: Spara captures these for ad attribution
* **Marketo cookie** (`_mkto_trk`), Marketing: read only when Marketo visitor recognition is enabled for your account
* **HubSpot cookie** (`hubspotutk`), Marketing: read only when HubSpot visitor recognition is enabled for your account

These cookies are set by Google Analytics, Google Ads, Marketo, and HubSpot, not by Spara. See [Query Parameters](https://docs.spara.com/developers/installation/query-parameters.md) for how to map the click ID cookies to fields.

Cookies set by other tools on your site (for example your own analytics or marketing tools) aren't set or controlled by Spara.

### What the widget sends to Spara

When the chat widget loads, it sends the current page URL to `app.spara.co`. Spara uses it to choose the right agent and to apply the query parameters you've mapped to fields. For visitors who haven't consented to Analytics, Spara uses the URL for that request and does not store it.

Fields your page code passes through the JavaScript API are also sent and saved for every visitor, whatever their consent, so decide whether to pass them before the visitor has consented.

## Cookie consent and Spara

A common question is whether Spara needs to be behind your cookie consent banner. Here are the technical facts:

* **Spara sets one cookie**, the `fastapi-csrf-token` security cookie on `app.spara.co`, which is strictly necessary for the widget to work
* **Spara generates a pseudonymous identifier** (the prelead UUID). With Functional consent it's kept in localStorage; without it, only in sessionStorage for the current tab
* **Spara reads existing Google Analytics, Google Ads, Marketo, and HubSpot cookies** if present, only with Analytics or Marketing consent when a consent platform is connected

### How Spara groups what it collects

Spara integrates with OneTrust, Transcend, and WPConsent. Rather than hiding the chat widget, Spara reads the visitor's consent choices and collects each kind of data only when the visitor has opted into its category. The chat is treated as required functionality and always loads.

Spara groups everything it collects into four categories:

<table data-full-width="true"><thead><tr><th width="160">Category</th><th>What Spara collects</th><th>Without consent</th></tr></thead><tbody><tr><td><strong>Essential</strong></td><td><ul><li>The chat widget and the conversation transcript, including anything the visitor types</li><li>The visitor's country, used for country-based display rules</li><li>A temporary identifier that keeps the conversation going between pages in the same tab</li><li>The current page URL, used to choose the agent and apply mapped query parameters (stored only with Analytics consent)</li><li>The kind of site the visitor came from (for example ChatGPT or Google), without the referring address</li><li>The site the visitor came from and the page they landed on, kept in <code>sessionStorage</code> until the tab closes so they can be recorded if the visitor consents later in the visit</li><li>The <code>fastapi-csrf-token</code> security cookie on <code>app.spara.co</code></li></ul></td><td>Always collected</td></tr><tr><td><strong>Functional</strong></td><td><ul><li>A persistent identifier (the prelead UUID in <code>localStorage</code>) that recognizes a returning visitor</li><li>Resuming an earlier conversation on a later visit</li><li>Emailed identity links that tie a visit to a known lead</li></ul></td><td>The visitor stays anonymous: the identifier lives in <code>sessionStorage</code> and is forgotten when the tab closes, every return visit starts a fresh conversation, and any identifier from an earlier visit is removed</td></tr><tr><td><strong>Analytics</strong></td><td><ul><li>Page visits and the visitor's path around your site</li><li>The site the visitor came from (the referrer) and the page they landed on, recorded on the lead and the conversation</li><li>The visitor's IP address</li><li>Google Analytics cookies (<code>_ga</code>, <code>_ga_*</code>) and events forwarded to your Google Analytics property</li></ul></td><td>Not collected</td></tr><tr><td><strong>Marketing</strong></td><td><ul><li>Visitor deanonymization (reverse-IP company lookup through Spara's providers)</li><li>Google Ads click cookies (<code>_gcl_aw</code>, <code>_gcl_au</code>) for attribution</li><li>Marketo and HubSpot visitor recognition (<code>_mkto_trk</code>, <code>hubspotutk</code>)</li></ul></td><td>Not collected</td></tr></tbody></table>

In **Chat Settings → Configuration → Cookie Consent**, pick your consent platform and enter the category that covers Functional, Analytics, and Marketing. Spara pre-fills each platform's standard categories:

| Category   | OneTrust group ID | Transcend purpose | WPConsent category |
| ---------- | ----------------- | ----------------- | ------------------ |
| Functional | `C0003`           | `Functional`      | `statistics`       |
| Analytics  | `C0002`           | `Analytics`       | `statistics`       |
| Marketing  | `C0004`           | `Advertising`     | `marketing`        |

Change any of them to match your own configuration, for example a custom Transcend purpose named `Marketing`. Several categories can share one ID. Leave a category blank to collect it for every visitor, as if it were essential.

No engineering work is required on your side: Spara reads the consent platform's JavaScript already present on your site.

### OneTrust integration

Spara reads the `OnetrustActiveGroups` global and the `OneTrustGroupsUpdated` event. Enter each group ID exactly as your OneTrust tenant reports it: most use the prefixed form (`C0002`), but some are configured with bare numbers (`2`), and the two are not interchangeable.

### Transcend integration

Spara reads the airgap.js script already on your site, via `airgap.getConsent()` and the `consent-change` event. Enter each purpose exactly as it's named in your Transcend consent configuration, including capitalization. Consent follows Transcend's own regional rules rather than any geography logic in Spara:

* A purpose the visitor has opted into counts as consent.
* A purpose Transcend reports as `Auto` (opted in by default under the visitor's regime, such as a US opt-out regime) counts as consent.
* A purpose the visitor has opted out of, or one Transcend doesn't report, does not.

{% hint style="warning" %}
airgap.js blocks network requests it can't classify. Classify Spara's domains (the embed script, `app.spara.co`, and the chat widget) as **Essential** in Transcend so the chat itself is never blocked. Spara enforces each category on its own side.
{% endhint %}

### WPConsent integration

Spara reads the WPConsent banner already on your site, via `WPConsent.lastPreferences`, the `wpconsent_preferences` cookie, and the `wpconsent_consent_processed` event. Enter each category as its slug, in lowercase: `statistics` and `marketing` for WPConsent's built-in categories, or the slug of a category you added yourself.

* WPConsent has no Functional category of its own; it treats preferences as essential. Spara's Functional category follows `statistics` by default, so a visitor who declines statistics stays anonymous. Change it to another category, or leave it blank to always remember returning visitors.
* In opt-out mode, WPConsent grants every category until the visitor declines, and Spara follows that.
* When a visitor changes an earlier choice, WPConsent reloads the page, and Spara applies the new choice on the reload.
* Until WPConsent reports a choice (for example, a visitor who hasn't answered the banner), Spara collects nothing that needs consent.

{% hint style="warning" %}
Keep Spara's embed script out of WPConsent's script blocking, or file it under **Essential**, so the chat itself always loads. Spara enforces each category on its own side.
{% endhint %}

### Changing consent mid-session

Consent changes take effect immediately, category by category:

* Granting Functional keeps the conversation already in progress and remembers the visitor from then on. Revoking it removes the stored identifier.
* Granting Marketing starts visitor deanonymization. Revoking Analytics or Marketing stops further collection in that category.

If your consent platform loads after Spara, Spara treats every category as not yet consented until the platform reports, so nothing gated is collected in the meantime. It only removes a visitor's stored identifier once the platform reports a decline, so a returning visitor who consented earlier keeps their conversation history. An emailed identity link that arrives in that window is applied if the visitor grants Functional, and discarded if they decline.

Two limitations are worth knowing:

* Third-party deanonymization scripts already loaded into the page before a revoke cannot be unloaded without a page reload, which Spara will not trigger on your site.
* A chat window already open when consent changes keeps its previous setting until the visitor navigates.

Consent settings don't change what the visitor chooses to share. Their transcript, and anything they type into chat (such as an email address), is always saved. Fields your own page code sends through the JavaScript API, and query parameters you have mapped to fields, are also always applied, so decide whether to send them for visitors who haven't consented.

{% hint style="warning" %}
Spara does not provide legal advice, and this integration does not by itself make your site compliant. Spara does not currently support Global Privacy Control (`Sec-GPC`) signals and does not keep a server-side record of consent decisions. Consult your legal or compliance team to determine the correct configuration for your privacy policy and applicable regulations (GDPR, CCPA, etc.).
{% endhint %}

### Without a consent platform

If no consent platform is connected, Spara collects every category above for all visitors. Organizations that would rather not load Spara at all before consent can continue to insert the embed snippet conditionally, based on their consent management platform's API.

## Z-index and stacking

The Spara chat widget uses a high `z-index` to ensure it appears above most page content. If your cookie consent banner also uses a high `z-index`, both elements can coexist — the banner will typically appear above or alongside the chat widget depending on your CSS. If you need to adjust layering, contact your Spara account manager.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.spara.com/developers/installation/iframe-and-cookies.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
