Consent

The Datafly mobile SDKs support category-based consent management. Set consent categories to control which types of data processing are permitted.

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

  1. Consent categories are stored locally (UserDefaults on iOS, SharedPreferences on Android)
  2. Consent state is restored automatically on SDK init
  3. The consent.categories object is attached to every event
  4. The server-side event processor uses consent to gate which vendors receive the event
// 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:

CategoryDescription
analyticsAnalytics and performance tracking
marketingMarketing and advertising
functionalFunctional features (e.g., chat widgets)
personalizationContent personalisation
essentialStrictly 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:

CanonicalRecognised aliases
essentialnecessary, strictly_necessary, security_storage
functionalfunctionality, preferences, functionality_storage, preferences_storage
analyticsanalytics_storage, statistics, performance, measurement
marketingad_storage, ad_user_data, advertising, targeting, advertisement
personalizationpersonalisation, 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.

Calling reset() does not clear consent state. Consent is considered a user preference that persists across sessions, not part of the user identity.