Skip to content

Commit 5691c3b

Browse files
author
Amit kremer
committed
review 1
1 parent 70671fc commit 5691c3b

5 files changed

Lines changed: 64 additions & 48 deletions

File tree

Docs/RN_API.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ The list of available methods for this plugin is described below.
3737
- [disableAdvertisingIdentifier](#disableAdvertisingIdentifier)
3838
- [enableTCFDataCollection](#enableTCFDataCollection)
3939
- [setConsentData](#setConsentData)
40-
- [setNonGDPRUser](#setNonGDPRUser)
4140
- [Android Only APIs](#android-only-apis)
4241
- [setCollectAndroidID](#setcollectandroidid)
4342
- [setCollectIMEI](#setcollectimei)
@@ -772,40 +771,30 @@ appsFlyer.enableTCFDataCollection(true);
772771

773772
---
774773
### setConsentData
775-
`setConsentData(consentData): void`
774+
`setConsentData(consentObject): void`
776775

777776
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>
778-
The consent object has 2 properties:
777+
The AppsFlyerConsent object has 2 methods:
778+
779+
1. `AppsFlyerConsent.forNonGDPRUser`: Indicates that GDPR doesn’t apply to the user and generates nonGDPR consent object. This method doesn’t accept any parameters.
780+
2. `AppsFlyerConsent.forGDPRUser`: create an AppsFlyerConsent object with 2 parameters:
779781

780-
1. `hasConsentForDataUsage`: Indicates whether the user has consented to use their data for advertising purposes.
781-
2. `hasConsentForAdsPersonalization`: ndicates whether the user has consented to use their data for personalized advertising.
782782

783783
| parameter | type | description |
784784
| ---------- |----------|------------------ |
785-
| consentData | object | Consent object of the user |
785+
| hasConsentForDataUsage | boolean | Indicates whether the user has consented to use their data for advertising purposes |
786+
| hasConsentForAdsPersonalization | boolean | Indicates whether the user has consented to use their data for personalized advertising |
786787

787788
*Example:*
788789

789790
```javascript
790-
let consentData = {
791-
hasConsentForDataUsage: true,
792-
hasConsentForAdsPersonalization: false
793-
}
794-
795-
appsFlyer.setConsentData(consentData);
796-
```
797-
798-
---
799-
800-
### setNonGDPRUser
801-
`setNonGDPRUser(): void`
791+
import appsFlyer, {AppsFlyerConsent} from 'react-native-appsflyer';
802792

803-
Use this API if GDPR doesn’t apply to the user.<br>
793+
let nonGDPRUser = AppsFlyerConsent.forNonGDPRUser();
794+
// OR
795+
let GDPRUser = AppsFlyerConsent.forGDPRUser(true, false);
804796

805-
*Example:*
806-
807-
```javascript
808-
appsFlyer.setNonGDPRUser();
797+
appsFlyer.setConsentData(nonGDPRUser /**or**/ GDPRUser);
809798
```
810799

811800
## Android Only APIs

android/src/main/java/com/appsflyer/reactnative/RNAppsFlyerModule.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,18 +824,18 @@ public void enableTCFDataCollection(Boolean enabled) {
824824
@ReactMethod
825825
public void setConsentData(ReadableMap consentData) {
826826
JSONObject JSONConsentData = RNUtil.readableMapToJson(consentData);
827+
boolean isUserSubjectToGDPR = JSONConsentData.optBoolean("isUserSubjectToGDPR");
827828
boolean hasConsentForDataUsage = JSONConsentData.optBoolean("hasConsentForDataUsage");
828829
boolean hasConsentForAdsPersonalization = JSONConsentData.optBoolean("hasConsentForAdsPersonalization");
829-
AppsFlyerConsent consentObject = AppsFlyerConsent.forGDPRUser(hasConsentForDataUsage, hasConsentForAdsPersonalization);
830+
AppsFlyerConsent consentObject;
831+
if (isUserSubjectToGDPR) {
832+
consentObject = AppsFlyerConsent.forGDPRUser(hasConsentForDataUsage, hasConsentForAdsPersonalization);
833+
} else {
834+
consentObject = AppsFlyerConsent.forNonGDPRUser();
835+
}
830836
AppsFlyerLib.getInstance().setConsentData(consentObject);
831837
}
832838

833-
@ReactMethod
834-
public void setNonGDPRUser() {
835-
AppsFlyerConsent consentData = AppsFlyerConsent.forNonGDPRUser();
836-
AppsFlyerLib.getInstance().setConsentData(consentData);
837-
}
838-
839839
@ReactMethod
840840
public void addListener(String eventName) {
841841
// Keep: Required for RN built in Event Emitter Calls.

index.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ declare module "react-native-appsflyer" {
114114
brandDomain?: string;
115115
}
116116

117+
export const AppsFlyerConsent: {
118+
forGDPRUser: (hasConsentForDataUsage: boolean, hasConsentForAdsPersonalization: boolean) => void;
119+
forNonGDPRUser: () => void;
120+
}
121+
122+
export type AppsFlyerConsentType = typeof AppsFlyerConsent;
123+
117124
const appsFlyer: {
118125
onInstallConversionData(callback: (data: ConversionData) => any): () => void;
119126
onInstallConversionFailure(callback: (data: ConversionData) => any): () => void;
@@ -152,8 +159,7 @@ declare module "react-native-appsflyer" {
152159
appendParametersToDeepLinkingURL(contains: string, parameters: object): void
153160
startSdk(): void
154161
enableTCFDataCollection(enabled: boolean): void
155-
setConsentData(consentData: object): void
156-
setNonGDPRUser(): void
162+
setConsentData(consentData: AppsFlyerConsentType): void
157163

158164
/**
159165
* For iOS Only

index.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,20 +635,38 @@ appsFlyer.enableTCFDataCollection= (enabled) => {
635635

636636
/**
637637
* 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.
638-
* @param consentData: object with 2 properties: hasConsentForDataUsage and hasConsentForAdsPersonalization.
638+
* @param consentData: AppsFlyerConsent object.
639639
*/
640640
appsFlyer.setConsentData = (consentData) => {
641641
return RNAppsFlyer.setConsentData(consentData);
642642
}
643643

644-
appsFlyer.setNonGDPRUser = () => {
645-
return RNAppsFlyer.setNonGDPRUser();
646-
}
647-
648644
function AFParseJSONException(_message, _data) {
649645
this.message = _message;
650646
this.data = _data;
651647
this.name = 'AFParseJSONException';
652648
}
653649

654-
export default appsFlyer;
650+
// Consent object
651+
export const AppsFlyerConsent = (function () {
652+
// Private constructor
653+
function AppsFlyerConsent(isUserSubjectToGDPR, hasConsentForDataUsage, hasConsentForAdsPersonalization) {
654+
this.isUserSubjectToGDPR = isUserSubjectToGDPR;
655+
this.hasConsentForDataUsage = hasConsentForDataUsage;
656+
this.hasConsentForAdsPersonalization = hasConsentForAdsPersonalization;
657+
}
658+
659+
return {
660+
// Factory method for GDPR user
661+
forGDPRUser: function(hasConsentForDataUsage, hasConsentForAdsPersonalization) {
662+
return new AppsFlyerConsent(true, hasConsentForDataUsage, hasConsentForAdsPersonalization);
663+
},
664+
665+
// Factory method for non GDPR user
666+
forNonGDPRUser: function() {
667+
return new AppsFlyerConsent(false, null, null);
668+
}
669+
};
670+
})();
671+
672+
export default appsFlyer;

ios/RNAppsFlyer.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,21 @@ - (BOOL)isExpoApp {
569569
[[AppsFlyerLib shared] enableTCFDataCollection:enabled];
570570
}
571571

572-
RCT_EXPORT_METHOD(setConsentData:(NSDictionary *)consentData) {
573-
if (![consentData isKindOfClass:[NSNull null]]) {
574-
BOOL hasConsentForDataUsage = consentData[@"hasConsentForDataUsage"];
575-
BOOL hasConsentForAdsPersonalization = consentData[@"hasConsentForAdsPersonalization"];
576-
AppsFlyerConsent *consentData = [[AppsFlyerConsent alloc] initForGDPRUserWithHasConsentForDataUsage:hasConsentForDataUsage hasConsentForAdsPersonalization:hasConsentForAdsPersonalization];
572+
RCT_EXPORT_METHOD(setConsentData:(NSDictionary *)consentDictionary) {
573+
if (![consentDictionary isKindOfClass:[NSNull null]]) {
574+
BOOL isUserSubjectToGDPR = [consentDictionary[@"isUserSubjectToGDPR"] boolValue];
575+
576+
AppsFlyerConsent *consentData;
577+
if (isUserSubjectToGDPR){
578+
BOOL hasConsentForDataUsage = [consentDictionary[@"hasConsentForDataUsage"] boolValue];
579+
BOOL hasConsentForAdsPersonalization = [consentDictionary[@"hasConsentForAdsPersonalization"] boolValue];
580+
consentData = [[AppsFlyerConsent alloc] initForGDPRUserWithHasConsentForDataUsage:hasConsentForDataUsage hasConsentForAdsPersonalization:hasConsentForAdsPersonalization];
581+
} else {
582+
consentData = [[AppsFlyerConsent alloc] initNonGDPRUser];
583+
}
584+
577585
[[AppsFlyerLib shared] setConsentData:consentData];
578586
}
579587
}
580588

581-
RCT_EXPORT_METHOD(setNonGDPRUser) {
582-
AppsFlyerConsent *consentData = [[AppsFlyerConsent alloc] initNonGDPRUser];
583-
[[AppsFlyerLib shared] setConsentData:consentData];
584-
}
585-
586589
@end

0 commit comments

Comments
 (0)