What the widget stores before a visitor opens it, and how to connect it to Cookiebot, Usercentrics, Borlabs Cookie or your own banner.
By default the chat widget stores nothing in the visitor's browser and starts no session until the visitor opens the chat. Opening the chat is an explicit request by the visitor, so in most setups you don't need a cookie banner entry for asktrix at all.
If you want the chat running before that, for example for proactive messages, connect the widget to your cookie banner as described below.
What happens by default
The setting Start session only when widget is opened is on by default. Until the visitor clicks the chat button, the widget:
- doesn't create a visitor session,
- doesn't write anything to the browser's local storage,
- doesn't open the live connection to asktrix.
The button itself is shown: the browser loads the widget's script and settings, like any other script on your page.
Once the visitor opens the chat, a session starts and the widget stores a token in local storage. That's needed for the conversation the visitor asked for: on the next pages the widget reconnects with it, so your replies still arrive.
The trade-off: until the visitor opens the chat, your team can't see them in the visitor list, proactive messages and chat campaigns aren't shown, and there's no unread badge on the button.
On the Team plan and up you can change the setting under Settings → Channels → Identity & protection → Domains & sessions. On Free and Start it always stays on. The consent API below works on every plan.
Start the chat after cookie consent
To get the full feature set for visitors who agree to cookies, tell the widget when consent is given:
asktrix.consent(true);
// or
asktrix("consent", true);
The widget then starts its session right away, without waiting for the visitor to open the chat.
When there's no consent, or the visitor withdraws it:
asktrix.consent(false);
// or
asktrix("consent", false);
The widget then starts no session by itself. If it's connected and the chat isn't open right now, the connection is closed. The visitor can still open the chat themselves, because that's an explicit request. A conversation the visitor started is kept on their device.
The decision only applies to the current page. Report the visitor's choice on every page load. Cookie banners do that anyway: they fire their event on every page.
Calling it before the widget has loaded
window.asktrix only exists after the widget has loaded. Your banner may report consent earlier. Use the ready queue, which works before and after loading:
window.asktrixReady = window.asktrixReady || [];
asktrixReady.push(function (trix) {
trix.consent(true);
});
Callbacks in the queue run before the widget starts on its own. A decision your banner knows at page load therefore takes effect before anything connects.
The examples below use this small helper. Put it once on every page, before the code for your banner:
<script>
var asktrixGranted = null;
function asktrixConsent(granted) {
if (granted === asktrixGranted) return; // banners often fire several events in a row
asktrixGranted = granted;
window.asktrixReady = window.asktrixReady || [];
window.asktrixReady.push(function (trix) {
trix.consent(granted);
});
}
</script>
Without consent this calls consent(false) on every page. A visitor who opened the chat without agreeing to cookies then reconnects when they open the chat again on the next page, not automatically.
Cookiebot
Cookiebot fires CookiebotOnAccept and CookiebotOnDecline on page load and whenever the visitor changes their choice. Pick the category that matches where you've put asktrix in your Cookiebot setup. A chat is usually a preferences (functional) cookie; if you've classified it as statistics, use Cookiebot.consent.statistics instead.
<script>
window.addEventListener("CookiebotOnAccept", function () {
asktrixConsent(!!(window.Cookiebot && Cookiebot.consent.preferences));
});
window.addEventListener("CookiebotOnDecline", function () {
asktrixConsent(false);
});
</script>
Usercentrics
- In the Usercentrics admin interface, add a custom service named
asktrix and put it in a category, for example functional.
- Under Implementation → Data Layer & Events, add a window event named
ucEvent, if it isn't there yet.
- Add this script:
<script>
window.addEventListener("ucEvent", function (e) {
if (e.detail && e.detail.event === "consent_status") {
asktrixConsent(e.detail["asktrix"] === true);
}
});
</script>
The key in e.detail is the service name, so it has to be exactly asktrix. This works with the Usercentrics CMP v2 and v3.
Borlabs Cookie
In Borlabs Cookie 3, create a service with the ID asktrix in a fitting service group. Then use one of these two ways.
Opt-in code. Paste this into the service's opt-in code field. Borlabs runs it once the visitor agrees:
<script>window.asktrixReady=window.asktrixReady||[];asktrixReady.push(function(t){t.consent(true)})</script>
If your Borlabs version has an opt-out code field, paste the same line with t.consent(false) there.
The opt-in code only runs when there is consent. It's the quickest way, but on pages without consent the widget isn't told anything. If a visitor once agreed and later withdraws, the widget can still reconnect on later pages with the session it already has. To avoid that, use the script instead.
Script on your site. This reports the choice on every page:
<script>
function asktrixBorlabsCheck() {
var b = window.BorlabsCookie;
asktrixConsent(!!(b && b.Consents && b.Consents.hasConsent("asktrix")));
}
document.addEventListener("borlabs-cookie-consent-saved", asktrixBorlabsCheck);
if (window.BorlabsCookie && window.BorlabsCookie.Consents) asktrixBorlabsCheck();
else window.addEventListener("load", asktrixBorlabsCheck);
</script>
Other banners
Any banner works the same way: call asktrixConsent(true) when the visitor agrees and asktrixConsent(false) when they withdraw. Most banners offer a JavaScript callback or event for this. Look for "callback", "event" or "consent API" in their documentation.
Privacy policy link
Under Settings → Channels → Behavior, in the Privacy & live features card, enter the URL of your privacy policy as Privacy policy link. The widget shows the link when it asks a visitor for their email address and in the footer of the chat window.
Describe asktrix in your privacy policy as a processor for the live chat, and mention which data the chat stores (messages, email address if given, browser and page information).
AI answers are labeled
Every message written by Trix carries an AI badge next to the name in the widget (KI in German). Visitors always know when they're talking to an AI and not to your team. You can't turn the badge off.