Skip to content

Commit

Permalink
Merge pull request #404 from BranchMetrics/setRequestMetadata
Browse files Browse the repository at this point in the history
Set request metadata
  • Loading branch information
ethanneff authored Dec 8, 2017
2 parents 5802163 + c8fe13e commit 35c90ee
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 16 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@
// for better Android matching
Branch.setCookieBasedMatching('cordova.app.link')

// to sync with Mixpanel if plugin is installed
Branch.setMixpanelToken('your_mixpanel_token')

// Branch initialization
Branch.initSession(function(data) {
if (data['+clicked_branch_link']) {
Expand Down Expand Up @@ -1072,6 +1069,14 @@
| 176 | ZAR |
| 177 | ZMW |

- #### Link data: Mixpanel Integration

- Sync with Mixpanel if plugin is installed

```js
Branch.setRequestMetadata("$mixpanel_distinct_id", "123")
```

- #### Compiling: Cordova Dependencies

- Node
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/branch.js",
"version": "2.6.19",
"version": "2.6.20",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion plugin.template.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="2.6.19">
version="2.6.20">

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

Expand Down
2 changes: 1 addition & 1 deletion 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="2.6.19">
version="2.6.20">

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

Expand Down
10 changes: 5 additions & 5 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("initSession")) {
cordova.getActivity().runOnUiThread(r);
return true;
} else if (action.equals("setMixpanelToken")) {
} else if (action.equals("setRequestMetadata")) {
cordova.getActivity().runOnUiThread(r);
return true;
} else {
Expand Down Expand Up @@ -611,9 +611,9 @@ private void setIdentity(String newIdentity, CallbackContext callbackContext) {
* @param token A {@link String} value containing the unique identifier of the Mixpanel user.
* @param callbackContext A callback to execute at the end of this method
*/
private void setMixpanelToken(String token, CallbackContext callbackContext) {
private void setRequestMetadata(String key, String val, CallbackContext callbackContext) {

Branch.getInstance().setRequestMetadata("$mixpanel_distinct_id", token);
Branch.getInstance().setRequestMetadata(key, val);

callbackContext.success("Success");

Expand Down Expand Up @@ -1258,8 +1258,8 @@ public void run() {
setDebug(this.args.getBoolean(0), this.callbackContext);
} else if (this.action.equals("initSession")) {
initSession(this.callbackContext);
} else if (this.action.equals("setMixpanelToken")) {
setMixpanelToken(this.args.getString(0), this.callbackContext);
} else if (this.action.equals("setRequestMetadata")) {
setRequestMetadata(this.args.getString(0), this.args.getString(1), this.callbackContext);
} else {
if (this.action.equals("setIdentity")) {
setIdentity(this.args.getString(0), this.callbackContext);
Expand Down
17 changes: 16 additions & 1 deletion src/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,23 @@ Branch.prototype.initSession = function (deepLinkDataListener) {
return execute('initSession')
}

// deprecated for setRequestMetadata()
Branch.prototype.setMixpanelToken = function (token) {
return execute('setMixpanelToken', [token])
return this.setRequestMetadata('$mixpanel_distinct_id', token)
}

Branch.prototype.setRequestMetadata = function (key, val) {
if (!key || typeof key !== 'string') {
return new Promise(function (resolve, reject) {
reject(new Error('Please set key'))
})
}
if (!val || typeof val !== 'string') {
return new Promise(function (resolve, reject) {
reject(new Error('Please set value'))
})
}
return execute('setRequestMetadata', [key, val])
}

Branch.prototype.setDebug = function (isEnabled) {
Expand Down
4 changes: 2 additions & 2 deletions src/ios/BranchSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
}];
}

- (void)setMixpanelToken:(CDVInvokedUrlCommand*)command
- (void)setRequestMetadata:(CDVInvokedUrlCommand*)command
{

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

}

Expand Down
1 change: 0 additions & 1 deletion testbed/config.template.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<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">
<!-- Branch -->
<plugin name="branch-cordova-sdk" />
<branch-config>
<branch-key value="key_live_ndqptlgXNE4LHqIahH1WIpbiyFlb62J3" />
<uri-scheme value="branchcordova" />
Expand Down
2 changes: 1 addition & 1 deletion testbed/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function BranchInit (isDebug) {
Branch.setCookieBasedMatching('cordova.app.link')

// sync with Mixpanel if installed
Branch.setMixpanelToken('your_mixpanel_token')
Branch.setRequestMetadata('$mixpanel_distinct_id', 'your_mixpanel_token')

// Branch initialization
Branch.initSession(function (data) {
Expand Down

0 comments on commit 35c90ee

Please sign in to comment.