Skip to content

Commit

Permalink
[SDK-2249] Expose the setDMAParamsForEEA method (#957)
Browse files Browse the repository at this point in the history
* Added setDMAParamsForEEA

* Updated native SDKs

* Removed setDebug

* Update react-native-branch.podspec

* Update index.js
  • Loading branch information
nsingh-branch authored Mar 1, 2024
1 parent 247c090 commit 4db1afe
Show file tree
Hide file tree
Showing 9 changed files with 687 additions and 614 deletions.
1,053 changes: 560 additions & 493 deletions ChangeLog.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def safeExtGet(prop, fallback) {
dependencies {
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'com.facebook.react:react-native:+' // From node_modules
api 'io.branch.sdk.android:library:5.7.1'
api 'io.branch.sdk.android:library:5.9.0'
}
14 changes: 6 additions & 8 deletions android/src/main/java/io/branch/rnbranch/RNBranchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,6 @@ private static void notifyJSOfInitSessionStart(Context context, Uri uri) {
LocalBroadcastManager.getInstance(context).sendBroadcast(broadcastIntent);
}

/**
* @deprecated setDebug is deprecated and all functionality has been disabled. If you wish to enable
* logging, please invoke enableLogging. If you wish to simulate installs, please Test Devices
* (https://help.branch.io/using-branch/docs/adding-test-devices)
*/
@Deprecated
public static void setDebug() { }

public static void enableLogging() {
Branch.enableLogging();
}
Expand Down Expand Up @@ -1253,4 +1245,10 @@ private static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSON
}
return array;
}

@ReactMethod
public void setDMAParamsForEEA(boolean eeaRegion, boolean adPersonalizationConsent, boolean adUserDataUsageConsent) {
Branch branch = Branch.getInstance();
branch.setDMAParamsForEEA(eeaRegion, adPersonalizationConsent, adUserDataUsageConsent);
}
}
45 changes: 0 additions & 45 deletions docs/setDebug.md

This file was deleted.

1 change: 0 additions & 1 deletion ios/RNBranch.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern NSString * _Nonnull const RNBranchLinkOpenedNotificationLinkPropertiesKey
+ (void)useTestInstance;
+ (void)deferInitializationForJSLoad;

+ (void)setDebug;
+ (void)enableLogging;

