Skip to content

Commit 4db1afe

Browse files
[SDK-2249] Expose the setDMAParamsForEEA method (#957)
* Added setDMAParamsForEEA * Updated native SDKs * Removed setDebug * Update react-native-branch.podspec * Update index.js
1 parent 247c090 commit 4db1afe

File tree

9 files changed

+687
-614
lines changed

9 files changed

+687
-614
lines changed

ChangeLog.md

Lines changed: 560 additions & 493 deletions
Large diffs are not rendered by default.

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ def safeExtGet(prop, fallback) {
4747
dependencies {
4848
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
4949
implementation 'com.facebook.react:react-native:+' // From node_modules
50-
api 'io.branch.sdk.android:library:5.7.1'
50+
api 'io.branch.sdk.android:library:5.9.0'
5151
}

android/src/main/java/io/branch/rnbranch/RNBranchModule.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,6 @@ private static void notifyJSOfInitSessionStart(Context context, Uri uri) {
257257
LocalBroadcastManager.getInstance(context).sendBroadcast(broadcastIntent);
258258
}
259259

260-
/**
261-
* @deprecated setDebug is deprecated and all functionality has been disabled. If you wish to enable
262-
* logging, please invoke enableLogging. If you wish to simulate installs, please Test Devices
263-
* (https://help.branch.io/using-branch/docs/adding-test-devices)
264-
*/
265-
@Deprecated
266-
public static void setDebug() { }
267-
268260
public static void enableLogging() {
269261
Branch.enableLogging();
270262
}
@@ -1253,4 +1245,10 @@ private static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSON
12531245
}
12541246
return array;
12551247
}
1248+
1249+
@ReactMethod
1250+
public void setDMAParamsForEEA(boolean eeaRegion, boolean adPersonalizationConsent, boolean adUserDataUsageConsent) {
1251+
Branch branch = Branch.getInstance();
1252+
branch.setDMAParamsForEEA(eeaRegion, adPersonalizationConsent, adUserDataUsageConsent);
1253+
}
12561254
}

docs/setDebug.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

ios/RNBranch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extern NSString * _Nonnull const RNBranchLinkOpenedNotificationLinkPropertiesKey
2828
+ (void)useTestInstance;
2929
+ (void)deferInitializationForJSLoad;
3030

31-
+ (void)setDebug;
3231
+ (void)enableLogging;
3332

3433
@end

