Consent banners
Many teams ask before recording sessions. Consent mode makes Specto wait for the answer from your banner — nothing is recorded or stored in the browser until the visitor agrees.
How consent mode works
Add data-consent="required" to the script tag (or consent: 'required' with the npm package). Until consent:
• no session starts, nothing is uploaded and nothing is written to storage;
• Specto.consent(true) starts recording and remembers the answer (localStorage), so later page loads record without asking again;
• Specto.consent(false) stops recording and forgets the answer.
Call it whenever your banner knows the visitor's choice — on page load and when they change their mind. Specto counts as analytics (Cookiebot's "statistics", OneTrust's "performance").
Cookiebot
<script src="https://specto.sh/specto.js" data-key="pk_your_key" data-consent="required" defer></script> <script> // Specto follows Cookiebot's "statistics" category function spectoConsent() { if (window.Specto && window.Cookiebot && window.Cookiebot.consent) Specto.consent(Cookiebot.consent.statistics) } window.addEventListener('CookiebotOnConsentReady', spectoConsent) window.addEventListener('CookiebotOnAccept', spectoConsent) window.addEventListener('CookiebotOnDecline', spectoConsent) // Cookiebot may answer before Specto has loaded window.addEventListener('DOMContentLoaded', spectoConsent) </script>
OneTrust
OneTrust calls OptanonWrapper() when the banner loads and whenever consent changes, with the accepted categories in OnetrustActiveGroups. C0002 is OneTrust's default Performance category — use the id your banner gives to analytics. If you already define OptanonWrapper, add the Specto line to it.
<script src="https://specto.sh/specto.js" data-key="pk_your_key" data-consent="required" defer></script> <script> function OptanonWrapper() { if (window.Specto) Specto.consent(String(window.OnetrustActiveGroups || '').indexOf(',C0002,') !== -1) } // OneTrust may answer before Specto has loaded window.addEventListener('DOMContentLoaded', function () { if (window.OnetrustActiveGroups) OptanonWrapper() }) </script>
Any other consent manager
Whatever exposes the visitor's analytics decision — Google Consent Mode's analytics_storage, an IAB TCF purpose, your own banner — call Specto.consent(granted) with it when it is known and when it changes. Repeated calls are fine: if Specto is already recording, it keeps the same session.
With the npm package
import { startRecording, grantConsent, revokeConsent } from '@spectosh/browser' startRecording({ key: 'pk_your_key', consent: 'required' }) // from your banner's callbacks: onAnalyticsConsent((granted) => (granted ? grantConsent() : revokeConsent()))
An opt-out link
Independent of any banner, visitors can turn recording off for good — useful in a privacy policy:
<a href="#" onclick="Specto.optOut(); this.textContent = 'Session recording is off'; return false">Don't record my sessions</a>
Specto.optIn() undoes it. Visitors with Do-Not-Track or Global Privacy Control turned on are never recorded, banner or not. See the SDK reference for every call.
A note on the law
Whether you need consent depends on where your visitors are and what you do with recordings — ask your counsel. Specto masks inputs and scrubs personal data in the visitor's browser either way (privacy controls).

