The standard snippet loads the widget with the page, so tufu's servers receive the visitor's address and browser details on their first page. If your site asks for consent first, or you'd rather load nothing until someone wants the chat, paste one of the two snippets below in place of both standard ones (the script tag and the chat element). Each is the chat element and one line of script. Whether you need consent is a question for your own adviser: tufu doesn't decide it for you.
Load on click#
Only a plain button shows until the visitor clicks it. Nothing reaches tufu before that. The click loads the widget and opens the chat, in your bot's own look from then on.
<tufu-chat team="your-team" bot="your-bot" data-load="click" button-text="Chat with us"></tufu-chat>
<script>(function(){var e=!1,t=!1,n;function r(e){if(!t){t=!0;var r=document.createElement(`script`);r.type=`module`,r.src=`https://tufu.ai/widget/v1/tufu-chat.esm.js`,document.head.appendChild(r),e&&customElements.whenDefined(`tufu-chat`).then(function(){n.show()})}}function i(){var e=document.createElement(`button`);e.type=`button`,e.textContent=n.getAttribute(`button-text`)||`Chat`,e.setAttribute(`data-tufu-launcher`,``),e.style.cssText=`position:fixed;right:20px;bottom:20px;z-index:2147483000;padding:12px 18px;border:0;border-radius:999px;background:#111827;color:#fff;font:600 14px system-ui,sans-serif;cursor:pointer`,e.addEventListener(`click`,function(){e.remove(),r(!0)}),document.body.appendChild(e)}function a(){n=n||document.querySelector(`tufu-chat[data-load],tufu-chat[data-consent]`),n&&(n.getAttribute(`data-consent`)!==`wait`||e)&&(n.getAttribute(`data-load`)===`click`?!document.querySelector(`[data-tufu-launcher]`)&&!t&&i():r(!1))}window.tufu=window.tufu||{},window.tufu.consent=function(t){e=t!==!1,e&&a()},document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,a):a()})();</script>
Change the button's words with button-text. Your studio settings don't apply to it until the click.
Load after consent#
Nothing shows and nothing loads until your page calls tufu.consent(true). Call it on every page load where the visitor
has agreed. tufu.consent(false) does nothing further: to remove a loaded chat after consent is withdrawn, reload the page.
<tufu-chat team="your-team" bot="your-bot" data-consent="wait"></tufu-chat>
<script>(function(){var e=!1,t=!1,n;function r(e){if(!t){t=!0;var r=document.createElement(`script`);r.type=`module`,r.src=`https://tufu.ai/widget/v1/tufu-chat.esm.js`,document.head.appendChild(r),e&&customElements.whenDefined(`tufu-chat`).then(function(){n.show()})}}function i(){var e=document.createElement(`button`);e.type=`button`,e.textContent=n.getAttribute(`button-text`)||`Chat`,e.setAttribute(`data-tufu-launcher`,``),e.style.cssText=`position:fixed;right:20px;bottom:20px;z-index:2147483000;padding:12px 18px;border:0;border-radius:999px;background:#111827;color:#fff;font:600 14px system-ui,sans-serif;cursor:pointer`,e.addEventListener(`click`,function(){e.remove(),r(!0)}),document.body.appendChild(e)}function a(){n=n||document.querySelector(`tufu-chat[data-load],tufu-chat[data-consent]`),n&&(n.getAttribute(`data-consent`)!==`wait`||e)&&(n.getAttribute(`data-load`)===`click`?!document.querySelector(`[data-tufu-launcher]`)&&!t&&i():r(!1))}window.tufu=window.tufu||{},window.tufu.consent=function(t){e=t!==!1,e&&a()},document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,a):a()})();</script>
Put the snippet before your consent tool's script, so tufu.consent exists when the tool calls it. You can use both
together: data-consent="wait" data-load="click" shows the button only after consent.
Cookiebot#
<script>
window.addEventListener('CookiebotOnConsentReady', function () {
if (Cookiebot.consent.preferences) tufu.consent(true);
});
</script>
OneTrust#
Your category ids are in your OneTrust settings; C0003 (functional) is the usual default.
<script>
function OptanonWrapper() {
if (window.OnetrustActiveGroups && OnetrustActiveGroups.indexOf('C0003') !== -1) tufu.consent(true);
}
</script>
Google Consent Mode#
Consent Mode has no event of its own. Where your consent tool updates it, call tufu too:
gtag('consent', 'update', { functionality_storage: 'granted' });
tufu.consent(true);
Why the script is in your page#
A browser fetches a <script src> before anything on the page can read an attribute, so the loader has to live in your
own page: a src pointing at tufu would already be a request to tufu. The line is a short loader, minified, that adds
tufu's script only after the click or the consent. If your site has a Content Security Policy, the inline loader needs
your nonce, and your policy must allow tufu's script once the loader adds it.
What the chat keeps in the browser#
Before the chat opens, the widget stores no identifier. If your bot has a greeting bubble, the standard snippet keeps a small note that it has shown (and, if the visitor closes it, that it was closed), so it doesn't repeat on every page; with the snippets above, none of that runs before the click or the consent. Once the chat opens, it keeps a random visitor id in the chat's own frame, so a returning visitor's conversation carries on.