ios/RNBranch.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ + (BOOL)requiresMainQueueSetup {
109109

110110
#pragma mark - Class methods
111111

112-
+ (void)setDebug
113-
{
114-
[self.branch setDebug];
115-
}
116-
117112
+ (void)enableLogging
118113
{
119114
[self.branch enableLogging];
@@ -744,4 +739,9 @@ - (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start le
744739
return hexComponent / 255.0;
745740
}
746741

742+
#pragma mark setDMAParamsForEEA
743+
RCT_EXPORT_METHOD(setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPersonalizationConsent AdUserDataUsageConsent:(BOOL)adUserDataUsageConsent) {
744+
[Branch setDMAParamsForEEA:eeaRegion AdPersonalizationConsent:adPersonalizationConsent AdUserDataUsageConsent:adUserDataUsageConsent];
745+
}
746+
747747
@end

react-native-branch.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Pod::Spec.new do |s|
2222
s.source_files = [ "ios/*.h", "ios/*.m"]
2323
s.compiler_flags = %[-DRNBRANCH_VERSION=@\\"#{s.version}\\"]
2424
s.header_dir = 'RNBranch' # also sets generated module name
25-
s.dependency 'BranchSDK', '3.0.0'
25+
s.dependency 'BranchSDK', '3.2.0'
2626
s.dependency 'React-Core' # to ensure the correct build order
2727

2828
# Swift/Objective-C compatibility

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ interface Branch {
347347
) => Promise<string>;
348348
setPreInstallCampaign: (campaign: string) => void;
349349
setPreInstallPartner: (partner: string) => void;
350+
setDMAParamsForEEA: (eeaRegion: boolean, adPersonalizationConsent: boolean, adUserDataUsageConsent: boolean) => void;
350351
}
351352
declare const branch: Branch;
352353
export default branch;

src/index.js

Lines changed: 113 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,182 @@
1-
import { NativeModules, Platform } from 'react-native'
1+
import { NativeModules, Platform } from "react-native";
22

3-
const { RNBranch } = NativeModules
3+
const { RNBranch } = NativeModules;
44

5-
import createBranchUniversalObject from './branchUniversalObject'
6-
import BranchEvent from './BranchEvent'
7-
import BranchSubscriber from './BranchSubscriber'
5+
import createBranchUniversalObject from "./branchUniversalObject";
6+
import BranchEvent from "./BranchEvent";
7+
import BranchSubscriber from "./BranchSubscriber";
88

9-
const packageFile = require('./../package.json')
10-
export const VERSION = packageFile.version
9+
const packageFile = require("./../package.json");
10+
export const VERSION = packageFile.version;
1111

1212
class Branch {
1313
key = null;
1414
_checkCachedEvents = true;
1515
_debug = false;
1616

1717
constructor(options = {}) {
18-
if (options.debug) this._debug = true
18+
if (options.debug) this._debug = true;
1919

20-
console.info('Initializing react-native-branch v. ' + VERSION)
20+
console.info("Initializing react-native-branch v. " + VERSION);
2121
}
2222

2323
subscribe(options) {
24-
if (typeof options === 'function') {
24+
if (typeof options === "function") {
2525
/*
2626
* Support for legacy API, passing a single callback function:
2727
* branch.subscribe(({params, error, uri}) => { ... }). This is
2828
* the same as the onOpenComplete callback.
2929
*/
3030
options = {
3131
onOpenComplete: options,
32-
}
32+
};
3333
}
3434

3535
/*
3636
* You can specify checkCachedEvents in the subscribe options to control
3737
* this per subscriber.
3838
*/
39-
if (!('checkCachedEvents' in options)) {
40-
options.checkCachedEvents = this._checkCachedEvents
39+
if (!("checkCachedEvents" in options)) {
40+
options.checkCachedEvents = this._checkCachedEvents;
4141
}
42-
this._checkCachedEvents = false
42+
this._checkCachedEvents = false;
4343

44-
const subscriber = new BranchSubscriber(options)
45-
subscriber.subscribe()
44+
const subscriber = new BranchSubscriber(options);
45+
subscriber.subscribe();
4646

47-
return () => subscriber.unsubscribe()
47+
return () => subscriber.unsubscribe();
4848
}
4949

5050
skipCachedEvents() {
5151
/*** Sets to ignore cached events. ***/
52-
this._checkCachedEvents = false
52+
this._checkCachedEvents = false;
5353
}
5454

5555
/*** Tracking related methods ***/
56-
disableTracking = (disable) => RNBranch.disableTracking(disable)
57-
isTrackingDisabled = RNBranch.isTrackingDisabled
56+
disableTracking = (disable) => RNBranch.disableTracking(disable);
57+
isTrackingDisabled = RNBranch.isTrackingDisabled;
5858

5959
/*** RNBranch singleton methods ***/
60-
setDebug = () => { throw 'setDebug() is not supported in the RN SDK. For other solutions, please see https://rnbranch.app.link/setDebug' }
61-
getLatestReferringParams = (synchronous = false) => RNBranch.getLatestReferringParams(synchronous)
62-
getFirstReferringParams = RNBranch.getFirstReferringParams
63-
lastAttributedTouchData = (attributionWindow = {}) => RNBranch.lastAttributedTouchData(attributionWindow)
64-
setIdentity = (identity) => RNBranch.setIdentity(identity)
65-
setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity)
60+
getLatestReferringParams = (synchronous = false) =>
61+
RNBranch.getLatestReferringParams(synchronous);
62+
getFirstReferringParams = RNBranch.getFirstReferringParams;
63+
lastAttributedTouchData = (attributionWindow = {}) =>
64+
RNBranch.lastAttributedTouchData(attributionWindow);
65+
setIdentity = (identity) => RNBranch.setIdentity(identity);
66+
setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity);
6667
setRequestMetadata = (key, value) => {
67-
console.info('[Branch] setRequestMetadata has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the metadata.')
68-
return RNBranch.setRequestMetadataKey(key, value)
69-
}
68+
console.info(
69+
"[Branch] setRequestMetadata has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the metadata."
70+
);
71+
return RNBranch.setRequestMetadataKey(key, value);
72+
};
7073
addFacebookPartnerParameter = (name, value) => {
71-
console.info('[Branch] addFacebookPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters.')
72-
return RNBranch.addFacebookPartnerParameter(name, value)
73-
}
74+
console.info(
75+
"[Branch] addFacebookPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters."
76+
);
77+
return RNBranch.addFacebookPartnerParameter(name, value);
78+
};
7479
addSnapPartnerParameter = (name, value) => {
75-
console.info('[Branch] addSnapPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters.')
76-
return RNBranch.addSnapPartnerParameter(name, value)
77-
}
78-
clearPartnerParameters = RNBranch.clearPartnerParameters
79-
logout = RNBranch.logout
80-
getShortUrl = RNBranch.getShortUrl
80+
console.info(
81+
"[Branch] addSnapPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters."
82+
);
83+
return RNBranch.addSnapPartnerParameter(name, value);
84+
};
85+
clearPartnerParameters = RNBranch.clearPartnerParameters;
86+
logout = RNBranch.logout;
87+
getShortUrl = RNBranch.getShortUrl;
8188
openURL = (url, options = {}) => {
8289
return Platform.select({
8390
android: () => RNBranch.openURL(url, options),
84-
ios: () => RNBranch.openURL(url)
85-
})()
86-
}
91+
ios: () => RNBranch.openURL(url),
92+
})();
93+
};
8794
handleATTAuthorizationStatus = (ATTAuthorizationStatus) => {
88-
if (Platform.OS != 'ios') return;
89-
let normalizedAttAuthorizationStatus = -1
95+
if (Platform.OS != "ios") return;
96+
let normalizedAttAuthorizationStatus = -1;
9097

91-
switch(ATTAuthorizationStatus) {
92-
case 'authorized':
98+
switch (ATTAuthorizationStatus) {
99+
case "authorized":
93100
normalizedAttAuthorizationStatus = 3;
94101
break;
95-
case 'denied':
102+
case "denied":
96103
normalizedAttAuthorizationStatus = 2;
97104
break;
98-
case 'undetermined':
105+
case "undetermined":
99106
normalizedAttAuthorizationStatus = 0;
100107
break;
101-
case 'restricted':
108+
case "restricted":
102109
normalizedAttAuthorizationStatus = 1;
103110
break;
104111
}
105112

106113
if (normalizedAttAuthorizationStatus < 0) {
107-
console.info('[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted')
114+
console.info(
115+
"[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted"
116+
);
108117
return;
109118
}
110119

111-
RNBranch.handleATTAuthorizationStatus(normalizedAttAuthorizationStatus)
112-
}
120+
RNBranch.handleATTAuthorizationStatus(normalizedAttAuthorizationStatus);
121+
};
113122

