Asking for consent (optional)
By default datacub tracks from the first page view. There is no banner to wire and no call to make. If you want to wait for your visitors' consent first, you can turn that on.
Whether you need consent depends on your site and your users. Turn this on if you collect consent.
Turn it on
- In your project, open Settings and turn on Ask for consent first.
- Add
requireConsent: truetodatacub.init. On the script tag, add thedata-require-consentattribute instead. - Call
datacub.consent.grant()when the visitor agrees, anddatacub.consent.revoke()when they withdraw.
datacub.init('pk_live_YOUR_PROJECT_KEY', { requireConsent: true })
// the visitor accepted analytics
datacub.consent.grant({ method: 'banner', policyVersion: '2026-10' })
// the visitor withdrew it later
datacub.consent.revoke()With the script tag:
<script src="https://ingest.datacub.example/v1/sdk/datacub-0.4.0.min.js" data-key="pk_live_YOUR_PROJECT_KEY" data-require-consent defer></script>The install snippet in your project settings adds these lines for you when the setting is on.
Before the visitor agrees
| Call | What happens |
|---|---|
before grant() | no cookies, no storage, no network requests. Events tracked now are not kept. The datacub server also refuses any event that does not carry a grant |
datacub.consent.grant(options?) | the SDK writes its cookie, records a $consent event and the current page view, and starts sending |
datacub.consent.revoke() | stops sending, deletes the SDK's cookies and the queue. Nothing tracked before the revoke is sent later |
grant options, all optional:
| Option | Values |
|---|---|
method | where the visitor agreed: banner, settings, api or cmp (a consent management platform) |
policyVersion | the version of your privacy notice they agreed to, up to 64 characters |
overrideGPC | see Global Privacy Control |
The web SDK does not remember a grant between page loads. Your banner or consent platform already stores the visitor's answer: call grant() on each page load while it says yes. The mobile SDK keeps the grant in its storage, but call grant() at every launch after the user has agreed anyway, so the SDK follows your app's own record.
identify before grant() is kept in memory and applied at the grant.
With a consent platform
Call grant and revoke from your platform's callbacks. If the platform loads before the SDK file, use the queue snippet; calls wait in order. Add a consent stub to it so early calls are kept:
<script>
window.datacub = window.datacub || []
datacub.consent = datacub.consent || {
grant: function () { datacub.push(['consent.grant'].concat([].slice.call(arguments))) },
revoke: function () { datacub.push(['consent.revoke']) },
}
</script>datacub.init('pk_live_YOUR_PROJECT_KEY', { requireConsent: true })
onAnalyticsConsent(() => datacub.consent.grant({ method: 'cmp' }))
onAnalyticsConsentWithdrawn(() => datacub.consent.revoke())In React Native, pass the same option:
import AsyncStorage from '@react-native-async-storage/async-storage'
import datacub from '@datacub/react-native'
datacub.init('pk_live_YOUR_PROJECT_KEY', { storage: AsyncStorage, requireConsent: true })
// once the user has agreed: your app keeps their answer; call it at every launch
if (await hasAnalyticsConsent()) datacub.consent.grant()Opting out, in every project
This part applies whether or not you ask for consent first.
datacub.consent.revoke()always works, and datacub remembers it on that device. On the web it sets a first-party cookie,datacub_optout=1, for 400 days. It contains no identifier. On mobile it is a flag in the SDK's stored value.- When the SDK starts, a stored opt-out means nothing is sent.
- An explicit
datacub.consent.grant()clears the opt-out.
For example, a "stop tracking me" button in your privacy settings:
datacub.init('pk_live_YOUR_PROJECT_KEY')
function onStopTrackingClick() {
datacub.consent.revoke()
}Global Privacy Control
If the browser sends Global Privacy Control (GPC), datacub treats it as an opt-out: when the SDK starts, nothing is sent, and grant() does nothing. Only when the visitor explicitly opts in on your site, for example in your privacy settings, pass overrideGPC: true:
// only from the visitor's own click on an opt-in control
function onAnalyticsToggleOn() {
datacub.consent.grant({ method: 'settings', overrideGPC: true })
}What datacub never collects
This holds in every project, with or without consent first.
- field values or URL fragments (button and link text, page titles and URL query values are collected, scrubbed, and you can turn each off in Settings, Data capture)
- passwords, OTPs, card data, IBANs, national or Iqama IDs, tokens: dropped or redacted on the device and again on the server
- raw IP addresses: used in memory for the country and city and for rate limits, then dropped, never stored
- device fingerprints or advertising IDs
Where data is stored and how long it is kept is in datacub's privacy notice.
Your part
You choose whether to ask for consent and what basis applies to your users. datacub gives you the switch; it does not decide for you. Keep properties free of personal data, use your own internal ID for identify, and call reset() at logout. When someone asks for their data to be deleted, see deleting a person's data.