Widget Public API¶
If you add custom code to your website, Rose exposes a small browser API on window.InboundXWidget.
You can use it to:
- check whether the widget is ready
- read Rose identity context from your own scripts
- add Rose session and visitor IDs to your own links, redirects, forms, or booking flows
- send Rose visitor IDs into tools such as HubSpot so contacts can be matched back to Rose
- tell Rose when your cookie banner allows it to identify the visitor
When to use it¶
The widget loads in the background after your page starts rendering.
If you want to read data from the widget as soon as the page loads, wait until Rose is ready:
<script>
function waitForRoseReady(callback) {
const tryAgain = () => {
if (!window.InboundXWidget) {
window.setTimeout(tryAgain, 100);
return;
}
if (window.InboundXWidget.isReady?.()) {
callback();
return;
}
if (window.InboundXWidget.onReady) {
window.InboundXWidget.onReady(callback);
return;
}
window.setTimeout(tryAgain, 100);
};
tryAgain();
}
waitForRoseReady(() => {
console.log('Rose is ready');
});
</script>
You can also check readiness manually:
This returns:
truewhen the widget is fully loadedfalsewhen it is still loading
Available methods¶
| Method | What it does | Typical use |
|---|---|---|
isReady() |
Returns true when the widget is ready |
Check whether you can safely call the API |
onReady(callback) |
Runs your callback once the widget is ready | Best option when adding custom scripts |
getIdentityContext() |
Returns all available Rose identifiers in one object | Recommended for forms, HubSpot, booking links, and redirects |
getLastActiveSessionId() |
Returns the most recent Rose session where the visitor actively engaged | Best session ID for CRM and post-chat conversion attribution |
getSessionId() |
Returns the current Rose session ID | Use only when you specifically need the current page's widget session |
getVisitorId() |
Returns Rose's visitor ID for this browser when available | Send this to HubSpot or your CRM to match contacts back to Rose visitors |
getPersonId() |
Returns the visitor's Rose person ID when available | Useful for advanced tracking |
trackFormSubmitted(data?) |
Reports a form submission to Rose (fires the conversion event) | Use when Rose cannot auto-detect your form (custom JS or single-page app) |
startPostConversionQualification(options?) |
Opens Rose's post-conversion qualification flow | Use after your own conversion success signal when Rose cannot detect it reliably |
setIdentificationConsent(granted) |
Tells Rose whether your cookie banner allows visitor identification | Sites where Rose identifies visitors only after consent |
setConsentMode(mode) |
Switches between pending, cookieless, and full |
Keep chat available without browser persistence before consent |
What getIdentityContext() returns¶
{
sessionId: "sess_123",
lastActiveSessionId: "sess_123",
personId: "person_456",
visitorId: "visitor_789"
}
Some values can be null.
For example:
lastActiveSessionIdis the session ID to forward to HubSpot, booking tools, or your own CRM because it points to the last conversation where the visitor actively engagedsessionIdis the current widget session on the page. Do not use it as a fallback for CRM attribution.visitorIdidentifies the Rose visitor and is the value to ingest into HubSpot when you want to match a contact back to RosepersonIdmay still benullif Rose has not identified the visitor yet
If you are forwarding multiple values, call getIdentityContext() once. If you only need one value, use the dedicated getter.
Most common use case¶
For most integrations, collect the identity context and forward both:
rose_session_id:lastActiveSessionIdrose_visitor_id:visitorId
const identity = window.InboundXWidget?.getIdentityContext?.();
const roseSessionId = identity?.lastActiveSessionId;
const roseVisitorId = identity?.visitorId;
if (!roseSessionId) {
console.log('No active Rose conversation yet');
} else {
const rosePayload = {
rose_session_id: roseSessionId,
rose_visitor_id: roseVisitorId
};
// Add rosePayload to your CRM form, redirect, or booking link.
}
The same logic with dedicated getters looks like this:
const roseSessionId = window.InboundXWidget?.getLastActiveSessionId?.();
const roseVisitorId = window.InboundXWidget?.getVisitorId?.();
if (!roseSessionId) {
console.log('No active Rose conversation yet');
} else {
const rosePayload = {
rose_session_id: roseSessionId,
rose_visitor_id: roseVisitorId
};
// Add rosePayload to your CRM form, redirect, or booking link.
}
Use this after the widget is ready, or inside a click handler.
Example: add Rose IDs to your redirect URL¶
Here is the basic idea:
const url = new URL('https://example.com/book-demo');
const identity = window.InboundXWidget?.getIdentityContext?.();
const lastActiveSessionId = identity?.lastActiveSessionId;
const visitorId = identity?.visitorId;
if (lastActiveSessionId) {
url.searchParams.set('rose_session_id', lastActiveSessionId);
}
if (visitorId) {
url.searchParams.set('rose_visitor_id', visitorId);
}
window.location.href = url.toString();
If both IDs are available, the final URL becomes:
If the visitor has not had an active Rose conversation yet, lastActiveSessionId can be null. In that case, the redirect still works and opens without rose_session_id.
Example: add Rose IDs to hidden form fields¶
Use this pattern when your form or HubSpot form includes hidden properties for Rose data.
<input type="hidden" name="rose_session_id" id="rose-session-id" />
<input type="hidden" name="rose_visitor_id" id="rose-visitor-id" />
<script>
window.InboundXWidget?.onReady?.(() => {
const identity = window.InboundXWidget.getIdentityContext();
const lastActiveSessionId = identity.lastActiveSessionId;
const sessionInput = document.getElementById('rose-session-id');
const visitorInput = document.getElementById('rose-visitor-id');
if (lastActiveSessionId && sessionInput) {
sessionInput.value = lastActiveSessionId;
}
if (identity.visitorId && visitorInput) {
visitorInput.value = identity.visitorId;
}
});
</script>
In HubSpot, create matching contact properties such as rose_session_id and rose_visitor_id, then map your hidden fields to those properties.
Examples by platform¶
<button id="book-demo-button">Book a demo</button>
<script>
document.addEventListener('DOMContentLoaded', () => {
const button = document.getElementById('book-demo-button');
if (!button) return;
button.addEventListener('click', () => {
const url = new URL('https://example.com/book-demo');
const identity = window.InboundXWidget?.getIdentityContext?.();
const lastActiveSessionId = identity?.lastActiveSessionId;
const visitorId = identity?.visitorId;
if (lastActiveSessionId) {
url.searchParams.set('rose_session_id', lastActiveSessionId);
}
if (visitorId) {
url.searchParams.set('rose_visitor_id', visitorId);
}
window.location.href = url.toString();
});
});
</script>
import React from 'react';
export default function BookDemoButton() {
const handleClick = () => {
const url = new URL('https://example.com/book-demo');
const identity = window.InboundXWidget?.getIdentityContext?.();
const lastActiveSessionId = identity?.lastActiveSessionId;
const visitorId = identity?.visitorId;
if (lastActiveSessionId) {
url.searchParams.set('rose_session_id', lastActiveSessionId);
}
if (visitorId) {
url.searchParams.set('rose_visitor_id', visitorId);
}
window.location.href = url.toString();
};
return <button onClick={handleClick}>Book a demo</button>;
}
import * as React from 'react';
export default function BookDemoButton() {
const handleClick = () => {
const url = new URL('https://example.com/book-demo');
const identity = window.InboundXWidget?.getIdentityContext?.();
const lastActiveSessionId = identity?.lastActiveSessionId;
const visitorId = identity?.visitorId;
if (lastActiveSessionId) {
url.searchParams.set('rose_session_id', lastActiveSessionId);
}
if (visitorId) {
url.searchParams.set('rose_visitor_id', visitorId);
}
window.location.href = url.toString();
};
return (
<button
onClick={handleClick}
style={{ padding: '12px 20px', cursor: 'pointer' }}
>
Book a demo
</button>
);
}
In Framer, you can use this inside a Code Component or a custom code block.
Give your button an ID such as book-demo-button, then add this in Project Settings → Custom Code or on the page:
<script>
document.addEventListener('DOMContentLoaded', () => {
const button = document.getElementById('book-demo-button');
if (!button) return;
button.addEventListener('click', function (event) {
event.preventDefault();
const url = new URL('https://example.com/book-demo');
const identity = window.InboundXWidget?.getIdentityContext?.();
const lastActiveSessionId = identity?.lastActiveSessionId;
const visitorId = identity?.visitorId;
if (lastActiveSessionId) {
url.searchParams.set('rose_session_id', lastActiveSessionId);
}
if (visitorId) {
url.searchParams.set('rose_visitor_id', visitorId);
}
window.location.href = url.toString();
});
});
</script>
If you want to read identity context immediately on page load¶
For example, if you want to store Rose IDs in your own script before any button click, use waitForRoseReady:
<script>
function waitForRoseReady(callback) {
const tryAgain = () => {
if (!window.InboundXWidget) {
window.setTimeout(tryAgain, 100);
return;
}
if (window.InboundXWidget.isReady?.()) {
callback();
return;
}
if (window.InboundXWidget.onReady) {
window.InboundXWidget.onReady(callback);
return;
}
window.setTimeout(tryAgain, 100);
};
tryAgain();
}
waitForRoseReady(() => {
const identity = window.InboundXWidget.getIdentityContext();
const lastActiveSessionId = identity.lastActiveSessionId;
if (!lastActiveSessionId) {
console.log('No active Rose conversation yet');
return;
}
console.log('Rose last active session:', lastActiveSessionId);
console.log('Rose visitor:', identity.visitorId);
});
</script>
Report a form submission¶
Rose automatically detects most form submissions. If your form uses custom
JavaScript or a single-page app flow that Rose cannot observe, call
trackFormSubmitted() yourself when the submission succeeds. This fires the same
conversion event Rose records for auto-detected forms.
This method only reports the conversion event. To open Rose's qualification flow,
use startPostConversionQualification().
Call it from your own success handler — for example, after your form's API call returns OK:
// In your form's "submitted successfully" handler:
window.InboundXWidget?.trackFormSubmitted?.({ formId: 'demo-request' });
- All fields are optional.
trackFormSubmitted()with no arguments works. formIdis optional — pass it only if you want to tell several forms apart in analytics.- The widget loads in the background, so guard the call with
?.(oronReady). A call made once the widget script has loaded but before Rose has finished starting is kept and sent as soon as Rose is ready, as long as the visitor stays on the page. It returnsfalseonly when Rose cannot run on this page.
window.InboundXWidget?.onReady?.(() => {
// ... later, when the form is submitted:
window.InboundXWidget.trackFormSubmitted({ formId: 'demo-request' });
});
Prefer no-code? Use Google Tag Manager
If you manage your tags through GTM, you can fire this same conversion from a GTM tag on form submit — without editing your site code. See GTM Conversion Tracking.
Start post-conversion qualification¶
If your site already knows when a visitor has converted, call
startPostConversionQualification() from your own success handler. Rose opens
the widget and starts the configured post-conversion qualification questions.
// In your form's "submitted successfully" handler:
window.InboundXWidget?.startPostConversionQualification?.({
formId: 'demo-request',
context: {
email: 'lead@example.com',
utm_source: 'google'
}
});
formIdis optional when your Rose config has one post-conversion form. Pass it when several forms exist.contextis optional. Values are included in Rose's post-conversion completion payload asvisitor_contact.trackConversiondefaults tofalse. SettrackConversion: trueonly if you also want this call to record Rose's conversion event.- The widget loads in the background, so guard the call with
?.or run it insideonReady.
window.InboundXWidget?.onReady?.(() => {
// ... later, when your form submission succeeds:
window.InboundXWidget.startPostConversionQualification({
formId: 'demo-request',
trackConversion: true
});
});
Open Rose on a question from a link¶
Add rose_q to any link to a page where Rose is installed. Rose opens and asks that
question as soon as the page loads, as if the visitor had typed it. No code is needed.
- Encode the question for a URL (a space becomes
%20,?becomes%3F). Most email and link tools do this for you. - Use it in emails, ads, QR codes or buttons on another site. Keep your usual UTM
parameters: Rose removes only
rose_qfrom the address bar, so a refresh does not ask the question again. - The question is cut at 500 characters. An empty
rose_qis ignored. - If Rose starts as a hidden zone on your site, the link opens it as if the visitor had clicked it.
- Nothing happens on pages where a page rule hides the widget, or on Form Assistant pages: link to another page.
- If your site redirects visitors when they arrive (for example to a language version) and that redirect drops the query string, the question is lost. Link to the final page instead.
Keep chat available without cookies¶
Configure the loader with consentMode: 'pending' before it loads the widget:
window.InboundXLoader.init({
api_key: 'YOUR_API_KEY',
api_host: 'YOUR_API_HOST',
consentMode: 'pending'
});
Alternatively, set data-consent-mode="pending" on the widget script, or supply
consentMode to InboundXWidget.init(). With no mode supplied, Rose defaults to
full; existing installations do not become consent-managed automatically.
| Mode | Browser persistence and identification | Chat and measurement |
|---|---|---|
pending |
Off, except the current chat in the browser tab | Chat continues across pages of the tab; limited cookieless usage events |
cookieless |
Off, except the current chat in the browser tab | Same behavior as pending; use after refusal |
full |
Enabled, subject to your identification settings | Current chat continues; optional providers can start |
The cookieless usage events carry the page address without its query string or anchor, the domain of the site the visitor came from, the browser's user agent, and a random identifier of the page visit or of the current chat (kept across the pages of the tab). They carry no persistent visitor identifier: Rose's analytics provider counts a visitor once per day from the user agent, and can't follow them to another day. Your cookie policy can describe them.
From your banner's callback, call:
window.InboundXWidget.setConsentMode('full'); // Accepted
window.InboundXWidget.setConsentMode('cookieless'); // Refused or withdrawn
If the widget has not loaded yet, update
window.__INBOUNDX_CONSENT_MODE__ instead. Once the public API is available, use
setConsentMode(); changing the global directly does not run transition cleanup.
Read your banner's saved choice on every page load and seed the mode before Rose
starts. Rose neither reads the banner itself nor saves a separate consent choice.
Withdrawal from full reloads the page and ends the active chat. Rose clears its
own persistence before reloading, because loaded identification SDKs cannot be
reliably stopped in place. Snitcher writes its rosrd_ identifiers back while the page
unloads, so Rose removes them again on every load that starts without full consent.
Save the refusal in your CMP first, so the next load starts in pending or cookieless. Repeated calls with the same mode do nothing.
Acceptance does not reload or replay previously anonymous analytics events.
In pending/cookieless mode, personId, visitorId, and lastActiveSessionId are
null. Until the visitor sends a message, the sessionId lasts one page load. Once they
send one, Rose keeps the chat in the tab's sessionStorage (the session ID, the
transcript, the chat language and a marker saying the chat started without consent,
under keys starting with inboundx_), so the chat continues when the visitor opens
another page or refreshes. A chat that went on with consent is never restored after a
refusal or withdrawal, and its turns from before consent are never exported. Closing the tab ends it.
Nothing else is stored and nobody is identified. If the visitor accepts cookies later,
the same chat continues in full mode.
Credit later forms to the chat¶
By default, a form the visitor fills on a later page than the chat counts as a separate
session, credited to the chat only through Rose's same-day estimate. To credit it, pass
cookielessAttribution: true to InboundXLoader.init() (or InboundXWidget.init()).
This uses the chat's session ID for a second purpose, measuring conversions; check with
your counsel that your consent setup covers it before turning it on.
When the form is on another host than the chat (a chat on www.example.com, a signup on
app.example.com or on another domain of yours), Rose adds the chat's session ID to the
CTA links it decorates, under your session_utm_name parameter, and the form page reads
it from its address. Nothing else crosses: no visitor ID, no forwarded campaign
parameters, nothing stored on the visitor's device. Both pages need the Rose script with
cookielessAttribution: true, and both hosts must be registered as your domains: Rose
never credits a form to another client's chat.
Automatic profiling, booking forms, identification, and transcript exports are
disabled; ordinary destination links still work.
A visitor can still deliberately give their own email in chat for follow-up or a booking request. Rose records that contact separately and can forward it through your configured HubSpot email-capture integration, without the conversation text or tracking identifiers. An incidental email mention is not a contact submission. This does not accept cookies, enable enrichment, or authorize unrelated marketing.
Set it up with a coding agent¶
Give these instructions to your coding agent. They work with any cookie banner:
Connect this website's cookie banner to Rose consent mode. Rose does not read the banner:
the site must tell Rose the visitor's choice.
1. Find where Rose is initialized (InboundXLoader.init, or the Rose script tag) and find
the cookie banner and how to read its saved choice. If the site has no banner, stop
and ask.
2. On every page load, before Rose initializes, read the saved choice and pass
consentMode: 'full' if accepted, 'cookieless' if refused, 'pending' if there is no
choice yet or the banner is not ready.
3. When the visitor's choice changes, let the banner save it first. Then call
window.InboundXWidget.setConsentMode('full') if accepted, or 'cookieless' if refused
or withdrawn. If the widget has not loaded yet, set
window.__INBOUNDX_CONSENT_MODE__ to that value instead.
4. If the site uses Rose's "Identify only after cookie consent" setting, also call
window.InboundXWidget.setIdentificationConsent(true) when the visitor accepts.
5. List any other tags that set cookies without following the banner, and report them
without changing them.
Do not change the Rose API key, store a separate consent choice, or add legal claims.
Check in a browser with cleared site data:
- No choice or refused: chat works, and Rose adds no cookies or localStorage (names
starting with rose_, inboundx_, rosrd_ or ph_). After a message, sessionStorage holds only
inboundx_session_, inboundx_chat_state_ and inboundx_lang_ keys and
inboundx_private_chat, and the chat continues on another page.
- Accept: the same chat continues, and Rose's cookies appear.
- Withdraw after accepting: Rose's data is cleared, the page reloads, and the next load
starts as refused, with no rosrd_ cookie or storage key left.
- Reload after each choice: the choice is kept.
Check it works¶
Open your site in a private window, with your browser's developer tools on the
Application tab (Storage in Firefox). In the console,
window.__INBOUNDX_CONSENT_MODE__ shows the mode Rose is in.
- Before choosing, or after refusing: chat with Rose. It answers, and no cookie or
localStorage entry starting with
rose_,inboundx_,rosrd_orph_appears. Open another page: the chat is still there. - Accept cookies: the same chat continues, and Rose's cookies appear.
- Withdraw consent: the page reloads, Rose's cookies and storage are gone, and Rose starts again without cookies.
- Reload after each choice: Rose follows the choice your banner saved.
Privacy and your responsibilities¶
In pending and cookieless modes, Rose sets no cookies or long-lived browser storage on
the visitor's device. Once the visitor sends a message, it keeps that chat in the tab's
sessionStorage so it survives a page change; the browser deletes it when the tab closes.
Usage is measured through PostHog's cookieless mode. PostHog receives the visitor's IP address and user agent, uses them to compute a daily hash, then removes them from the stored event. Rose keeps that hash and a temporary session ID with each usage event, so it can report chats and conversions per session and estimate same-day conversions. When the visitor leaves the page or switches tab, the widget also sends Rose (not PostHog) a page-leave event that carries only that session ID and your site's origin, so the visit duration can be measured.
Cookieless does not mean no data is processed. Messages reach Rose and its AI model providers. Transient chat context is kept for up to 24 hours after its last write, and retained conversations have email addresses and phone numbers masked, which is not complete removal of personal data. If a visitor chooses to leave an email for follow-up, Rose keeps it and can send it to your configured CRM.
Rose acts as your data processor. You remain the controller: you decide your legal basis and what you tell visitors, including whether your cookie banner needs to cover this mode. This is not legal advice, so we recommend checking with your own counsel before enabling it. Contact your Rose team before enabling this mode in production.
Identification setting¶
The existing Identify only after cookie consent setting is independent:
setConsentMode('full') does not override an identification refusal. If enabled,
your integration must also report setIdentificationConsent(true) for identification.
Identify visitors only after cookie consent¶
By default Rose identifies a visitor's company (IP lookup and de-anonymization providers) once they engage with the widget. If your cookie banner must allow this first, ask your Rose account manager to turn on Identify only after cookie consent for your site. Rose then stays visible and answers every visitor, but identifies nobody until your page reports consent.
Report consent from your banner's consent callback, or from a Google Tag Manager tag fired by your consent trigger:
function setRoseIdentificationConsent(granted) {
// Read by Rose if it loads after this call.
window.__INBOUNDX_IDENTIFICATION_CONSENT__ = granted;
// Applies immediately if Rose is already loaded.
window.InboundXWidget?.setIdentificationConsent?.(granted);
}
Call setRoseIdentificationConsent(true) when the visitor accepts and
setRoseIdentificationConsent(false) when they refuse or withdraw consent. Calling it
on every page load, before or after Rose loads, and calling it several times, are all
safe: the latest value wins.
- Consent given mid-conversation: Rose identifies the visitor from their next message.
- Consent withdrawn (
false): Rose starts no new identification on that page. - Rose does not read your banner itself. You choose which consent purpose allows visitor identification.
- The option covers identification only. Before consent, Rose still stores its session and analytics identifiers in the browser, records the conversation and measures widget usage (displays, opens, messages) under that analytics identifier. To disable browser persistence too, use consent mode.
Example with a banner that implements the IAB TCF v2 API (Sirdata, Didomi, OneTrust…):
<script>
window.__tcfapi?.('addEventListener', 2, function (tcData, success) {
if (!success) return;
if (tcData.eventStatus !== 'tcloaded' && tcData.eventStatus !== 'useractioncomplete') return;
// Replace with the purpose(s) you map to visitor identification.
setRoseIdentificationConsent(tcData.purpose.consents[1] === true);
});
</script>
With Google Tag Manager, add a Custom HTML tag containing
<script>setRoseIdentificationConsent(true);</script> (define the function in the
same tag or earlier) and fire it on the trigger your banner uses for the accepted
consent.
Which method should I use?¶
| Goal | Recommended method |
|---|---|
| Wait until Rose is ready | onReady(callback) |
| Check readiness manually | isReady() |
| Add Rose IDs to HubSpot, a form, a booking link, or a redirect | getIdentityContext() |
| Get the best session ID for CRM attribution | getLastActiveSessionId() |
| Get the current page's widget session ID | getSessionId() |
| Get the Rose visitor ID for CRM matching | getVisitorId() |
| Report a form submission Rose cannot auto-detect | trackFormSubmitted(data?) |
| Start Rose qualification after a known conversion | startPostConversionQualification(options?) |
| Open Rose on a question from a link (email, ad, QR code) | ?rose_q=<question> in the link |
| Identify visitors only once your cookie banner allows it | setIdentificationConsent(granted) |
Good to know¶
- The public API is available on the top-level page where the Rose widget is installed.
- If you test inside a preview iframe, some values may be missing.
- For CRM and HubSpot ingestion, prefer
getIdentityContext()so you can sendlastActiveSessionIdandvisitorIdtogether.