Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-branch

Package Overview
Dependencies
Maintainers
4
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-branch

Branch Metrics React Native SDK

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
44K
decreased by-4.02%
Maintainers
4
Weekly downloads
 
Created
Source

Branch Metrics React Native SDK Reference

This is a repository of our open source React Native SDK. Huge shoutout to our friends at Dispatcher, Inc. for their help in compiling the initial version of this SDK. This SDK will help you handle iOS Universal Links, Android App Link, deferred deep links, do install attribution and much more!

v0.1.0 has just been released with breaking changes! [Upgrade Notes]

build status npm version npm downloads

Installation

  1. npm install --save react-native-branch
  2. rnpm link react-native-branch or link the project manually
  3. Add pod 'Branch' to your ios/Podfile (details)
  4. cd ios && pod install
  5. Follow the setup instructions

If you are new to react-native or cocoa-pods, read below for more details:

Next Steps

In order to get full branch support you will need to setup your ios and android projects accordingly:

Please see the branch SDK Integration Guide for complete setup instructions.

Additional Resources

Usage

import branch from 'react-native-branch'

// Subscribe to incoming links (both branch & non-branch)
branch.subscribe(({params, error, uri}) => {
  if (params) { /* handle branch link */ }
  else { /* handle uri */ }
})

let lastParams = await branch.getLatestReferringParams() // params from last open
let installParams = await branch.getFirstReferringParams() // params from original install
branch.setIdentity('theUserId')
branch.userCompletedAction('Purchased Item', {item: 123})
branch.logout()

let branchUniversalObject = branch.createBranchUniversalObject('canonicalIdentifier', {metadata: {prop1: 'test', prop2: 'abc'}, contentTitle: 'Cool Content!', contentDescription: 'Cool Content Description'}

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()
let spotlightResult = await branchUniversalObject.listOnSpotlight()

let rewards = await branch.loadRewards()
let redeemResult = await branch.redeemRewards(amount, bucket)
let creditHistory = await branch.getCreditHistory()

Linking

subscribe(listener)

listener (function)
Adds a change listener. Listener takes 1 argument with the shape { params, uri, error}. The listener will be called for all incoming links. Branch links will have params, plain deep links will only have a uri.

getLatestReferringParams(): Promise

Returns a promise that resolves to the most recent referring params. Because params come in asynchronously, in most cases it is better to use the subscribe method to receive the params as soon as they are available.

getFirstReferringParams(): Promise

Returns a promise to resolves with the first install referring params.

params object

The params object is returned by various linking methods including subscribe, getLatestReferringParams, and getFirstReferringParams. Params will contain any data associated with the Branch link that was clicked before the app session began.

Branch returns explicit parameters every time. Here is a list, and a description of what each represents.

  • ~ denotes analytics
  • + denotes information added by Branch
ParameterMeaning
~channelThe channel on which the link was shared, specified at link creation time
~featureThe feature, such as invite or share, specified at link creation time
~tagsAny tags, specified at link creation time
~campaignThe campaign the link is associated with, specified at link creation time
~stageThe stage, specified at link creation time
~creation_sourceWhere the link was created ('API', 'Dashboard', 'SDK', 'iOS SDK', 'Android SDK', or 'Web SDK')
+match_guaranteedTrue or false as to whether the match was made with 100% accuracy
+referrerThe referrer for the link click, if a link was clicked
+phone_numberThe phone number of the user, if the user texted himself/herself the app
+is_first_sessionDenotes whether this is the first session (install) or any other session (open)
+clicked_branch_linkDenotes whether or not the user clicked a Branch link that triggered this session
+click_timestampEpoch timestamp of when the click occurred

Any additional data attached to the branch link will be available unprefixed.

User Methods

setIdentity(userId)

Set an identifier for the current user.

logout(userId)

Logout the current user.

userCompletedAction(label, payload)

Register a user action with branch.

Branch Universal Object

createBranchUniversalObject(canonicalIdentifier, universalObjectOptions): object

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.

The following methods are available on the resulting branchUniversalObject:
- showsharesheet(shareOptions, linkProperties, controlParams): object

shareOptions as defined below
linkProperties as defined below
controlParams as defined below
Returns an object with { channel, completed, error }

- generateShortUrl(linkProperties, controlParams): object

linkProperties as defined below
controlParams as defined below
Returns an object with { url }

- registerView()

Register a view for this universal object.

- listOnSpotlight()

List the univeral object in spotlight (ios only).

universalObjectOptions object

An object of options for the branchUniversalObject.

KeyTYPEDESCRIPTION
canonicalIdentifierStringThe object identifier
titleStringThe object title
contentDescriptionStringObject Description
contentImageUrlStringThe Image URL
contentIndexingModeStringIndexing Mode 'private' or 'public'
contentMetadataObjectCustom key/value
linkProperties object

An object of link properties.

KEYTYPEMEANING
featurestringThis is the feature of your app that the link might be associated with. eg: if you had built a referral program, you would label links with the feature referral
aliasstringSpecify a link alias in place of the standard encoded short URL (e.g., [branchsubdomain]/youralias or yourdomain.co/youralias). Link aliases are unique, immutable objects that cannot be deleted. Aliases on the legacy bnc.lt domain are incompatible with Universal Links and Spotlight
channelstringUse channel to tag the route that your link reaches users. For example, tag links with ‘Facebook’ or ‘LinkedIn’ to help track clicks and installs through those paths separately
stagestringUse this to categorize the progress or category of a user when the link was generated. For example, if you had an invite system accessible on level 1, level 3 and 5, you could differentiate links generated at each level with this parameter
durationintduration of the link.
controlParams object

Control parameters for the link.

KEYTYPEMEANING
$fallback_urlstringChange the redirect endpoint for all platforms - so you don’t have to enable it by platform
$desktop_urlstringChange the redirect endpoint on desktops
$android_urlstringChange the redirect endpoint for Android
$ios_urlstringChange the redirect endpoint for iOS
$ipad_urlstringChange the redirect endpoint for iPads
$fire_urlstringChange the redirect endpoint for Amazon Fire OS
$blackberry_urlstringChange the redirect endpoint for Blackberry OS
$windows_phone_urlstringChange the redirect endpoint for Windows OS
shareOptions object
KEYTYPEMEANING
messageHeaderstringThe header text
messageBodystringThe body text

Referral Methods

loadRewards()

Load rewards.

redeemRewards(amount, bucket)

Redeem rewards. amount the amount to redeem
bucket (optional) the bucket to redeem from.

getCreditHistory(): array

Get the credit history as an array.

Keywords

FAQs

Package last updated on 02 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc