Consent
The Datafly mobile SDKs support category-based consent management. Set consent categories to control which types of data processing are permitted.
Setting consent
iOS (Swift)
Datafly.shared.setConsent(["analytics": true, "marketing": false, "functional": true])Android (Kotlin)
Datafly.setConsent(mapOf(
"analytics" to true,
"marketing" to false,
"functional" to true
))React Native
Datafly.setConsent({ analytics: true, marketing: false, functional: true });How it works
- Consent categories are stored locally (UserDefaults on iOS, SharedPreferences on Android)
- Consent state is restored automatically on SDK init
- The
consent.categoriesobject is attached to every event - The server-side event processor uses consent to gate which vendors receive the event
Reading consent
// iOS
let currentConsent = Datafly.shared.consent // [String: Bool]?
// Android
val currentConsent = Datafly.consent // Map<String, Boolean>?Category names
Category names are flexible — use whatever categories your consent implementation requires. Common categories:
| Category | Description |
|---|---|
analytics | Analytics and performance tracking |
marketing | Marketing and advertising |
functional | Functional features (e.g., chat widgets) |
personalization | Content personalisation |
essential | Strictly necessary processing |
How categories map to vendor gating
Your category names are sent verbatim as consent.categories, and the SDK also
sends a normalised consent.canonical alongside them. Server-side vendor gating
reads the canonical form, so a CMP that names its categories differently still
gates correctly. These aliases are recognised:
| Canonical | Recognised aliases |
|---|---|
essential | necessary, strictly_necessary, security_storage |
functional | functionality, preferences, functionality_storage, preferences_storage |
analytics | analytics_storage, statistics, performance, measurement |
marketing | ad_storage, ad_user_data, advertising, targeting, advertisement |
personalization | personalisation, ad_personalization, personalization_storage |
Matching is case-insensitive and treats - and _ alike. A category name
outside this list is still delivered in consent.categories, but it will not
drive vendor gating on its own — use one of the canonical names or a
recognised alias for anything you need gated.
iOS App Tracking Transparency
On iOS, if you need to track users across apps (IDFA), you must request ATT permission. This is separate from the consent categories:
import AppTrackingTransparency
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
// User granted tracking permission
Datafly.shared.setConsent(["analytics": true, "marketing": true])
let idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidString
Datafly.shared.setAdvertisingId(idfa, enabled: true)
case .denied, .restricted:
Datafly.shared.setConsent(["analytics": true, "marketing": false])
default:
break
}
}The Datafly SDK continues to collect events regardless of consent state. Consent categories are attached to each event and enforced server-side during pipeline processing. This means you can update consent retroactively without losing events.
Consent on reset
Calling reset() does not clear consent state. Consent is considered a user preference that persists across sessions, not part of the user identity.