From 17569f1d4efe56db313ebebc6823cd412ed9a70c Mon Sep 17 00:00:00 2001 From: Jimmy Dee Date: Thu, 16 Mar 2017 09:57:09 -0700 Subject: [PATCH 1/3] Documentation of userCompletedAction(). --- README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bbdf6d191..67b39b49a 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,9 @@ let {url} = await branchUniversalObject.generateShortUrl(linkProperties, control let viewResult = await branchUniversalObject.registerView() // deprecated. use userCompletedAction(RegisterViewEvent) instead. let spotlightResult = await branchUniversalObject.listOnSpotlight() +// optional: release native resources right away when finished with this BUO. +branchUniversalObject.release() + let rewards = await branch.loadRewards() let redeemResult = await branch.redeemRewards(amount, bucket) let creditHistory = await branch.getCreditHistory() @@ -154,11 +157,21 @@ Register a user action with Branch. ###### [createBranchUniversalObject(canonicalIdentifier, universalObjectOptions): object](#createbranchuniversalobject) Create a branch universal object. **canonicalIdentifier** the unique identifier for the content. -**universalObjectOptions** options for universal object as defined [below][#universalobjectoptions]. -Returns an object with methods `generateShortUrl`, `registerView`, `listOnSpotlight`, and `showShareSheet`. +**universalObjectOptions** options for universal object as defined [below](#universalobjectoptions). +Returns an object with methods `generateShortUrl`, `registerView`, `listOnSpotlight`, `showShareSheet` and `userCompletedAction`. ##### The following methods are available on the resulting branchUniversalObject: -###### [- showsharesheet(shareOptions, linkProperties, controlParams): object](#showsharesheet) + +###### [- userCompletedAction(event, state = {}): null](#usercompletedaction) + +Report a user action for this Branch Universal Object instance. Create a Branch Universal Object on page load and call `userCompletedAction(RegisterViewEvent)`. + +**event** an event name string, either one of the standard events defined by the SDK (as defined [below](#useractions)) or a custom event name. +**state** an optional object with string properties representing custom application state + +Returns null. + +###### [- showShareSheet(shareOptions, linkProperties, controlParams): object](#showsharesheet) **shareOptions** as defined [below](#shareoptions) **linkProperties** as defined [below](#linkproperties) **controlParams** as defined [below](#controlparams) @@ -170,10 +183,46 @@ Returns an object with `{ channel, completed, error }` Returns an object with `{ url }` ###### [- registerView()](#registerview) -Register a view for this universal object. +Register a view for this universal object. **Deprecated**: Use `userCompletedAction(RegisterViewEvent)` instead. ###### [- listOnSpotlight()](#listonspotlight) -List the univeral object in spotlight (ios only). +List the universal object on Spotlight (iOS only). **Note**: The recommended way to list an item on Spotlight is to use the `automaticallyListOnSpotlight` property with `createBranchUniversalObject` and then call `userCompletedAction(RegisterViewEvent)`, e.g. + +```js +import branch, { RegisterViewEvent } from 'react-native-branch' + +let universalObject = branch.createBranchUniversalObject('abc', { + automaticallyListOnSpotlight: true, + title: 'Item title', + contentDescription: 'Item description', + contentImageUrl: 'https://example.com/image.png' +}) +universalObject.userCompletedAction(RegisterViewEvent) +``` + +The `automaticallyListOnSpotlight` property is ignored on Android. + +##### [Register User Actions On An Object](#useractions) + +We've added a series of custom events that you'll want to start tracking for rich analytics and targeting. Here's a list below with a sample snippet that calls the register view event. + +| Event | Description +| ----- | --- +| RegisterViewEvent | User viewed the object +| AddToWishlistEvent | User added the object to their wishlist +| AddToCartEvent | User added object to cart +| PurchaseInitiatedEvent | User started to check out +| PurchasedEvent | User purchased the item +| ShareInitiatedEvent | User started to share the object +| ShareCompletedEvent | User completed a share + +```js +import branch, { RegisterViewEvent } from 'react-native-branch' +let universalObject = branch.createUniversalObject('abc', {}) +universalObject.userCompletedAction(RegisterViewEvent) +``` + +Note that `registerView()` is deprecated in favor of `userCompletedAction(RegisterViewEvent)`. ###### [universalObjectOptions object](#universalobjectoptions) An object of options for the branchUniversalObject. From e1feeef6d335bf75c7bf95e11e677b5c8663e3c6 Mon Sep 17 00:00:00 2001 From: Jimmy Dee Date: Thu, 16 Mar 2017 10:06:37 -0700 Subject: [PATCH 2/3] Add calls to this.buo.release() in componentWillUnmount() in testbed apps. --- testbed/testbed_carthage/src/BranchMethods.js | 5 +++++ testbed/testbed_cocoapods/src/BranchMethods.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/testbed/testbed_carthage/src/BranchMethods.js b/testbed/testbed_carthage/src/BranchMethods.js index cafd46e39..11c4dc635 100644 --- a/testbed/testbed_carthage/src/BranchMethods.js +++ b/testbed/testbed_carthage/src/BranchMethods.js @@ -17,6 +17,11 @@ class BranchMethods extends Component { results: [], } + componentWillUnmount() { + if (!this.buo) return + this.buo.release() + } + createBranchUniversalObject = async () => { try { let result = await branch.createBranchUniversalObject('abc', defaultBUO) diff --git a/testbed/testbed_cocoapods/src/BranchMethods.js b/testbed/testbed_cocoapods/src/BranchMethods.js index cafd46e39..11c4dc635 100644 --- a/testbed/testbed_cocoapods/src/BranchMethods.js +++ b/testbed/testbed_cocoapods/src/BranchMethods.js @@ -17,6 +17,11 @@ class BranchMethods extends Component { results: [], } + componentWillUnmount() { + if (!this.buo) return + this.buo.release() + } + createBranchUniversalObject = async () => { try { let result = await branch.createBranchUniversalObject('abc', defaultBUO) From f6267c3feafb1af4bdfc268d09b0982133a017a3 Mon Sep 17 00:00:00 2001 From: Jimmy Dee Date: Thu, 16 Mar 2017 10:16:35 -0700 Subject: [PATCH 3/3] Document release() method and update to version 1.1.0. --- README.md | 12 +++++++----- package.json | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 67b39b49a..2cb8d7d97 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is a repository of our open source React Native SDK. Huge shoutout to our friends at [Dispatcher, Inc.](https://dispatchertrucking.com) for their help in compiling the initial version of this SDK. This SDK will help you handle iOS Universal Links, Android App Links and deferred deep links, do install attribution and much more! -**react-native v0.40 support** is available in version 1.0.0. This is a non-backwards compatible update. If you need to stay on react-native <0.40 please fix your package.json version to react-native-branch@0.9. See [Updating to 1.0.0](./docs/updating-1.0.0.md) for details. Note that some build steps differ between 0.9 and 1.0. These are highlighted +**react-native v0.40 support** is available in version 1.x. This is a non-backwards compatible update. If you need to stay on react-native <0.40 please fix your package.json version to react-native-branch@0.9. See [Updating to 1.0.0](./docs/updating-1.0.0.md) for details. Note that some build steps differ between 0.9 and 1.x. These are highlighted where applicable. **v0.8.0** If you have overridden `onStop` in MainActivity.java be sure *not* to invoke `RNBranchModule.onStop()`. @@ -83,15 +83,14 @@ let branchUniversalObject = branch.createBranchUniversalObject('canonicalIdentif metadata: {prop1: 'test', prop2: 'abc'}, title: 'Cool Content!', contentDescription: 'Cool Content Description'}) -let actionResult = await branchUniversalObject.userCompletedAction(RegisterViewEvent) -let customActionResult = await branchUniversalObject.userCompletedAction('Custom Action', { key: 'value' }) +branchUniversalObject.userCompletedAction(RegisterViewEvent) +branchUniversalObject.userCompletedAction('Custom Action', { key: 'value' }) let shareOptions = { messageHeader: 'Check this out', messageBody: 'No really, check this out!' } let linkProperties = { feature: 'share', channel: 'RNApp' } let controlParams = { $desktop_url: 'http://example.com/home', $ios_url: 'http://example.com/ios' } let {channel, completed, error} = await branchUniversalObject.showShareSheet(shareOptions, linkProperties, controlParams) let {url} = await branchUniversalObject.generateShortUrl(linkProperties, controlParams) -let viewResult = await branchUniversalObject.registerView() // deprecated. use userCompletedAction(RegisterViewEvent) instead. let spotlightResult = await branchUniversalObject.listOnSpotlight() // optional: release native resources right away when finished with this BUO. @@ -158,7 +157,7 @@ Register a user action with Branch. Create a branch universal object. **canonicalIdentifier** the unique identifier for the content. **universalObjectOptions** options for universal object as defined [below](#universalobjectoptions). -Returns an object with methods `generateShortUrl`, `registerView`, `listOnSpotlight`, `showShareSheet` and `userCompletedAction`. +Returns an object with methods `generateShortUrl`, `registerView`, `listOnSpotlight`, `showShareSheet`, `userCompletedAction` and `release`. ##### The following methods are available on the resulting branchUniversalObject: @@ -202,6 +201,9 @@ universalObject.userCompletedAction(RegisterViewEvent) The `automaticallyListOnSpotlight` property is ignored on Android. +##### [- release()](#release) +(Optional) Immediately release native resources used by this Branch Universal Object instance. Those resources will eventually be removed if they are unused for some time, but you can also call `release()` when a BUO is no longer used, e.g. in `componentWillUnmount()`. (See the [testbed](./testbed) apps in this repo.) + ##### [Register User Actions On An Object](#useractions) We've added a series of custom events that you'll want to start tracking for rich analytics and targeting. Here's a list below with a sample snippet that calls the register view event. diff --git a/package.json b/package.json index acbdf42b8..b4c24b35d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-branch", - "version": "1.0.6", + "version": "1.1.0", "description": "Branch Metrics React Native SDK", "main": "src/index.js", "files": [