---
title: "Mobile apps (preview)"
description: "Fetch your published banner configuration in a native app and record consent from the mobile SDKs."
url: "https://cookiebeam.com/docs/install/mobile"
lang: "en"
last_updated: "2026-11-16"
---

# Mobile apps (preview)

Fetch your published banner configuration in a native app and record consent from the mobile SDKs.

The native mobile SDKs are in preview. This page describes the server contract every SDK uses, so you can also build against it directly.

## Status

| Package | Version | Published to a package registry |
| ------- | ------- | ------------------------------- |
| Android (`com.cookiebeam:consent`) | `0.2.0-rc.1`, release candidate | No, not yet on Maven Central |
| iOS (Swift package `CookieBeam`) | `0.2.0-rc.1`, preview | No |
| React Native (`@cookiebeam/react-native-consent`) | `0.1.0`, preview | No, not yet on npm |
| Flutter (`cookiebeam_consent`) | `0.1.0`, preview | No, not yet on pub.dev |

What this means for you today:

- The HTTP contract on this page (fetching the configuration and recording consent) is the stable part. You can build your own consent screen against it now.
- Preview SDK APIs can still change before their first published release.
- Fetching the configuration needs no API key and works on every plan. Recording consent from an app uses the API, which needs an API key and a plan that includes API access (Professional and above). See [Manage API keys](https://cookiebeam.com/docs/account/api-keys).

A native app uses the same banner as your website: the same categories, texts, regional rules and consent revision. Publish the banner (or an environment) in the dashboard first; apps only ever receive published configuration, never drafts.

## Fetch the configuration

```text
GET /api/v1/mobile/config?bannerId=PUBLIC_BANNER_ID&env=production&lang=de
```

| Parameter | Required | Notes |
| --------- | -------- | ----- |
| `bannerId` | Yes | The **public** Banner ID, the one in the loader script URL |
| `env` | No | Environment slug; defaults to `production`. Other environments return their own published version |
| `lang` | No | Preferred language tag such as `de` or `pt-BR`. Without it the `Accept-Language` header is used |

No API key is needed: the response contains only what the published banner script already makes public. The endpoint is rate limited per client IP like the CDN routes.

The visitor's region is taken from the request's edge geo headers, exactly as for the website, and the response carries the resolved regional outcome. Because of that the response is marked `private`: it may be cached by the app, never by a shared proxy. Send the `ETag` back in `If-None-Match` to get `304 Not Modified` when nothing changed.

An unknown banner, an inactive banner, an unknown environment and a banner or environment that has never been published all return the same `404` with the code `not_found`. A malformed query returns `400` with the code `invalid_request`.

### Response

The body is a versioned JSON document. `schemaVersion` is `1`; new fields can be added without changing it, and a breaking change would ship as a new schema version alongside a new SDK major version.

| Field | Contents |
| ----- | -------- |
| `banner.publicId`, `banner.id` | Public Banner ID, and the internal ID that `POST /api/v1/consent/log` expects as `bannerId` |
| `environment` | The environment slug and whether it is production |
| `version` | Published version number, `publishedAt`, a `configHash` of the consent-relevant settings, and `consentRevision` |
| `consent.expiresAfterDays` | The banner's consent lifetime |
| `language` | The requested tag, the `resolved` language of the texts, the banner default and every `available` language |
| `texts` | Banner and preferences screen copy: title, description, accept, reject, preferences, save and close labels |
| `categories` | Per category: `id`, `required`, `defaultEnabled`, `name`, `description` and the Google Consent Mode v2 keys it grants |
| `consentMode` | Whether Consent Mode v2 is enabled and the region-aware `defaults` to apply before anything else |
| `regional` | Country and region, matched rule and framework, `consentModel` (`opt-in`, `opt-out` or `notice`), `showBanner`, the categories in effect before a choice (`defaultGrantedCategories`), a regional consent lifetime and US privacy flags |
| `links` | Privacy and cookie policy URLs |

Language resolution follows the website: the banner's own default and customized translations come first, then the platform translation for the requested language, then the banner's default language, then English. Descriptions can contain the same limited HTML (links, bold, italics, line breaks) as on the website.

### When to ask again

Store the choice on the device together with `version.consentRevision`, the `regional.ruleId` it was made under and its timestamp. Show the banner again when there is no stored choice, when `consentRevision` changed (the same rule the website applies to its consent cookie), when the matched regional rule changed, or when the choice is older than `regional.consentExpiryDays` (or `consent.expiresAfterDays` when the region sets none). When `regional.showBanner` is `false`, store `defaultGrantedCategories` without asking.

## Record consent

Post each explicit choice to the versioned consent log with an API key that has the `consent:write` scope. See [Authentication](https://cookiebeam.com/docs/api-reference/authentication).

> A key compiled into an app can be extracted from it. Create a dedicated key with only the `consent:write` scope for the app so it can be revoked on its own, or relay consent records through your own backend and keep the key there.

```http
POST /api/v1/consent/log
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

{
  "bannerId": "INTERNAL_BANNER_ID_FROM_banner.id",
  "consentChoices": { "necessary": true, "analytics": true, "marketing": false },
  "language": "de",
  "timestamp": "2025-01-15T10:00:00.000Z",
  "platform": "android",
  "sdkVersion": "0.2.0-rc.1",
  "consentId": "7d9f3c1e-2b4a-4c8d-9e0f-112233445566",
  "method": "consent_given",
  "collectionMethod": "preferences"
}
```

`platform` is one of `web`, `ios`, `android`, `react-native` or `flutter`, and `sdkVersion` is a short version string. Both are optional and stored with the record, so consent analytics can be split by platform. Records written without them keep a null platform.

### Consent sync fields

Apps can send more about each choice. Every field is optional, and a request without them behaves as before.

| Field | Contents |
| ----- | -------- |
| `consentId` | A random ID the app generates once per device and banner, 8 to 64 letters, digits, `-` or `_`. It is stored with the consent record as a stable device-level reference for the app's consent history. Never derive it from a device or advertising identifier |
| `method` | `accept_all`, `accept_necessary`, `consent_given` (first custom choice) or `consent_changed` |
| `collectionMethod` | `banner`, `preferences` or `api` |
| `receipt` | `true` to get a signed consent receipt in the response |
| `receiptAudience` | The `https://` origin of one of the banner's domains to bind the receipt to. Without it the primary domain is used. Any other origin is refused with `400` and nothing is stored |

When a receipt is requested, the `201` response carries `data.receipt`. It is either `{ "status": "issued", "token", "payload", "verificationKeys" }` or `{ "status": "unavailable", "reason" }`, where the reason is `no_audience` (the banner has no domain) or `signing_unavailable`. The record is stored either way. A receipt is a signed JWS (`cb-consent-receipt+jws`, receipt version 6). Website receipts are version 4, which adds an evidence level. Anyone can check it with `POST /api/consent/receipt/verify` and its audience, or offline with the keys at `/.well-known/cookiebeam-jwks.json`. When the team's monthly consent log limit is reached, the response is `200` with `stored: false` and no receipt.

### Published contract

The JSON Schemas for the configuration and the consent log are published in the repository under `sdks/contract/`. They are generated from the server's own validation schemas, so they cannot drift from it. Shared fixtures and conformance cases sit next to them, and every SDK's tests run these cases.

## Android

The Android SDK is a release candidate and not yet published to Maven Central. It has three artifacts:

| Artifact | Contents |
| -------- | -------- |
| `com.cookiebeam:consent-core` | Pure Kotlin. Fetches and caches the configuration, decides when to ask, stores the choice, syncs it to the consent log with `platform: "android"` (with optional receipts) and maps it to Consent Mode v2 |
| `com.cookiebeam:consent` | The Android library. A banner and preferences screen built from framework Views with no AndroidX, Material or Compose dependency, `SharedPreferences` storage, and a facade that runs network calls in the background and calls you back on the main thread |
| `com.cookiebeam:consent-firebase` | Applies the Consent Mode v2 state with `FirebaseAnalytics.setConsent` |

```kotlin
// Application.onCreate
CookieBeam.initialize(
    context = this,
    options = CookieBeamOptions(publicBannerId = "PUBLIC_BANNER_ID"),
    apiKey = BuildConfig.COOKIEBEAM_CONSENT_KEY, // consent:write only, or null
)
CookieBeamFirebase.install(CookieBeam.consent, Firebase.analytics)

// First Activity.onCreate: shows the banner only when consent is needed
CookieBeam.showBannerIfNeeded(this)

// Privacy settings screen
CookieBeam.showPreferences(this)
```

The banner shows "Accept all" and "Reject all" with the same style and size. It cannot be dismissed without a choice. Texts, categories and regional behaviour come from the published configuration, so you change them in the dashboard, not in the app. Until the configuration has loaded, and whenever it cannot load, only required categories are in effect. To use your own UI, call `CookieBeam.acceptAll()`, `rejectAll()` or `save(choices)`, and build the screens from `ConsentUi.banner(config)` and `ConsentUi.preferences(config, stored)`.

Set the Firebase Analytics defaults to denied in your `AndroidManifest.xml`, so nothing is collected before the SDK applies the region's state:

```xml
<meta-data android:name="google_analytics_default_allow_analytics_storage" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_storage" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_user_data" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="false" />
```

The full API reference, storage notes and a sample app are in `sdks/android/` in the repository. The React Native and Flutter packages below, and the iOS SDK, follow the same contract.

## React Native

The React Native package (`@cookiebeam/react-native-consent`) is in preview and not yet published to npm. It is written in TypeScript and needs no native module. It implements the same contract and decision rules as the Android library. Choices are stored in AsyncStorage by default, or in any storage you pass. They are posted with `platform: "react-native"` and the consent sync fields above, with optional receipts. The package includes a `useConsent()` hook, a minimal two-layer `<ConsentBanner />` and `applyFirebaseConsent()` for `@react-native-firebase/analytics`.

```tsx
const consent = CookieBeamConsent.create({ publicBannerId: 'PUBLIC_BANNER_ID', apiKey: CONSENT_WRITE_KEY });
consent.subscribe((effective) => applyFirebaseConsent(analytics(), effective.consentMode));

<CookieBeamProvider consent={consent}>
  <App />
  <ConsentBanner />
</CookieBeamProvider>
```

## Flutter

The Flutter package (`cookiebeam_consent`) is in preview and not yet published to pub.dev. It has the same API as the React Native package. Choices are stored in `shared_preferences` by default and posted with `platform: "flutter"` and the consent sync fields above, with optional receipts. The package includes a `ConsentBanner` widget and `applyFirebaseConsent()`, which takes `FirebaseAnalytics.instance.setConsent` directly.

```dart
final consent = CookieBeamConsent.create(
  const CookieBeamOptions(publicBannerId: 'PUBLIC_BANNER_ID'),
  apiKey: consentWriteKey,
);
consent.addListener((e) => applyFirebaseConsent(FirebaseAnalytics.instance.setConsent, e.consentMode));
await consent.refresh();

// In the widget tree:
ConsentBanner(consent: consent)
```

## iOS

The iOS library (Swift package `CookieBeam`, preview, not yet published) implements the same contract with the same rules as the Android library: it fetches and caches the configuration, decides when to ask, stores the choice in the Keychain, posts it with `platform: "ios"` and the consent sync fields above (with optional receipts) and maps it to Consent Mode v2 for Firebase Analytics. It supports iOS 15 and later and has no third-party dependencies. An optional SwiftUI consent sheet renders the banner texts and categories; you can also build your own screen.

```swift
let consent = CookieBeamConsent.create(
    options: CookieBeamOptions(publicBannerId: "PUBLIC_BANNER_ID"),
    apiKey: consentWriteKey
)
consent.addListener { effective in applyConsent(effective) }

if try await consent.refresh().decision.needsBanner { showConsent = true }

// From your consent screen:
try await consent.acceptAll()   // or rejectAll(), save(["analytics": true])
```

Show the consent screen before Apple's App Tracking Transparency prompt, and ask for tracking permission only when the user granted a category that needs it. The library does not read the advertising identifier and does not track. It ships a privacy manifest (`PrivacyInfo.xcprivacy`); your app's App Store privacy answers still need to cover the consent records it sends.
