Mobile App Consent Management
Mobile App Consent Management is in beta for select customers and prospects. Please contact your Account Manager or support@datagrail.io for more information.
DataGrail provides native SDKs for iOS and Android that enable seamless consent management in your mobile applications. These SDKs offer fully native UI components, offline support, and automatic synchronization with the DataGrail backend.
The DataGrail Consent mobile SDKs allow your app to:
- Display native consent banners that match your app's look and feel
- Collect and store user preferences with automatic persistence
- Sync consent choices with the DataGrail backend
- Check consent status before initializing tracking SDKs
- Work offline with automatic retry when connectivity returns
- iOS SDK Guide — Swift Package Manager, CocoaPods, native UIKit implementation
- Android SDK Guide — Gradle integration, Kotlin-first, Material Design components
Getting Started
Setting up the mobile SDK requires a published configuration from the DataGrail console and platform-specific installation steps.
Create Your Configuration
Before integrating the SDK, set up your consent configuration in the DataGrail console:
- Navigate to Consent → Configurations
- Create or select a configuration for mobile
- Define your consent categories (e.g., Analytics, Marketing, Functional)
- Customize banner text and appearance
- Publish your configuration
After publishing, you'll receive a configuration URL in this format:
https://api.consent.datagrail.io/config/YOUR_CONFIG_ID.json
Install the SDK
Choose your platform and follow the installation guide:
| Platform | Minimum Version | Installation Methods |
|---|---|---|
| iOS | iOS 13.0+ | Swift Package Manager, CocoaPods |
| Android | API 21+ | Gradle |
Initialize and Display
Both SDKs follow a similar pattern:
- Initialize
- Check if consent needed
- Show banner
- Handle preferences
See the platform-specific guides for complete code examples.
Configuration
Your configuration defines how the SDK behaves, what categories are available, and how the banner appears to users.
Config.json Structure
Your published configuration controls the SDK behavior:
{
"showBanner": true,
"categories": [
{
"key": "category_essential",
"name": "Essential Cookies",
"description": "Required for the app to function",
"required": true,
"defaultEnabled": true
},
{
"key": "category_analytics",
"name": "Analytics",
"description": "Help us understand how you use the app",
"required": false,
"defaultEnabled": false
},
{
"key": "category_marketing",
"name": "Marketing",
"description": "Personalized ads and content",
"required": false,
"defaultEnabled": false
}
],
"banner": {
"title": "Privacy Preferences",
"description": "We use cookies and similar technologies...",
"acceptAllText": "Accept All",
"rejectAllText": "Reject All",
"savePreferencesText": "Save Preferences"
}
}
Category Keys
Use consistent category keys across platforms to ensure preferences sync correctly:
| Key | Purpose | Typical SDKs |
|---|---|---|
category_essential | App functionality | — |
category_analytics | Usage analytics | Firebase, Mixpanel, Amplitude |
category_marketing | Advertising | Facebook, Google Ads, AppsFlyer |
category_functional | Enhanced features | Intercom, Zendesk |
API Overview
Both SDKs provide equivalent APIs with platform-appropriate naming conventions:
| Operation | iOS (Swift) | Android (Kotlin) |
|---|---|---|
| Initialize | DataGrailConsent.shared.initialize(configURL:) | DataGrailConsent.getInstance().initialize(context, url) |
| Check consent needed | needsConsent() | needsConsent() |
| Show banner | showBanner(from:style:) | showBanner(activity, style) |
| Get preferences | getPreferences() | getPreferences() |
| Check category | isCategoryEnabled(_:) | isCategoryEnabled(key) |
| Accept all | acceptAll() | acceptAll() |
| Reject all | rejectAll() | rejectAll() |
| Listen for changes | onConsentChanged(_:) | onConsentChanged { } |
| Reset | reset() | reset() |
Integration Best Practices
Follow these recommendations to ensure your consent implementation works reliably and provides the best user experience.
Initialize Early
Initialize the SDK as early as possible in your app's lifecycle:
- iOS: In
application(_:didFinishLaunchingWithOptions:)or your SwiftUIAppinit - Android: In your
Application.onCreate()
Gate Tracking SDKs
Always check consent before initializing tracking:
// Pseudo-code pattern
if (consent.isCategoryEnabled("category_analytics")) {
initializeAnalytics()
}
if (consent.isCategoryEnabled("category_marketing")) {
initializeAds()
}
Handle Consent Changes
Register for consent change notifications to update tracking state:
consent.onConsentChanged { preferences ->
updateTrackingConfiguration(preferences)
}
Provide Settings Access
Give users a way to update their preferences from your app's settings screen. Both SDKs allow showing the banner at any time, regardless of needsConsent() status.
Offline Behavior
Both SDKs handle network failures gracefully:
- Preferences save locally first — Users never wait for network calls
- Backend sync happens asynchronously — Failed syncs are queued
- Automatic retry with exponential backoff — Up to 5 attempts
- Manual retry available —
retryPendingRequests()method
Accessibility
The SDKs provide full accessibility support:
- iOS: VoiceOver support with proper trait annotations
- Android: TalkBack support with content descriptions
- Both: Proper focus management and state announcements
Legacy WebView Implementation
The native SDKs described above are the recommended approach for new integrations. The WebView approach below is provided for reference but offers a less native user experience.
You can also implement consent using a web view that loads the DataGrail Consent banner. This approach embeds the web-based banner into your mobile app.
Legacy WebView Implementation
Configure Embedded Container
- Create an Embedded Container
- Customize and configure your banner layouts by policy
- Publish your changes to the container
- Retrieve the JavaScript code for embedding
Mobile Layer
For each layout, you can create a third unlinked layer called Mobile View that will be triggered by a mobile device.
Android WebView Reference Implementation
Download Android Reference Code
iOS WebView Reference Implementation
Disclaimer: The information contained in this message does not constitute as legal advice. We would advise seeking professional counsel before acting on or interpreting any material.