Skip to content

Commit

Permalink
Merge pull request #349 from sequoiaat/support-for-v2-events
Browse files Browse the repository at this point in the history
Support for v2 events
  • Loading branch information
aaaronlopez committed Jul 20, 2018
2 parents 86d8fd6 + 0818b7e commit 734583b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
6 changes: 3 additions & 3 deletions android/src/main/java/io/branch/rnbranch/RNBranchModule.java
Expand Up @@ -579,9 +579,9 @@ public static BranchEvent createBranchEvent(String eventName, ReadableMap params
if (params.hasKey("shipping")) event.setShipping(Double.parseDouble(params.getString("shipping")));
if (params.hasKey("tax")) event.setTax(Double.parseDouble(params.getString("tax")));
if (params.hasKey("coupon")) event.setCoupon(params.getString("coupon"));
if (params.hasKey("affiliation")) event.setTransactionID(params.getString("affiliation"));
if (params.hasKey("description")) event.setTransactionID(params.getString("description"));
if (params.hasKey("searchQuery")) event.setTransactionID(params.getString("searchQuery"));
if (params.hasKey("affiliation")) event.setAffiliation(params.getString("affiliation"));
if (params.hasKey("description")) event.setDescription(params.getString("description"));
if (params.hasKey("searchQuery")) event.setSearchQuery(params.getString("searchQuery"));

if (params.hasKey("customData")) {
ReadableMap customData = params.getMap("customData");
Expand Down
66 changes: 65 additions & 1 deletion examples/testbed_simple/src/BranchMethods.js
Expand Up @@ -3,7 +3,7 @@ import { ScrollView, StyleSheet, Text, View } from 'react-native'

import Button from './Button'

import branch, { RegisterViewEvent } from 'react-native-branch'
import branch, { RegisterViewEvent, BranchEvent } from 'react-native-branch'

const defaultBUO = {
title: 'wallo'
Expand Down Expand Up @@ -154,6 +154,68 @@ class BranchMethods extends Component {
}
}

logStandardEvent = async () => {
if (!this.buo) await this.createBranchUniversalObject()
try {
let branchEvent = new BranchEvent(
BranchEvent.Purchase,
this.buo,
{
transactionID: '12344555',
currency: 'USD',
revenue: 1.5,
shipping: 10.2,
tax: 12.3,
coupon: 'test_coupon',
affiliation: 'test_affiliation',
description: 'Test purchase event',
searchQuery: 'test keyword',
customData: {
"Custom_Event_Property_Key1": "Custom_Event_Property_val1",
"Custom_Event_Property_Key2": "Custom_Event_Property_val2"
}
}
)
branchEvent.logEvent()

this.addResult('success', 'sendStandardEvent', branchEvent)
} catch (err) {
console.log('sendStandardEvent err', err)
this.addResult('error', 'sendStandardEvent', err.toString())
}
}

logCustomEvent = async () => {
if (!this.buo) await this.createBranchUniversalObject()
try {
let branchEvent = new BranchEvent(
'Test Custom Event Name',
this.buo,
{
transactionID: '12344555',
currency: 'USD',
revenue: 1.5,
shipping: 10.2,
tax: 12.3,
coupon: 'test_coupon',
affiliation: 'test_affiliation',
description: 'Test purchase event',
searchQuery: 'test keyword',
customData: {
"Custom_Event_Property_Key1": "Custom_Event_Property_val1",
"Custom_Event_Property_Key2": "Custom_Event_Property_val2"
}
}
)
branchEvent.logEvent()

this.addResult('success', 'sendStandardEvent', branchEvent)
} catch (err) {
console.log('sendStandardEvent err', err)
this.addResult('error', 'sendStandardEvent', err.toString())
}
}

addResult(type, slug, payload) {
let result = { type, slug, payload }
this.setState({
Expand Down Expand Up @@ -192,6 +254,8 @@ class BranchMethods extends Component {
<Button onPress={this.redeemRewards.bind(this, 'testBucket')}>redeemRewards (with bucket)</Button>
<Button onPress={this.loadRewards}>loadRewards</Button>
<Button onPress={this.getCreditHistory}>getCreditHistory</Button>
<Button onPress={this.logStandardEvent}>BranchEvent.logEvent (Standard)</Button>
<Button onPress={this.logCustomEvent}>BranchEvent.logEvent (Custom)</Button>
</ScrollView>
</View>
)
Expand Down

0 comments on commit 734583b

Please sign in to comment.