Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Renemari Padillo committed Aug 8, 2016
2 parents 17d8725 + 836ddaf commit ef4cdbf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Branch.getFirstReferringParams().then(function (res) {
1. Branch Session
+ [setDebug](#setDebug)
+ [initSession](#initSession)
+ [setMixpanelToken](#setMixpanelToken)
+ [getLatestReferringParams](#getLatestReferringParams)
+ [getFirstReferringParams](#getFirstReferringParams)
+ [setIdentity](#setIdentity)
Expand Down Expand Up @@ -235,6 +236,17 @@ function DeepLinkHandler(data) {
}
```

### <a id="setMixpanelToken"></a>setMixpanelToken()

Allow Branch SDK to pass the user's Mixpanel distinct id to our servers. Branch will then pass that Distinct ID to Mixpanel when logging any event.
**Note:** This should be initialized first before `initSession()` or else Mixpanel integration won't work.

##### Usage

```js
Branch.setMixpanelToken('<your-mixpanel-token-here>');
```

### <a id="getFirstReferringParams"></a>getFirstReferringParams()

Retrieves the install session parameters.
Expand Down
2 changes: 0 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ SOFTWARE.
</intent-filter>
</config-file>
<source-file src="src/android/io/branch/BranchSDK.java" target-dir="src/io/branch" />
<framework src="com.mixpanel.android:mixpanel-android:4.+" type="gradleReference" />
<framework src="com.google.android.gms:play-services:3.1+" type="gradleReference" />
<framework src="io.branch.sdk.android:library:1+" />
</platform>

Expand Down
16 changes: 5 additions & 11 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import io.branch.referral.SharingHelper;
import io.branch.referral.util.ShareSheetStyle;

import com.mixpanel.android.mpmetrics.MixpanelAPI;

public class BranchSDK extends CordovaPlugin
{

Expand Down Expand Up @@ -108,7 +106,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("initSession")) {
cordova.getThreadPool().execute(r);
return true;
} else if (action.equals("getMixpanelInstance")) {
} else if (action.equals("setMixpanelToken")) {
cordova.getThreadPool().execute(r);
return true;
} else {
Expand Down Expand Up @@ -597,14 +595,10 @@ 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 getMixpanelInstance(String token, CallbackContext callbackContext)
private void setMixpanelToken(String token, CallbackContext callbackContext)
{

Log.d(LCAT, "Getting Mixpanel instance");

MixpanelAPI mp = MixpanelAPI.getInstance(this.activity.getApplicationContext(), token);

Branch.getInstance().setRequestMetadata("$mixpanel_distinct_id", mp.getDistinctId());
Branch.getInstance().setRequestMetadata("$mixpanel_distinct_id", token);

callbackContext.success("Success");

Expand Down Expand Up @@ -1167,8 +1161,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("getMixpanelInstance")) {
getMixpanelInstance(this.args.getString(0), this.callbackContext);
} else if (this.action.equals("setMixpanelToken")) {
setMixpanelToken(this.args.getString(0), this.callbackContext);
} else {
if (this.action.equals("setIdentity")) {
setIdentity(this.args.getString(0), this.callbackContext);
Expand Down
1 change: 1 addition & 0 deletions src/ios/BranchSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

// BranchSDK Basic Methods
- (void)initSession:(CDVInvokedUrlCommand*)command;
- (void)setMixpanelToken:(CDVInvokedUrlCommand*)command;
- (void)setDebug:(CDVInvokedUrlCommand*)command;
- (void)getAutoInstance:(CDVInvokedUrlCommand*)command;
- (void)getLatestReferringParams:(CDVInvokedUrlCommand*)command;
Expand Down
7 changes: 7 additions & 0 deletions src/ios/BranchSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
}];
}

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

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

}

- (void)setDebug:(CDVInvokedUrlCommand*)command
{
bool enableDebug = [[command.arguments objectAtIndex:0] boolValue] == YES;
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 @@ -82,7 +82,7 @@ function InitSession()
{
console.log('Trigger InitSession()');

Branch.getMixpanelInstance('<your-mixpanel-token>');
Branch.setMixpanelToken('<your-mixpanel-token-here>');
Branch.initSession().then(function (res) {
console.log(res);
alert('Response: ' + JSON.stringify(res));
Expand Down
4 changes: 2 additions & 2 deletions www/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ Branch.prototype.initSession = function () {
*
* @return (Promise)
*/
Branch.prototype.getMixpanelInstance = function (token) {
Branch.prototype.setMixpanelToken = function (token) {

return execute('getMixpanelInstance', [token]);
return execute('setMixpanelToken', [token]);

};

Expand Down

0 comments on commit ef4cdbf

Please sign in to comment.