Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-2249] Expose the setDMAParamsForEEA method #957

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved
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;

Check warning on line 40 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L40

Added line #L40 was not covered by tests
}
this._checkCachedEvents = false
this._checkCachedEvents = false;

Check warning on line 42 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L42

Added line #L42 was not covered by tests

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

Check warning on line 45 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L44-L45

Added lines #L44 - L45 were not covered by tests

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

Check warning on line 47 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L47

Added line #L47 was not covered by tests
}

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

Check warning on line 52 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L52

Added line #L52 was not covered by tests
}

/*** 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);

Check warning on line 61 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L61

Added line #L61 was not covered by tests
getFirstReferringParams = RNBranch.getFirstReferringParams;
lastAttributedTouchData = (attributionWindow = {}) =>
RNBranch.lastAttributedTouchData(attributionWindow);

Check warning on line 64 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L64

Added line #L64 was not covered by tests
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(

Check warning on line 68 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L68

Added line #L68 was not covered by tests
"[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);

Check warning on line 71 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L71

Added line #L71 was not covered by tests
};
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(

Check warning on line 74 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L74

Added line #L74 was not covered by tests
"[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);

Check warning on line 77 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L77

Added line #L77 was not covered by tests
};
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(

Check warning on line 80 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L80

Added line #L80 was not covered by tests
"[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);

Check warning on line 83 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L83

Added line #L83 was not covered by tests
};
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),

Check warning on line 91 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L91

Added line #L91 was not covered by tests
})();
};
handleATTAuthorizationStatus = (ATTAuthorizationStatus) => {
if (Platform.OS != 'ios') return;
let normalizedAttAuthorizationStatus = -1
if (Platform.OS != "ios") return;
let normalizedAttAuthorizationStatus = -1;

Check warning on line 96 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L96

Added line #L96 was not covered by tests

switch(ATTAuthorizationStatus) {
case 'authorized':
switch (ATTAuthorizationStatus) {
case "authorized":

Check warning on line 99 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L99

Added line #L99 was not covered by tests
normalizedAttAuthorizationStatus = 3;
break;
case 'denied':
case "denied":

Check warning on line 102 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L102

Added line #L102 was not covered by tests
normalizedAttAuthorizationStatus = 2;
break;
case 'undetermined':
case "undetermined":

Check warning on line 105 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L105

Added line #L105 was not covered by tests
normalizedAttAuthorizationStatus = 0;
break;
case 'restricted':
case "restricted":

Check warning on line 108 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L108

Added line #L108 was not covered by tests
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(

Check warning on line 114 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L114

Added line #L114 was not covered by tests
"[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted"
);
return;
}

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

Check warning on line 120 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L120

Added line #L120 was not covered by tests
};

/*** 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(

Check warning on line 133 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L128-L133

Added lines #L128 - L133 were not covered by tests
qrCodeSettings,
branchUniversalObject,
linkProperties,
controlParams
);
};

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

setPreInstallCampaign = (campaign) =>
RNBranch.setPreinstallCampaign(campaign);

Check warning on line 143 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L143

Added line #L143 was not covered by tests
setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner);

/*** DMA Consent Params ***/
setDMAParamsForEEA = (
eeaRegion,
adPersonalizationConsent,
adUserDataUsageConsent
) => {

Check warning on line 151 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L151

Added line #L151 was not covered by tests
const isValid =
validateParam(eeaRegion, "eeaRegion") &&
validateParam(adPersonalizationConsent, "adPersonalizationConsent") &&
validateParam(adUserDataUsageConsent, "adUserDataUsageConsent");

Check warning on line 155 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L154-L155

Added lines #L154 - L155 were not covered by tests

if (isValid) {
RNBranch.setDMAParamsForEEA(

Check warning on line 158 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L158

Added line #L158 was not covered by tests
eeaRegion,
adPersonalizationConsent,
adUserDataUsageConsent
);
} else {
console.warn("setDMAParamsForEEA: Unable to set DMA params.");

Check warning on line 164 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L163-L164

Added lines #L163 - L164 were not covered by tests
}
};
}

export { Branch, BranchEvent, BranchSubscriber }
export default new Branch()
const validateParam = (param, paramName) => {
if (param === true || param === false) {
return true;
} else {
console.warn(

Check warning on line 173 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L171-L173

Added lines #L171 - L173 were not covered by tests
`setDMAParamsForEEA: ${paramName} must be boolean, but got ${param}`
);

return false;

Check warning on line 177 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L177

Added line #L177 was not covered by tests
}
};

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