Consent and privacy
Send your consent banner's choices with every event, and control what the SDK keeps in the browser
On this page
Record consent#
Call setConsent when your consent banner resolves and whenever the visitor changes their choice. The categories are attached to every later event as context.consent, so each destination can respect them.
sfere.setConsent({ analytics: true, advertising: false });Category names are yours to choose. Use the same names your consent tool uses, such as analytics, advertising or functional.
Set consent when the SDK loads#
With the npm package, pass the stored choice to load() so the first page view already carries it:
const sfere = SfereAnalytics.load({
writeKey: "YOUR_WRITE_KEY",
host: "https://events.sfere.io",
consent: {
analytics: localStorage.getItem("consent_analytics") === "true",
advertising: localStorage.getItem("consent_advertising") === "true",
},
});With the script-tag loader, call sfere.setConsent(...) from your consent tool’s callback. Calls made before the SDK finishes loading are queued in order.
Connect a consent tool#
If you manage tags in Google Tag Manager, fire a Custom HTML tag that calls window.sfere.setConsent(...) on your consent tool’s update event.
// Example: a consent tool that exposes a callback when choices change
function onConsentChanged(consentTool) {
sfere.setConsent({
analytics: consentTool.getConsentFor("analytics"),
advertising: consentTool.getConsentFor("advertising"),
});
}What the SDK stores in the browser#
| Storage | What | Why |
|---|---|---|
Local storage sfere_session |
Session ID and last activity time | Groups events into sessions |
Session storage sfere_click_ids |
Ad click IDs from the landing URL | Attributes later conversions to the ad click |
Cookies and local storage ajs_* |
Anonymous ID, user ID and traits | Recognizes the visitor across pages |
If the browser blocks storage, the SDK keeps everything in memory for the current page and still sends events. To force that mode, load the npm package with disableClientPersistence: true.
Personal data#
Send email and phone as plain values in identify. Sfere hashes them for each destination that needs hashed identifiers, so never hash them yourself. To stop sending a signed-in customer’s details on a shared device, call sfere.reset() when they sign out.