Skip to content

Commit 35c90ee

Browse files
authored
Merge pull request #404 from BranchMetrics/setRequestMetadata
Set request metadata
2 parents 5802163 + c8fe13e commit 35c90ee

File tree

9 files changed

+35
-16
lines changed

9 files changed

+35
-16
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@
255255
// for better Android matching
256256
Branch.setCookieBasedMatching('cordova.app.link')
257257

258-
// to sync with Mixpanel if plugin is installed
259-
Branch.setMixpanelToken('your_mixpanel_token')
260-
261258
// Branch initialization
262259
Branch.initSession(function(data) {
263260
if (data['+clicked_branch_link']) {
@@ -1072,6 +1069,14 @@
10721069
| 176 | ZAR |
10731070
| 177 | ZMW |
10741071

1072+
- #### Link data: Mixpanel Integration
1073+
1074+
- Sync with Mixpanel if plugin is installed
1075+
1076+
```js
1077+
Branch.setRequestMetadata("$mixpanel_distinct_id", "123")
1078+
```
1079+
10751080
- #### Compiling: Cordova Dependencies
10761081

10771082
- Node

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "branch-cordova-sdk",
33
"description": "Branch Metrics Cordova SDK",
44
"main": "src/branch.js",
5-
"version": "2.6.19",
5+
"version": "2.6.20",
66
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
77
"repository": {
88
"type": "git",

plugin.template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.6.19">
27+
version="2.6.20">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.6.19">
27+
version="2.6.20">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

src/android/io/branch/BranchSDK.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
115115
} else if (action.equals("initSession")) {
116116
cordova.getActivity().runOnUiThread(r);
117117
return true;
118-
} else if (action.equals("setMixpanelToken")) {
118+
} else if (action.equals("setRequestMetadata")) {
119119
cordova.getActivity().runOnUiThread(r);
120120
return true;
121121
} else {
@@ -611,9 +611,9 @@ private void setIdentity(String newIdentity, CallbackContext callbackContext) {
611611
* @param token A {@link String} value containing the unique identifier of the Mixpanel user.
612612
* @param callbackContext A callback to execute at the end of this method
613613
*/
614-
private void setMixpanelToken(String token, CallbackContext callbackContext) {
614+
private void setRequestMetadata(String key, String val, CallbackContext callbackContext) {
615615

616-
Branch.getInstance().setRequestMetadata("$mixpanel_distinct_id", token);
616+
Branch.getInstance().setRequestMetadata(key, val);
617617

618618
callbackContext.success("Success");
619619

@@ -1258,8 +1258,8 @@ public void run() {
12581258
setDebug(this.args.getBoolean(0), this.callbackContext);
12591259
} else if (this.action.equals("initSession")) {
12601260
initSession(this.callbackContext);
1261-
} else if (this.action.equals("setMixpanelToken")) {
1262-
setMixpanelToken(this.args.getString(0), this.callbackContext);
1261+
} else if (this.action.equals("setRequestMetadata")) {
1262+
setRequestMetadata(this.args.getString(0), this.args.getString(1), this.callbackContext);
12631263
} else {
12641264
if (this.action.equals("setIdentity")) {
12651265
setIdentity(this.args.getString(0), this.callbackContext);

src/branch.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,23 @@ Branch.prototype.initSession = function (deepLinkDataListener) {
7575
return execute('initSession')
7676
}
7777

78+
// deprecated for setRequestMetadata()
7879
Branch.prototype.setMixpanelToken = function (token) {
79-
return execute('setMixpanelToken', [token])
80+
return this.setRequestMetadata('$mixpanel_distinct_id', token)
81+
}
82+
83+
Branch.prototype.setRequestMetadata = function (key, val) {
84+
if (!key || typeof key !== 'string') {
85+
return new Promise(function (resolve, reject) {
86+
reject(new Error('Please set key'))
87+
})
88+
}
89+
if (!val || typeof val !== 'string') {
90+
return new Promise(function (resolve, reject) {
91+
reject(new Error('Please set value'))
92+
})
93+
}
94+
return execute('setRequestMetadata', [key, val])
8095
}
8196

8297
Branch.prototype.setDebug = function (isEnabled) {

src/ios/BranchSDK.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
126126
}];
127127
}
128128

129-
- (void)setMixpanelToken:(CDVInvokedUrlCommand*)command
129+
- (void)setRequestMetadata:(CDVInvokedUrlCommand*)command
130130
{
131131

132-
[[Branch getInstance] setRequestMetadataKey:@"$mixpanel_distinct_id" value:[command.arguments objectAtIndex:0]];
132+
[[Branch getInstance] setRequestMetadataKey:[command.arguments objectAtIndex:0] value:[command.arguments objectAtIndex:1]];
133133

134134
}
135135

testbed/config.template.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version='1.0' encoding='utf-8'?>
22
<widget id="com.eneff.branch.cordovatestbed" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
33
<!-- Branch -->
4-
<plugin name="branch-cordova-sdk" />
54
<branch-config>
65
<branch-key value="key_live_ndqptlgXNE4LHqIahH1WIpbiyFlb62J3" />
76
<uri-scheme value="branchcordova" />

testbed/www/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function BranchInit (isDebug) {
3131
Branch.setCookieBasedMatching('cordova.app.link')
3232

3333
// sync with Mixpanel if installed
34-
Branch.setMixpanelToken('your_mixpanel_token')
34+
Branch.setRequestMetadata('$mixpanel_distinct_id', 'your_mixpanel_token')
3535

3636
// Branch initialization
3737
Branch.initSession(function (data) {

0 commit comments

Comments
 (0)