Compliant with GDPR, CCPA, COPPA, LGPD, PECR, PDPA, PIPEDA, and more.
This guide explains how to integrate the UniConsent CMP SDK into your React Native application for handling GDPR IAB TCF 2.3 consent management.
You can find a demo app integrated with this SDK in the UniConsentDemo directory provided alongside the SDK package.
uniconsent-react-native-sdk-26.2.0.zip), downloaded from your UniConsent dashboard or obtained from support.Download and unzip the SDK package (e.g., uniconsent-react-native-sdk-26.2.0.zip). Inside you will find:
uniconsent-react-native-sdk-26.2.0.tgz — npm-installable SDK packageuniconsent-sdk/ — Pre-built SDK library filesUniConsentDemo/ — Demo applicationREADME.md — DocumentationInstall the .tgz file using npm or Yarn:
# Replace <path-to-package-file.tgz> with the actual path to the file
npm install <path-to-package-file.tgz>
# or
yarn add <path-to-package-file.tgz>
Example: If you place the .tgz file in the root of your project:
npm install ./uniconsent-react-native-sdk-26.2.0.tgz
# or
yarn add file:./uniconsent-react-native-sdk-26.2.0.tgz
This SDK requires the following peer dependencies:
npm install react-native-webview react-native-default-preference
# or
yarn add react-native-webview react-native-default-preference
If developing for iOS, navigate to your project's ios directory and install the pods:
cd ios
pod install
cd ..
Before integrating the SDK, customize the consent banner appearance in the UniConsent Dashboard to match your brand and optimize consent rates.
Go to Projects → Select your Project → Settings → Step 5: UI & Style Settings to configure:
For more precise control, add custom CSS in the CSS Content field under Step 5. This is recommended to make the banner feel native to your app and achieve the best consent rate:
/* Example: Style the accept button to match your brand */
.unic-btn-accept {
background-color: #4CAF50;
border-radius: 8px;
font-weight: 600;
}
/* Example: Adjust banner font */
.unic-banner {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
/* Example: Make the reject button less prominent */
.unic-btn-reject {
background-color: transparent;
border: 1px solid #ccc;
color: #666;
}
Tip: A well-branded consent UI that feels native to your app typically achieves higher consent rates. Users are more likely to engage positively with a banner that matches the look and feel they expect.
Wrap your application's root component (or the relevant part) with UniConsentProvider. You must provide your licenseId (Publisher ID/pid from UniConsent).
// Your main App file (e.g., App.tsx or index.js)
import React from 'react';
import { UniConsentProvider } from 'uniconsent-sdk';
import YourAppRootComponent from './src/YourAppRootComponent';
const App = () => {
return (
<UniConsentProvider licenseId="YOUR_LICENSE_ID">
<YourAppRootComponent />
</UniConsentProvider>
);
};
export default App;
The SDK supports three display modes for the CMP UI, configured via the displayMode prop on UniConsentProvider:
| Mode | Description |
|---|---|
'fullScreen' | Full-screen page (default) |
'bottomSheet' | Modal sheet anchored to the bottom of the screen |
'dialog' | Centered modal dialog |
// Full screen (default — no prop needed)
<UniConsentProvider licenseId="YOUR_LICENSE_ID">
// Bottom sheet
<UniConsentProvider licenseId="YOUR_LICENSE_ID" displayMode="bottomSheet">
// Center dialog
<UniConsentProvider licenseId="YOUR_LICENSE_ID" displayMode="dialog">
Use the useConsent hook within a component inside the Provider to get the openCMP function, then call it when needed (e.g., from a button press).
import React from 'react';
import { View, Text, Button, ActivityIndicator } from 'react-native';
import { useConsent } from 'uniconsent-sdk';
const ConsentInfoComponent = () => {
const { consentStatus, isLoading, openCMP } = useConsent();
return (
<View>
<Text>Consent Status:</Text>
{isLoading ? (
<ActivityIndicator />
) : (
<Text>{consentStatus ?? 'Initializing...'}</Text>
)}
<Button
title="Manage Privacy Settings"
onPress={openCMP}
disabled={isLoading}
/>
</View>
);
};
Use the utility functions to check consent status directly without the hook:
import {
getTCString,
isEURegion,
isPurposeConsented,
isVendorConsented,
getConsentData,
} from 'uniconsent-sdk';
// Get the full TC String
const tcString = await getTCString();
// Check if user is in EU/EEA region
const inEU = await isEURegion();
// Check if a specific TCF purpose has consent (1-based ID)
const hasPurpose1 = await isPurposeConsented(1);
// Check if a specific vendor has consent (1-based ID)
const hasVendor755 = await isVendorConsented(755);
// Get all consent data as a single object
const consentData = await getConsentData();
The SDK provides helper functions for development and debugging:
import { listKV, clearKV } from 'uniconsent-sdk';
// Log all stored consent keys to console
await listKV();
// Clear all stored consent data
await clearKV();
UniConsentProvider Props| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
licenseId | string | Yes | — | Your UniConsent Publisher ID (pid). |
displayMode | CMPDisplayMode | No | 'fullScreen' | CMP display style: 'fullScreen', 'bottomSheet', or 'dialog'. |
| Export | Description |
|---|---|
UniConsentProvider | React component to wrap your application. Requires licenseId prop. |
useConsent() | Hook returning { consentStatus, isLoading, openCMP }. |
| Function | Returns | Description |
|---|---|---|
getTCString() | Promise<string> | Get the IAB TCF consent string. |
isEURegion() | Promise<boolean> | Check if the user is in an EU/EEA region. |
isPurposeConsented(purposeId) | Promise<boolean> | Check consent for a specific TCF purpose (1-based ID). |
isVendorConsented(vendorId) | Promise<boolean> | Check consent for a specific TCF vendor (1-based ID). |
getConsentData() | Promise<ConsentData> | Get a comprehensive consent data object. |
listKV() | Promise<void> | Debug: log all stored consent keys to console. |
clearKV() | Promise<void> | Debug: clear all stored consent data. |
| Type | Description |
|---|---|
CMPDisplayMode | 'fullScreen' | 'bottomSheet' | 'dialog' |
ConsentContextValue | Shape of the useConsent() return value. |
ConsentData | Shape of the getConsentData() return value. |
ConsentData Fields| Field | Type | Description |
|---|---|---|
tcString | string | Full IAB TCF consent string. |
isEURegion | boolean | Whether the user is in an EU/EEA region. |
gdprApplies | boolean | GDPR applies flag. |
cmpSdkId | number | Registered CMP SDK ID (68 for UniConsent). |
cmpSdkVersion | number | CMP SDK version. |
policyVersion | number | TCF policy version. |
purposeConsents | string | Binary string of consented purposes (e.g., "10110"). |
vendorConsents | string | Binary string of consented vendors. |
additionalConsent | string | Google Additional Consent (AC) string. |
gvlVersion | number | Global Vendor List version used. |
openCMP() function obtained from the useConsent hook.UniConsentProvider automatically checks consent status when your app starts, including whether the Global Vendor List (GVL) has been updated since the user last gave consent. If the GVL version has changed, the user will be re-prompted.