@end
10 changes: 5 additions & 5 deletions ios/RNBranch.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ + (BOOL)requiresMainQueueSetup {

#pragma mark - Class methods

+ (void)setDebug
{
[self.branch setDebug];
}

+ (void)enableLogging
{
[self.branch enableLogging];
Expand Down Expand Up @@ -744,4 +739,9 @@ - (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start le
return hexComponent / 255.0;
}

#pragma mark setDMAParamsForEEA
RCT_EXPORT_METHOD(setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPersonalizationConsent AdUserDataUsageConsent:(BOOL)adUserDataUsageConsent) {
[Branch setDMAParamsForEEA:eeaRegion AdPersonalizationConsent:adPersonalizationConsent AdUserDataUsageConsent:adUserDataUsageConsent];
}

@end
2 changes: 1 addition & 1 deletion react-native-branch.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Pod::Spec.new do |s|
s.source_files = [ "ios/*.h", "ios/*.m"]
s.compiler_flags = %[-DRNBRANCH_VERSION=@\\"#{s.version}\\"]
s.header_dir = 'RNBranch' # also sets generated module name
s.dependency 'BranchSDK', '3.0.0'
s.dependency 'BranchSDK', '3.2.0'
s.dependency 'React-Core' # to ensure the correct build order

# Swift/Objective-C compatibility
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ interface Branch {
) => Promise<string>;
setPreInstallCampaign: (campaign: string) => void;
setPreInstallPartner: (partner: string) => void;
setDMAParamsForEEA: (eeaRegion: boolean, adPersonalizationConsent: boolean, adUserDataUsageConsent: boolean) => void;
}
declare const branch: Branch;
export default branch;
173 changes: 113 additions & 60 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,129 +1,182 @@
import { NativeModules, Platform } from 'react-native'
import { NativeModules, Platform } from "react-native";

Check failure on line 1 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

const { RNBranch } = NativeModules
const { RNBranch } = NativeModules;

import createBranchUniversalObject from './branchUniversalObject'
import BranchEvent from './BranchEvent'
import BranchSubscriber from './BranchSubscriber'
import createBranchUniversalObject from "./branchUniversalObject";

Check failure on line 5 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
import BranchEvent from "./BranchEvent";

Check failure on line 6 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
import BranchSubscriber from "./BranchSubscriber";

Check failure on line 7 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

const packageFile = require('./../package.json')
export const VERSION = packageFile.version
const packageFile = require("./../package.json");

Check failure on line 9 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
export const VERSION = packageFile.version;

class Branch {
key = null;
_checkCachedEvents = true;
_debug = false;

constructor(options = {}) {
if (options.debug) this._debug = true
if (options.debug) this._debug = true;

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

Check failure on line 20 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
}

subscribe(options) {
if (typeof options === 'function') {
if (typeof options === "function") {

Check failure on line 24 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
/*
* Support for legacy API, passing a single callback function:
* branch.subscribe(({params, error, uri}) => { ... }). This is
* the same as the onOpenComplete callback.
*/
options = {
onOpenComplete: options,
}
};
}

/*
* You can specify checkCachedEvents in the subscribe options to control
* this per subscriber.
*/
if (!('checkCachedEvents' in options)) {
options.checkCachedEvents = this._checkCachedEvents
if (!("checkCachedEvents" in options)) {

Check failure on line 39 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
options.checkCachedEvents = this._checkCachedEvents;
}
this._checkCachedEvents = false
this._checkCachedEvents = false;

const subscriber = new BranchSubscriber(options)
subscriber.subscribe()
const subscriber = new BranchSubscriber(options);
subscriber.subscribe();

return () => subscriber.unsubscribe()
return () => subscriber.unsubscribe();
}

skipCachedEvents() {
/*** Sets to ignore cached events. ***/
this._checkCachedEvents = false
this._checkCachedEvents = false;
}

/*** Tracking related methods ***/
disableTracking = (disable) => RNBranch.disableTracking(disable)
isTrackingDisabled = RNBranch.isTrackingDisabled
disableTracking = (disable) => RNBranch.disableTracking(disable);
isTrackingDisabled = RNBranch.isTrackingDisabled;

/*** RNBranch singleton methods ***/
setDebug = () => { throw 'setDebug() is not supported in the RN SDK. For other solutions, please see https://rnbranch.app.link/setDebug' }
getLatestReferringParams = (synchronous = false) => RNBranch.getLatestReferringParams(synchronous)
getFirstReferringParams = RNBranch.getFirstReferringParams
lastAttributedTouchData = (attributionWindow = {}) => RNBranch.lastAttributedTouchData(attributionWindow)
setIdentity = (identity) => RNBranch.setIdentity(identity)
setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity)
getLatestReferringParams = (synchronous = false) =>
RNBranch.getLatestReferringParams(synchronous);
getFirstReferringParams = RNBranch.getFirstReferringParams;
lastAttributedTouchData = (attributionWindow = {}) =>
RNBranch.lastAttributedTouchData(attributionWindow);
setIdentity = (identity) => RNBranch.setIdentity(identity);
setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity);
setRequestMetadata = (key, value) => {
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.')
return RNBranch.setRequestMetadataKey(key, value)
}
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."

Check failure on line 69 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
);
return RNBranch.setRequestMetadataKey(key, value);
};
addFacebookPartnerParameter = (name, value) => {
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.')
return RNBranch.addFacebookPartnerParameter(name, value)
}
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."

