Skip to content

Commit

Permalink
[SDK-2253] Expose the setDMAParamsForEEA method (#727)
Browse files Browse the repository at this point in the history
* Added new method and updated native SDKs

* Added fix and changelog

* Updated ios to 3.2.0

* Removed setDebug

* Update index.js
  • Loading branch information
nsingh-branch authored Mar 1, 2024
1 parent 5ae8572 commit 3bcb05e
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 121 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

6.1.0 Feb 28, 2024
* Update Android SDK to 5.9.0
* Update iOS SDK to 3.2.0
* Added new method, setDMAParamsForEEA(), for setting DMA compliance parameters.
* Removed the deprecated setDebug() method

6.0.0 Dec 1, 2023
* Update Android SDK to 5.7.5
* Update iOS SDK to 3.0.1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "branch-cordova-sdk",
"description": "Branch Metrics Cordova SDK",
"main": "src/index.js",
"version": "6.0.0",
"version": "6.1.0",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="6.0.0">
version="6.1.0">

<!-- Description -->
<name>branch-cordova-sdk</name>
Expand Down Expand Up @@ -63,7 +63,7 @@ SOFTWARE.
<!-- Manifest configuration is done via a js script. We should move it to this config in the future. -->

<source-file src="src/android/io/branch/BranchSDK.java" target-dir="src/io/branch" />
<framework src="io.branch.sdk.android:library:5.7.5"/>
<framework src="io.branch.sdk.android:library:5.9.0"/>
</platform>

<!-- iOS -->
Expand All @@ -87,7 +87,7 @@ SOFTWARE.
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods>
<pod name="BranchSDK" spec="~> 3.0.1" />
<pod name="BranchSDK" spec="~> 3.2.0" />
</pods>
</podspec>
</platform>
Expand Down
20 changes: 20 additions & 0 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
}
cordova.getActivity().runOnUiThread(r);
return true;
} else if (action.equals("setDMAParamsForEEA")) {
if (args.length() != 3) {
callbackContext.error("Parameter count mismatch");
return false;
}
cordova.getActivity().runOnUiThread(r);
return true;
}

return true;
Expand Down Expand Up @@ -680,6 +687,17 @@ public void sendBranchEvent(String eventName, JSONObject metaData, CallbackConte
//callbackContext.success();
}

/**
* <p>Configures the handling of DMA parameters for users in the EEA region based on their consent.</p>
*
* @param eeaRegion A {@link Boolean} value indicating if the user is from the European Economic Area (EEA).
* @param adPersonalizationConsent A {@link Boolean} value indicating if the user has consented to ad personalization.
* @param adUserDataUsageConsent A {@link Boolean} value indicating if the user has consented to the usage of their data for ads.
*/
public void setDMAParamsForEEA(boolean eeaRegion, boolean adPersonalizationConsent, boolean adUserDataUsageConsent) {
Branch.getInstance().setDMAParamsForEEA(eeaRegion, adPersonalizationConsent, adUserDataUsageConsent);
}

private BranchUniversalObject getContentItem(JSONObject item) throws JSONException {
BranchUniversalObject universalObject = new BranchUniversalObject();
ContentMetadata contentMetadata = new ContentMetadata();
Expand Down Expand Up @@ -1129,6 +1147,8 @@ public void run() {
localization.put("shareWith", "Share With");
}
showShareSheet(this.args.getInt(0), this.args.getJSONObject(1), this.args.getJSONObject(2), localization);
} else if (this.action.equals("setDMAParamsForEEA")) {
setDMAParamsForEEA(this.args.getBoolean(0), this.args.getBoolean(1), this.args.getBoolean(2));
}
}
} catch (JSONException e) {
Expand Down
227 changes: 123 additions & 104 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const standardEvent = {
STANDARD_EVENT_INVITE: "INVITE",
STANDARD_EVENT_LOGIN: "LOGIN",
STANDARD_EVENT_SUBSCRIBE: "SUBSCRIBE",
STANDARD_EVENT_START_TRIAL: "START_TRIAL"
}
STANDARD_EVENT_START_TRIAL: "START_TRIAL",
};