114123
/*** BranchUniversalObject ***/
115-
createBranchUniversalObject = createBranchUniversalObject
124+
createBranchUniversalObject = createBranchUniversalObject;
116125

117126
/*** BranchQRCode ***/
118-
getBranchQRCode = (qrCodeSettings = {}, branchUniversalObject = {}, linkProperties = {}, controlParams = {}) => {
119-
return RNBranch.getBranchQRCode(qrCodeSettings, branchUniversalObject, linkProperties, controlParams);
120-
}
127+
getBranchQRCode = (
128+
qrCodeSettings = {},
129+
branchUniversalObject = {},
130+
linkProperties = {},
131+
controlParams = {}
132+
) => {
133+
return RNBranch.getBranchQRCode(
134+
qrCodeSettings,
135+
branchUniversalObject,
136+
linkProperties,
137+
controlParams
138+
);
139+
};
121140

122141
/*** PreInstall Parameters ***/
123-
setPreInstallCampaign = (campaign) => RNBranch.setPreinstallCampaign(campaign)
124-
setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner)
125-
142+
setPreInstallCampaign = (campaign) =>
143+
RNBranch.setPreinstallCampaign(campaign);
144+
setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner);
145+
146+
/*** DMA Consent Params ***/
147+
setDMAParamsForEEA = (
148+
eeaRegion,
149+
adPersonalizationConsent,
150+
adUserDataUsageConsent
151+
) => {
152+
const isValid =
153+
validateParam(eeaRegion, "eeaRegion") &&
154+
validateParam(adPersonalizationConsent, "adPersonalizationConsent") &&
155+
validateParam(adUserDataUsageConsent, "adUserDataUsageConsent");
156+
157+
if (isValid) {
158+
RNBranch.setDMAParamsForEEA(
159+
eeaRegion,
160+
adPersonalizationConsent,
161+
adUserDataUsageConsent
162+
);
163+
} else {
164+
console.warn("setDMAParamsForEEA: Unable to set DMA params.");
165+
}
166+
};
126167
}
127168

128-
export { Branch, BranchEvent, BranchSubscriber }
129-
export default new Branch()
169+
const validateParam = (param, paramName) => {
170+
if (param === true || param === false) {
171+
return true;
172+
} else {
173+
console.warn(
174+
`setDMAParamsForEEA: ${paramName} must be boolean, but got ${param}`
175+
);
176+
177+
return false;
178+
}
179+
};
180+
181+
export { Branch, BranchEvent, BranchSubscriber };
182+
export default new Branch();

0 commit comments

Comments
 (0)