Check failure on line 75 in src/index.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
);
return RNBranch.addFacebookPartnerParameter(name, value);
};
addSnapPartnerParameter = (name, value) => {
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.')
return RNBranch.addSnapPartnerParameter(name, value)
}
clearPartnerParameters = RNBranch.clearPartnerParameters
logout = RNBranch.logout
getShortUrl = RNBranch.getShortUrl
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."
);
return RNBranch.addSnapPartnerParameter(name, value);
};
clearPartnerParameters = RNBranch.clearPartnerParameters;
logout = RNBranch.logout;
getShortUrl = RNBranch.getShortUrl;
openURL = (url, options = {}) => {
return Platform.select({
android: () => RNBranch.openURL(url, options),
ios: () => RNBranch.openURL(url)
})()
}
ios: () => RNBranch.openURL(url),
})();
};
handleATTAuthorizationStatus = (ATTAuthorizationStatus) => {
if (Platform.OS != 'ios') return;
let normalizedAttAuthorizationStatus = -1
if (Platform.OS != "ios") return;
let normalizedAttAuthorizationStatus = -1;

switch(ATTAuthorizationStatus) {
case 'authorized':
switch (ATTAuthorizationStatus) {
case "authorized":
normalizedAttAuthorizationStatus = 3;
break;
case 'denied':
case "denied":
normalizedAttAuthorizationStatus = 2;
break;
case 'undetermined':
case "undetermined":
normalizedAttAuthorizationStatus = 0;
break;
case 'restricted':
case "restricted":
normalizedAttAuthorizationStatus = 1;
break;
}

if (normalizedAttAuthorizationStatus < 0) {
console.info('[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted')
console.info(
"[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted"
);
return;
}

RNBranch.handleATTAuthorizationStatus(normalizedAttAuthorizationStatus)
}
RNBranch.handleATTAuthorizationStatus(normalizedAttAuthorizationStatus);
};

/*** BranchUniversalObject ***/
createBranchUniversalObject = createBranchUniversalObject
createBranchUniversalObject = createBranchUniversalObject;

/*** BranchQRCode ***/
getBranchQRCode = (qrCodeSettings = {}, branchUniversalObject = {}, linkProperties = {}, controlParams = {}) => {
return RNBranch.getBranchQRCode(qrCodeSettings, branchUniversalObject, linkProperties, controlParams);
}
getBranchQRCode = (
qrCodeSettings = {},
branchUniversalObject = {},
linkProperties = {},
controlParams = {}
) => {
return RNBranch.getBranchQRCode(
qrCodeSettings,
branchUniversalObject,
linkProperties,
controlParams
);
};

/*** PreInstall Parameters ***/
setPreInstallCampaign = (campaign) => RNBranch.setPreinstallCampaign(campaign)
setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner)

setPreInstallCampaign = (campaign) =>
RNBranch.setPreinstallCampaign(campaign);
setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner);

/*** DMA Consent Params ***/
setDMAParamsForEEA = (
eeaRegion,
adPersonalizationConsent,
adUserDataUsageConsent
) => {
const isValid =
validateParam(eeaRegion, "eeaRegion") &&
validateParam(adPersonalizationConsent, "adPersonalizationConsent") &&
validateParam(adUserDataUsageConsent, "adUserDataUsageConsent");

if (isValid) {
RNBranch.setDMAParamsForEEA(
eeaRegion,
adPersonalizationConsent,
adUserDataUsageConsent
);
} else {
console.warn("setDMAParamsForEEA: Unable to set DMA params.");
}
};
}

export { Branch, BranchEvent, BranchSubscriber }
export default new Branch()
const validateParam = (param, paramName) => {
if (param === true || param === false) {
return true;
} else {
console.warn(
`setDMAParamsForEEA: ${paramName} must be boolean, but got ${param}`
);

return false;
}
};

export { Branch, BranchEvent, BranchSubscriber };
export default new Branch();

0 comments on commit 4db1afe

Please sign in to comment.