@privasapien/react-native-consent-sdk
v1.0.5
Published
React Native bridge for the Privasapien Consent SDK — delegates all consent UI to native Android and iOS SDKs.
Maintainers
Readme
Why Privasapien Consent SDK?
Most apps handle consent with hardcoded dialogs or fragile WebViews. When regulations change or your legal team updates the privacy policy, you're stuck pushing an app update.
Privasapien Consent SDK solves this with a backend-driven approach — your consent UI, text, and logic are all controlled from the server. No app updates needed.
Features
- Native Performance — all UI is rendered natively (Jetpack Compose / SwiftUI) rather than the React Native bridge.
- Backend-driven consent UI — colors, text, layout, and purposes all configured remotely.
- GDPR & DPDP compliant — built for global privacy regulations.
- Persistent consent state — dual-layer cache for instant loads.
- Event listeners — get notified on submit, toggle, language change, close, and errors.
Installation
npm install @privasapien/react-native-consent-sdk(Optional) If you use yarn:
yarn add @privasapien/react-native-consent-sdkiOS Requirements
Since the SDK uses native iOS frameworks, you must run pod install:
cd ios && pod installNote: Because the SDK relies on native modules, it cannot be used with the "Expo Go" app. You must use a custom development client (EAS Build) or a bare React Native workflow.
Quick Start
1. Initialize the SDK
Call initialize() as early as possible in your app lifecycle (e.g., inside App.tsx or index.js).
import React, { useEffect } from 'react';
import { View, Button } from 'react-native';
import ConsentSDK from '@privasapien/react-native-consent-sdk';
export default function App() {
useEffect(() => {
// 1. Initialize the SDK
ConsentSDK.initialize({
apiUrl: "https://api.your-domain.com/api/v1",
applicationId: "your-app-id",
tenantId: "your-tenant-id",
userIdentifier: "[email protected]",
modeOfCommunication: "email",
}).catch(console.error);
// 2. Setup Listeners
ConsentSDK.addListener({
onConsentSubmitted: (acceptedPurposeIds) => {
console.log('Consent saved:', acceptedPurposeIds);
},
onConsentClosed: () => {
console.log('Consent bottom sheet closed');
},
});
// Cleanup listeners on unmount
return () => ConsentSDK.removeListeners();
}, []);
// 3. Trigger the UI
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Button
title="Manage Privacy Settings"
onPress={() => ConsentSDK.showBottomSheet()}
/>
</View>
);
}Configuration
All fields for the initialization config object:
| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| apiUrl | string | ✓ | Base URL of your consent API |
| applicationId | string | ✓ | Your application UUID |
| tenantId | string | ✓ | Your tenant UUID |
| userIdentifier | string | ✓ | User's email or phone number |
| modeOfCommunication | string | ✓ | "email" or "phone" |
| introductionMessage | string? | | Custom message shown above the consent notice |
| age | number? | | User's age (enables parental consent flow if < 18) |
| parentEmail | string? | | Required when age < 18 |
| language | string? | | Default language. Defaults to "english" |
API Reference
ConsentSDK.initialize(config)
Initializes the SDK. Must be called before attempting to show any UI. Returns a Promise.
ConsentSDK.showBottomSheet()
Presents the consent UI as a modal bottom sheet overlay. Returns a Promise that resolves when the UI opens.
ConsentSDK.showFullScreen()
Presents the consent UI as a full-screen modal. Returns a Promise that resolves when the UI opens.
ConsentSDK.addListener(listener)
Registers a single listener for Consent SDK lifecycle events. Calling this replaces any previously registered listener.
ConsentSDK.removeListeners()
Removes all registered event listeners and cancels the native subscriptions. Call this in useEffect cleanup or when the screen unmounts to prevent memory leaks.
Event Listeners
Subscribe to consent lifecycle events via ConsentSDK.addListener(listener):
ConsentSDK.addListener({
onConsentSubmitted: (acceptedPurposeIds: string[]) => {
// User saved their preferences
},
onConsentClosed: () => {
// User dismissed without saving
},
onConsentError: (error: string) => {
// Network or API error occurred
},
onLanguageChanged: (languageCode: string) => {
// Language switched in the dropdown
},
onPurposeToggled: (purposeId: string, isSelected: boolean) => {
// Individual purpose toggled
}
});All methods are optional — provide only the callbacks you need.
License
Copyright © 2024 Privasapien. All rights reserved.
