Skip to content

Integrate consent banner

With your assetId and bannerId ready, add TruConsentModal to your React Native app. The component fetches its configuration on mount and auto-hides if the user has already consented to all purposes.

Terminal window
npm install @truconsent/consent-notice-react-native

Add your SDK credentials to app.json under the extra field so they are available via expo-constants:

{
"expo": {
"extra": {
"truConsentApiKey": "your-api-key",
"truConsentOrganizationId": "your-organization-id",
"truConsentAssetId": "your-asset-id",
"truConsentApiUrl": "https://trukit-dev.truconsent.io"
}
}
}

Import TruConsentModal and add it to your screen. Place it as a sibling to your main content so it renders as an overlay:

import React from 'react';
import { View } from 'react-native';
import Constants from 'expo-constants';
import TruConsentModal from '@truconsent/consent-notice-react-native';
const extra = Constants.expoConfig?.extra ?? {};
export default function App() {
return (
<View style={{ flex: 1 }}>
<MainContent />
<TruConsentModal
apiKey={extra.truConsentApiKey}
organizationId={extra.truConsentOrganizationId}
bannerId="CP003"
userId="user-uuid-or-session-id"
assetId={extra.truConsentAssetId}
apiUrl={extra.truConsentApiUrl}
companyName="Your Company"
onClose={(type) => console.log('Consent banner closed:', type)}
/>
</View>
);
}

Show the banner only when needed — for example, before a form submission:

import React, { useState } from 'react';
import { View, Button, Alert } from 'react-native';
import Constants from 'expo-constants';
import TruConsentModal from '@truconsent/consent-notice-react-native';
const extra = Constants.expoConfig?.extra ?? {};
export default function SignupScreen() {
const [showConsent, setShowConsent] = useState(false);
const handleConsentClose = (type: string) => {
setShowConsent(false);
if (type === 'approved' || type === 'partial_consent') {
proceedWithSignup();
} else {
Alert.alert('Consent required', 'You must consent to continue.');
}
};
const proceedWithSignup = () => {
// proceed with form submission
};
return (
<View style={{ flex: 1 }}>
<Button title="Sign Up" onPress={() => setShowConsent(true)} />
{showConsent && (
<TruConsentModal
apiKey={extra.truConsentApiKey}
organizationId={extra.truConsentOrganizationId}
bannerId="CP003"
userId="user-uuid"
assetId={extra.truConsentAssetId}
apiUrl={extra.truConsentApiUrl}
onClose={handleConsentClose}
/>
)}
</View>
);
}
* Required
PropTypeDescription
apiKey *stringAPI key from the platform dashboard.
organizationId *stringYour org ID — sent on every request.
bannerId *stringCollection point display_id from the platform (e.g. CP003).
assetId *stringAsset UUID from the platform.
apiUrl *stringSDK base URL: https://trukit-dev.truconsent.io
userIdstringAuthenticated user ID or guest UUID. Used to look up prior consent records.
logoUrlstringLogo URL shown in the banner header.
companyNamestringCompany name shown in the banner.
onClosefunctionCalled on close with one of the consent action types below.
ValueMeaning
approvedUser consented to all purposes
declinedUser declined all purposes
partial_consentUser consented to some purposes
revokedUser withdrew a previously granted consent
no_actionBanner auto-dismissed (user already consented)

Banner does not appear

  • Verify bannerId, assetId, and organizationId are correct.
  • If the user has already consented to all purposes, the component auto-hides and onClose fires with no_action.

401 Unauthorized

  • Check your API key is correct and matches your organization.

403 Forbidden

  • Your app bundle ID or domain is not allowlisted. Go to Settings → API Settings → Allowed Domains in the platform dashboard and add it.