Skip to content

Commit

Permalink
Merge pull request #169 from renesansz/feat/mixpanel-integration
Browse files Browse the repository at this point in the history
Mixpanel integration
  • Loading branch information
aaustin authored Aug 7, 2016
2 parents 56d9e9c + 93d2004 commit 836ddaf
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 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
22 changes: 22 additions & 0 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("initSession")) {
cordova.getThreadPool().execute(r);
return true;
} else if (action.equals("setMixpanelToken")) {
cordova.getThreadPool().execute(r);
return true;
} else {
if (this.instance != null) {
if (action.equals("setIdentity")) {
Expand Down Expand Up @@ -586,6 +589,21 @@ private void setIdentity(String newIdentity, CallbackContext callbackContext)

}

/**
* <p>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.</p>
*
* @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)
{

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

callbackContext.success("Success");

}

/**
* <p>A void call to indicate that the user has performed a specific action and for that to be
* reported to the Branch API.</p>
Expand All @@ -598,6 +616,7 @@ private void userCompletedAction(String action, CallbackContext callbackContext)
{

this.instance.userCompletedAction(action);

callbackContext.success("Success");

}
Expand All @@ -616,6 +635,7 @@ private void userCompletedAction(String action, JSONObject metaData, CallbackCon
{

this.instance.userCompletedAction(action, metaData);

callbackContext.success("Success");

}
Expand Down Expand Up @@ -1141,6 +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("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
1 change: 1 addition & 0 deletions testbed/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function InitSession()
{
console.log('Trigger InitSession()');

Branch.setMixpanelToken('<your-mixpanel-token-here>');
Branch.initSession().then(function (res) {
console.log(res);
alert('Response: ' + JSON.stringify(res));
Expand Down
14 changes: 14 additions & 0 deletions www/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ Branch.prototype.initSession = function () {

};

/**
* Get Mixpanel tolen/assisstance.
* NOTE: This must be called before initSession
*
* @param (String) token. Default = false
*
* @return (Promise)
*/
Branch.prototype.setMixpanelToken = function (token) {

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

};

/**
* Set debug mode.
* NOTE: This must be called before initSession
Expand Down

0 comments on commit 836ddaf

Please sign in to comment.