Skip to main content

React Native

There are two UI options for our CMP: classic or clear, both are used in the same way, and functionnality is the same, only the design is different.

AppConsent Classic package on NPMjs.com

AppConsent Clear package on NPMjs.com


Getting started​

Setup the environment for react-native as explained here.

To install the package for the classic UI

npm install appconsent-reactnative --save

To install the package for the clear UI

npm install appconsent-clear-reactnative --save

iOS​

Run pod install.

note

AppConsent SDK supports the new App Tracking Transparency framework (> iOS 14+ available).You must register the NSUserTrackingUsageDescription key in the Info.plist file of your application.

The documentation for the iOS AppConsent framework can be found here.

Android​

In project/build.gradle, add this maven url in the allprojects/repositories block.

allprojects {
repositories {
maven {
url "https://artifactory.datalf.chat/artifactory/app-consent-v2-release"
}
}
}

The Documentation for the Android AppConsent framework can be found here.


Usage​

// for classic UI import from 'appconsent-reactnative'
// for clear UI import from 'appconsent-clear-reactnative'
import AppConsent from 'appconsent-reactnative';

// Configure at launch (appKey:forceApplyGDPR:forceATT)
AppConsent.configureWith("appKey", true, true);

Features of AppConsent​

AppConsent.consentAlreadyGiven()
.then( success =>
console.log("πŸ”₯ consentAlreadyGiven => " + success)
)

Return true if consent is given, false otherwise.

Present notice​

AppConsent.present(true)

To display AppConsent UI by modal on top of your view. present:false displays introduction page first.

Get App Key​

AppConsent.getAppKey()
.then( success =>
console.log("πŸ”₯ getAppKey => " + success)
)

Return AppKey.

Get Force Apply GDPR​

AppConsent.getForceApplyGDPR()
.then( success =>
console.log("πŸ”₯ getForceApplyGDPR => " + success)
)

Return forceApplyGDPR => true or false.

Get Force ATT - iOS Only​

AppConsent.getForceATT()
.then( success =>
console.log("πŸ”₯ getForceATT => " + success)
)

Return forceATT => true or false.

AppConsent.consentGiven()
.then( success =>
console.log("πŸ”₯ consentGiven => " + success)
)

Callback when user give its consent.

Consentable allowed - objectId​

AppConsent.consentableAllowedByObjectId("1")
.then( success =>
console.log("πŸ”₯ consentableAllowedByObjectId => " + success)
)

Return true if consentable with objectId = 1 is allowed, false otherwise.

Consentable allowed - iabId​

AppConsent.consentableAllowedByIABId("1", 1)
.then( success =>
console.log("πŸ”₯ consentableAllowedByIABId => " + success)
)

Params:
iabId is a String
type is a NSInteger (0: purpose ,1: feature , 2: specialFeature ,3: specialPurpose)
Return true if consentable with iabId = 1 is allowed, false otherwise.

Consentable allowed - extraId​

AppConsent.extraConsentableAllowed("1")
.then( success =>
console.log("πŸ”₯ extraConsentableAllowed => " + success)
)

Return true if consentable with extraId = 1 is allowed, false otherwise.

Stack allowed - iabId​

AppConsent.stackAllowedByIABId("1")
.then( success =>
console.log("πŸ”₯ stackAllowedByIABId => " + success)
)

Return true if consentable with iabId = 1 is allowed, false otherwise.

Vendor allowed - iabId​

AppConsent.vendorAllowedByIABId("1")
.then( success =>
console.log("πŸ”₯ vendorAllowedByIABId => " + success)
)

Return true if consentable with iabId = 1 is allowed, false otherwise.

Vendor allowed - extraId​

AppConsent.extraVendorAllowed("1")
.then( success =>
console.log("πŸ”₯ extraVendorAllowed => " + success)
)

Return true if consentable with extraId = 1 is allowed, false otherwise.

AppConsent.setConsentableConsent({"1":1})
.then( success =>
console.log("πŸ”₯ setConsentableConsent => " + "Success")
)

Set consentables status with an iabId.

caution

Key must be an iabId, not an objectId.
Value must be an Integer: 0 (pending), 1 (allowed), -1 (denied)

note

This method doesn’t send request to the server.

AppConsent.setExtraConsentableConsent({"TDWLFix3":1})
.then( success =>
console.log("πŸ”₯ setExtraConsentableConsent => " + "Success")
)

Set consentables status with extraId.

caution

Key must be an extraId, not an objectId.
Value must be an Integer: 0 (pending), 1 (allowed), -1 (denied)

note

This method doesn’t send request to the server.

Check for update​

AppConsent.checkForUpdate()
.then( success =>
console.log("πŸ”₯ checkForUpdate => " + success)
)

Check if consent must be updated (new gvl version, new consentables…)

Clear consents​

AppConsent.clearConsent()

Clear consents on NSUserDefaults, but not on server.

Is GDPR Country​

AppConsent.isGDPRCountry()
.then( success =>
console.log("πŸ”₯ isGDPRCountry => " + success)
)

Check if device is GDPR country.
Return true, false otherwise.

App Tracking is available - iOS Only​

AppConsent.appTrackingIsAvailable()
.then( success =>
console.log("πŸ”₯ appTrackingIsAvailable => " + success)
)

Check if your device supports App Tracking Transparency.
Return true if available, false otherwise.

App Tracking Authorization Given - iOS Only​

AppConsent.appTrackingAuthorizationGiven()
.then( success =>
console.log("πŸ”₯ appTrackingAuthorizationGiven => " + success)
)

Check if App Tracking Transparency has been given.
Return 0 (not given), 1 (given), 2 (not supported)

App Tracking Authorization Status - iOS Only​

AppConsent.appTrackingAuthorizationStatus()
.then( success =>
console.log("πŸ”₯ appTrackingAuthorizationStatus => " + success)
)

Check status of App Tracking Transparency.
Return 0 (failure), 1 (success), 2 (not supported)

Floating purpose allowed - extraId​

AppConsent.extraFloatingPurposeAllowed("NkDawTu1")
.then( success =>
console.log("πŸ”₯ extraFloatingPurposeAllowed => " + success)
)

Check if floating purpose is allowed.

note

You need to call checkForUpdate method before calling the above method to stay up to date.