Skip to content

Commit

Permalink
Merge pull request #526 from AppsFlyerSDK/dev/DELIVERY-54536/update-6…
Browse files Browse the repository at this point in the history
….13.0

Dev/delivery 54536/update 6.13.0
  • Loading branch information
amit-kremer93 authored Feb 19, 2024
2 parents ff4a502 + cc5ebfc commit 46c9732
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 18 deletions.
47 changes: 47 additions & 0 deletions Docs/RN_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The list of available methods for this plugin is described below.
- [addPushNotificationDeepLinkPath](#addpushnotificationdeeplinkpath)
- [appendParametersToDeepLinkingURL](#appendparameterstodeeplinkingurl)
- [disableAdvertisingIdentifier](#disableAdvertisingIdentifier)
- [enableTCFDataCollection](#enableTCFDataCollection)
- [setConsentData](#setConsentData)
- [Android Only APIs](#android-only-apis)
- [setCollectAndroidID](#setcollectandroidid)
- [setCollectIMEI](#setcollectimei)
Expand Down Expand Up @@ -750,6 +752,51 @@ Disables collection of various Advertising IDs by the SDK.<br>
appsFlyer.disableAdvertisingIdentifier(true);
```

---
### enableTCFDataCollection
`enableTCFDataCollection(enabled): void`

instruct the SDK to collect the TCF data from the device.


| parameter | type | description |
| ---------- |----------|------------------ |
| enabled | boolean | enable/disable TCF data collection |

*Example:*

```javascript
appsFlyer.enableTCFDataCollection(true);
```

---
### setConsentData
`setConsentData(consentObject): void`

When GDPR applies to the user and your app does not use a CMP compatible with TCF v2.2, use this API to provide the consent data directly to the SDK.<br>
The AppsFlyerConsent object has 2 methods:

1. `AppsFlyerConsent.forNonGDPRUser`: Indicates that GDPR doesn’t apply to the user and generates nonGDPR consent object. This method doesn’t accept any parameters.
2. `AppsFlyerConsent.forGDPRUser`: create an AppsFlyerConsent object with 2 parameters:


| parameter | type | description |
| ---------- |----------|------------------ |
| hasConsentForDataUsage | boolean | Indicates whether the user has consented to use their data for advertising purposes |
| hasConsentForAdsPersonalization | boolean | Indicates whether the user has consented to use their data for personalized advertising |

*Example:*

```javascript
import appsFlyer, {AppsFlyerConsent} from 'react-native-appsflyer';

let nonGDPRUser = AppsFlyerConsent.forNonGDPRUser();
// OR
let GDPRUser = AppsFlyerConsent.forGDPRUser(true, false);

appsFlyer.setConsentData(nonGDPRUser /**or**/ GDPRUser);
```

## Android Only APIs

### setCollectAndroidID
Expand Down
139 changes: 139 additions & 0 deletions Docs/RN_CMP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
title: Send consent for DMA compliance
category: 5f9705393c689a065c409b23
parentDoc: 645213236f53a00d4daa9230
order: 12
hidden: false
---

## Send consent for DMA compliance
The SDK offers two alternative methods for gathering consent data:

Through a Consent Management Platform (CMP): If the app uses a CMP that complies with the Transparency and Consent Framework (TCF) v2.2 protocol, the SDK can automatically retrieve the consent details.

OR

Through a dedicated SDK API: Developers can pass Google's required consent data directly to the SDK using a specific API designed for this purpose.

### Use CMP to collect consent data
A CMP compatible with TCF v2.2 collects DMA consent data and stores it in NSUserDefaults (iOS) and SharedPreferences (Android). To enable the SDK to access this data and include it with every event, follow these steps:

1. Call `appsFlyer.enableTCFDataCollection(true)`
2. Initialize the SDK in [manual start mode](/Docs/RN_API.md#initsdk)
3. Use the CMP to decide if you need the consent dialog in the current session to acquire the consent data. If you need the consent dialog move to step 4; otherwise move to step 5
4. Get confirmation from the CMP that the user has made their consent decision and the data is available in NSUserDefaults/SharedPreferences
5. Call `appsFlyer.startSdk()`
```javascript
useEffect(() => {
const option = {
isDebug: true,
devKey: 'UxXxXxXxXd',
onInstallConversionDataListener: true,
onDeepLinkListener: true,
timeToWaitForATTUserAuthorization: 10,
manualStart: true, // <-- Manual start
};
// TCF data collection
appsFlyer.enableTCFDataCollection(true);

//init appsflyer
appsFlyer.initSdk(
option,
res => {
console.log(res);
},
err => {
console.log(err);
},
);

...

// CMP Pseudocode
if (cmpManager.hasConsent()) {
appsFlyer.startSdk();
} else {
cmpManager.presentConsentDialog(res => {
appsFlyer.startSdk();
});
}
},[])
```
## Manually collect consent data
If your app does not use a CMP compatible with TCF v2.2, use the SDK API detailed below to provide the consent data directly to the SDK.

### When GDPR applies to the user
If GDPR applies to the user, perform the following:

1. Given that GDPR is applicable to the user, determine whether the consent data is already stored for this session.
1. If there is no consent data stored, show the consent dialog to capture the user consent decision.
2. If there is consent data stored continue to the next step.
2. To transfer the consent data to the SDK create an AppsFlyerConsent object using `forGDPRUser` method that accepts the following parameters:<br>
`hasConsentForDataUsage: boolean` - Indicates whether the user has consented to use their data for advertising purposes.<br>
`hasConsentForAdsPersonalization: boolean` - Indicates whether the user has consented to use their data for personalized advertising.
3. Call `appsFlyer.setConsentData(consentData)` with the AppsFlyerConsent object.
4. Call `appsFlyer.initSdk()`.
```javascript
import appsFlyer, {AppsFlyerConsent} from 'react-native-appsflyer';

useEffect(() => {
const option = {
isDebug: true,
devKey: 'UxXxXxXxXd',
onInstallConversionDataListener: true,
onDeepLinkListener: true,
timeToWaitForATTUserAuthorization: 10,
};

// user consent data
let consentData = AppsFlyerConsent.forGDPRUser(true, false);

appsFlyer.setConsentData(consentData);

//start appsflyer
appsFlyer.initSdk(
option,
res => {
console.log(res);
},
err => {
console.log(err);
},
);
},[])
```
### When GDPR does not apply to the user

If GDPR doesn’t apply to the user perform the following:
1. Create an AppsFlyerConsent object using `forNonGDPRUser` method that doesn't accepts any parameters
2. Call `appsFlyer.setConsentData(consentData)` with the AppsFlyerConsent object.
3. Call `appsFlyer.initSdk()`.
```javascript
import appsFlyer, {AppsFlyerConsent} from 'react-native-appsflyer';

useEffect(() => {
const option = {
isDebug: true,
devKey: 'UxXxXxXxXd',
onInstallConversionDataListener: true,
onDeepLinkListener: true,
timeToWaitForATTUserAuthorization: 10,
};

// GDPR does not apply to the user
let consentData = AppsFlyerConsent.forNonGDPRUser();

appsFlyer.setConsentData(consentData);

//start appsflyer
appsFlyer.initSdk(
option,
res => {
console.log(res);
},
err => {
console.log(err);
},
);
},[])
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ If you have used 1 of the removed APIs, please check the integration guide for t
- [Test integration](/Docs/RN_Testing.md)
- [In-app events](/Docs/RN_InAppEvents.md)
- [Uninstall measurement](/Docs/RN_UninstallMeasurement.md)
- [Send consent for DMA compliance](/Docs/RN_CMP.md)
## 🔗 Deep Linking
- [Integration](/Docs/RN_DeepLinkIntegrate.md)
- [***Expo*** Integration](/Docs/RN_ExpoDeepLinkIntegration.md)
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ repositories {
dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation "com.android.installreferrer:installreferrer:${safeExtGet('installReferrerVersion', '2.1')}"
api "com.appsflyer:af-android-sdk:${safeExtGet('appsflyerVersion', '6.12.2')}"
api "com.appsflyer:af-android-sdk:${safeExtGet('appsflyerVersion', '6.13.0')}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class RNAppsFlyerConstants {

final static String PLUGIN_VERSION = "6.12.2";
final static String PLUGIN_VERSION = "6.13.0";
final static String NO_DEVKEY_FOUND = "No 'devKey' found or its empty";
final static String UNKNOWN_ERROR = "AF Unknown Error";
final static String SUCCESS = "Success";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,27 @@ public void performOnDeepLinking() {
Log.d("AppsFlyer", "performOnDeepLinking: activity is null!");
}
}


@ReactMethod
public void enableTCFDataCollection(Boolean enabled) {
AppsFlyerLib.getInstance().enableTCFDataCollection(enabled);
}

@ReactMethod
public void setConsentData(ReadableMap consentData) {
JSONObject JSONConsentData = RNUtil.readableMapToJson(consentData);
boolean isUserSubjectToGDPR = JSONConsentData.optBoolean("isUserSubjectToGDPR");
boolean hasConsentForDataUsage = JSONConsentData.optBoolean("hasConsentForDataUsage");
boolean hasConsentForAdsPersonalization = JSONConsentData.optBoolean("hasConsentForAdsPersonalization");
AppsFlyerConsent consentObject;
if (isUserSubjectToGDPR) {
consentObject = AppsFlyerConsent.forGDPRUser(hasConsentForDataUsage, hasConsentForAdsPersonalization);
} else {
consentObject = AppsFlyerConsent.forNonGDPRUser();
}
AppsFlyerLib.getInstance().setConsentData(consentObject);
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
Expand Down
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ declare module "react-native-appsflyer" {
brandDomain?: string;
}

export const AppsFlyerConsent: {
forGDPRUser: (hasConsentForDataUsage: boolean, hasConsentForAdsPersonalization: boolean) => void;
forNonGDPRUser: () => void;
}

export type AppsFlyerConsentType = typeof AppsFlyerConsent;

const appsFlyer: {
onInstallConversionData(callback: (data: ConversionData) => any): () => void;
onInstallConversionFailure(callback: (data: ConversionData) => any): () => void;
Expand Down Expand Up @@ -151,6 +158,8 @@ declare module "react-native-appsflyer" {
setPartnerData(partnerId: string, partnerData: object): void
appendParametersToDeepLinkingURL(contains: string, parameters: object): void
startSdk(): void
enableTCFDataCollection(enabled: boolean): void
setConsentData(consentData: AppsFlyerConsentType): void

/**
* For iOS Only
Expand Down
40 changes: 39 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,48 @@ appsFlyer.performOnDeepLinking = () => {
return RNAppsFlyer.performOnDeepLinking();
};

/**
* instruct the SDK to collect the TCF data from the device.
* @param enabled: if the sdk should collect the TCF data. true/false
*/
appsFlyer.enableTCFDataCollection= (enabled) => {
return RNAppsFlyer.enableTCFDataCollection(enabled);
}

/**
* If your app does not use a CMP compatible with TCF v2.2, use the SDK API detailed below to provide the consent data directly to the SDK.
* @param consentData: AppsFlyerConsent object.
*/
appsFlyer.setConsentData = (consentData) => {
return RNAppsFlyer.setConsentData(consentData);
}

function AFParseJSONException(_message, _data) {
this.message = _message;
this.data = _data;
this.name = 'AFParseJSONException';
}

export default appsFlyer;
// Consent object
export const AppsFlyerConsent = (function () {
// Private constructor
function AppsFlyerConsent(isUserSubjectToGDPR, hasConsentForDataUsage, hasConsentForAdsPersonalization) {
this.isUserSubjectToGDPR = isUserSubjectToGDPR;
this.hasConsentForDataUsage = hasConsentForDataUsage;
this.hasConsentForAdsPersonalization = hasConsentForAdsPersonalization;
}

return {
// Factory method for GDPR user
forGDPRUser: function(hasConsentForDataUsage, hasConsentForAdsPersonalization) {
return new AppsFlyerConsent(true, hasConsentForDataUsage, hasConsentForAdsPersonalization);
},

// Factory method for non GDPR user
forNonGDPRUser: function() {
return new AppsFlyerConsent(false, null, null);
}
};
})();

export default appsFlyer;
26 changes: 26 additions & 0 deletions ios/AppsFlyerConsent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// AppsFlyerConsent.h
// AppsFlyerLib
//
// Created by Veronica Belyakov on 14/01/2024.
//
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface AppsFlyerConsent : NSObject <NSCoding>

@property (nonatomic, readonly, assign) BOOL isUserSubjectToGDPR;
@property (nonatomic, readonly, assign) BOOL hasConsentForDataUsage;
@property (nonatomic, readonly, assign) BOOL hasConsentForAdsPersonalization;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

- (instancetype)initForGDPRUserWithHasConsentForDataUsage:(BOOL)hasConsentForDataUsage
hasConsentForAdsPersonalization:(BOOL)hasConsentForAdsPersonalization NS_DESIGNATED_INITIALIZER;
- (instancetype)initNonGDPRUser NS_DESIGNATED_INITIALIZER;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 46c9732

Please sign in to comment.