// Branch prototype
var Branch = function Branch() {
Expand All @@ -45,7 +45,7 @@ function execute(method, params) {

if (method == "getStandardEvents") {
return new Promise(function promise(resolve, reject) {
resolve(standardEvent);
resolve(standardEvent);
});
}

Expand Down Expand Up @@ -93,7 +93,9 @@ Branch.prototype.disableTracking = function disableTracking(isEnabled) {

Branch.prototype.enableTestMode = function initSession() {
if (this.sessionInitialized) {
return executeReject("[enableTestMode] should be called before [initSession]");
return executeReject(
"[enableTestMode] should be called before [initSession]"
);
}
return execute("enableTestMode");
};
Expand All @@ -113,13 +115,6 @@ Branch.prototype.setRequestMetadata = function setRequestMetadata(key, val) {
return execute("setRequestMetadata", [key, val]);
};

// Deprecated. Replaced by setLogging(isEnabled) and test devices. https://help.branch.io/using-branch/docs/adding-test-devices
Branch.prototype.setDebug = function setDebug(isEnabled) {
return new Promise(function promise(resolve, reject) {
resolve(false);
});
};

// For early lifecycle logging, we recommend you enable logging in the native iOS or Android code.
Branch.prototype.setLogging = function setLogging(isEnabled) {
var value = typeof isEnabled !== "boolean" ? false : isEnabled;
Expand All @@ -137,26 +132,26 @@ Branch.prototype.setCookieBasedMatching = function setCookieBasedMatching(
};

//DEPRECATED
Branch.prototype.delayInitToCheckForSearchAds = function delayInitToCheckForSearchAds(
isEnabled
) {
// stub call from known issue calling it from JS
return new Promise(function promise(resolve, reject) {
resolve(false);
});
Branch.prototype.delayInitToCheckForSearchAds =
function delayInitToCheckForSearchAds(isEnabled) {
// stub call from known issue calling it from JS
return new Promise(function promise(resolve, reject) {
resolve(false);
});

// var value = typeof isEnabled !== "boolean" ? false : isEnabled;
// var value = typeof isEnabled !== "boolean" ? false : isEnabled;

// return execute("delayInitToCheckForSearchAds", [value]);
};
// return execute("delayInitToCheckForSearchAds", [value]);
};

Branch.prototype.getFirstReferringParams = function getFirstReferringParams() {
return execute("getFirstReferringParams");
};

Branch.prototype.getLatestReferringParams = function getLatestReferringParams() {
return execute("getLatestReferringParams");
};
Branch.prototype.getLatestReferringParams =
function getLatestReferringParams() {
return execute("getLatestReferringParams");
};

Branch.prototype.setIdentity = function setIdentity(identity) {
if (identity) {
Expand All @@ -171,13 +166,9 @@ Branch.prototype.logout = function logout() {

Branch.prototype.getStandardEvents = function getStandardEvents() {
return execute("getStandardEvents");

};

Branch.prototype.sendBranchEvent = function sendBranchEvent(
action,
metaData
) {
Branch.prototype.sendBranchEvent = function sendBranchEvent(action, metaData) {
var args = [action];
if (!action) {
return executeReject("Please set a standard event");
Expand All @@ -190,86 +181,85 @@ Branch.prototype.sendBranchEvent = function sendBranchEvent(
return execute("sendBranchEvent", args);
};

Branch.prototype.createBranchUniversalObject = function createBranchUniversalObject(
options
) {
return new Promise(function promise(resolve, reject) {
execute("createBranchUniversalObject", [options]).then(
function success(res) {
var obj = {
message: res.message,
instanceId: res.branchUniversalObjectId
};

obj.registerView = function registerView() {
return execute("registerView", [obj.instanceId]);
};

obj.generateShortUrl = function generateShortUrl(
analytics,
properties
) {
return execute("generateShortUrl", [
obj.instanceId,
Branch.prototype.createBranchUniversalObject =
function createBranchUniversalObject(options) {
return new Promise(function promise(resolve, reject) {
execute("createBranchUniversalObject", [options]).then(
function success(res) {
var obj = {
message: res.message,
instanceId: res.branchUniversalObjectId,
};

obj.registerView = function registerView() {
return execute("registerView", [obj.instanceId]);
};

obj.generateShortUrl = function generateShortUrl(
analytics,
properties
]);
};

obj.showShareSheet = function showShareSheet(
analytics,
properties,
shareText
) {
var message = !shareText ? "This stuff is awesome: " : shareText;

return execute("showShareSheet", [
obj.instanceId,
) {
return execute("generateShortUrl", [
obj.instanceId,
analytics,
properties,
]);
};

obj.showShareSheet = function showShareSheet(
analytics,
properties,
message
]);
};

obj.onShareSheetLaunched = function onShareSheetLaunched(callback) {
if (deviceVendor.indexOf("Apple") < 0) {
executeCallback("onShareLinkDialogLaunched", callback, [
obj.instanceId
shareText
) {
var message = !shareText ? "This stuff is awesome: " : shareText;

return execute("showShareSheet", [
obj.instanceId,
analytics,
properties,
message,
]);
}
};

obj.onShareSheetDismissed = function onShareSheetDismissed(callback) {
executeCallback("onShareLinkDialogDismissed", callback, [
obj.instanceId
]);
};

obj.onLinkShareResponse = function onLinkShareResponse(callback) {
executeCallback("onLinkShareResponse", callback, [obj.instanceId]);
};

obj.onChannelSelected = function onChannelSelected(callback) {
if (deviceVendor.indexOf("Apple") < 0) {
executeCallback("onChannelSelected", callback, [obj.instanceId]);
}
};

obj.listOnSpotlight = function listOnSpotlight() {
if (!(deviceVendor.indexOf("Apple") < 0)) {
return execute("listOnSpotlight", [obj.instanceId]);
}
return executeReject("iOS Spotlight only");
};

resolve(obj);
},
function failure(err) {
reject(err);
}
);
});
};
};

obj.onShareSheetLaunched = function onShareSheetLaunched(callback) {
if (deviceVendor.indexOf("Apple") < 0) {
executeCallback("onShareLinkDialogLaunched", callback, [
obj.instanceId,
]);
}
};

obj.onShareSheetDismissed = function onShareSheetDismissed(callback) {
executeCallback("onShareLinkDialogDismissed", callback, [
obj.instanceId,
]);
};

obj.onLinkShareResponse = function onLinkShareResponse(callback) {
executeCallback("onLinkShareResponse", callback, [obj.instanceId]);
};

obj.onChannelSelected = function onChannelSelected(callback) {
if (deviceVendor.indexOf("Apple") < 0) {
executeCallback("onChannelSelected", callback, [obj.instanceId]);
}
};

obj.listOnSpotlight = function listOnSpotlight() {
if (!(deviceVendor.indexOf("Apple") < 0)) {
return execute("listOnSpotlight", [obj.instanceId]);
}
return executeReject("iOS Spotlight only");
};

resolve(obj);
},
function failure(err) {
reject(err);
}
);
});
};

Branch.prototype.crossPlatformIds = function crossPlatformIds() {
return execute("crossPlatformIds");
Expand Down Expand Up @@ -302,6 +292,35 @@ Branch.prototype.getBranchQRCode = function getBranchQRCode(
return execute("getBranchQRCode", args);
};

Branch.prototype.setDMAParamsForEEA = function setDMAParamsForEEA(
eeaRegion,
adPersonalizationConsent,
adUserDataUsageConsent
) {
const isValid =
validateParam(eeaRegion, "eeaRegion") &&
validateParam(adPersonalizationConsent, "adPersonalizationConsent") &&
validateParam(adUserDataUsageConsent, "adUserDataUsageConsent");

if (isValid) {
var args = [eeaRegion, adPersonalizationConsent, adUserDataUsageConsent];
return execute("setDMAParamsForEEA", args);
} else {
return executeReject("Unable to set DMA Params");
}
};

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 object
module.exports = new Branch();
1 change: 1 addition & 0 deletions src/ios/BranchSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- (void)setIdentity:(CDVInvokedUrlCommand*)command;
- (void)registerDeepLinkController:(CDVInvokedUrlCommand*)command;
- (void)logout:(CDVInvokedUrlCommand*)command;
- (void)setDMAParamsForEEA:(CDVInvokedUrlCommand*)command;

// Branch Universal Object Methods
- (void)createBranchUniversalObject:(CDVInvokedUrlCommand*)command;
Expand Down
Loading

0 comments on commit 3bcb05e

Please sign in to comment.