diff --git a/README.md b/README.md index b8e9d1f2..95bc3498 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ - [Install Branch](#install-branch) - [Configure App](#configure-app) - [Initialize Branch](#initialize-branch) - - [Listen Deep Link](#listen-deep-link) - [Test Deep Link iOS](#test-deep-link-ios) - [Test Deep Link Android](#test-deep-link-android) - [Features](#features) @@ -40,7 +39,7 @@ - [Link Domain: Custom](#link-domain-custom) - [Link Domain: Bnc.lt](#link-domain-bnclt) - [Link Data: Convert to Ionic/Angular](#link-data-convert-to-ionicangular) - - [Link Data: Depreciated Methods](#link-data-depreciated-methods) + - [Link Data: Global Listener Warning](#link-data-global-listener-warning) - [Compiling: Updating the Branch SDK](#compiling-updating-the-branch-sdk) - [Compiling: Cordova Dependencies](#compiling-cordova-dependencies) - [Compiling: Visual Studio TACO](#compiling-visual-studio-taco) @@ -60,7 +59,7 @@ - #### Install Branch - - Change `key_live_hiuejxqEdbHR8Tc1L92nmiijrse9OBpq`, and `branchcordova` to the values in your [Branch Dashboard](https://dashboard.branch.io/settings/link) + - Change `key_live_hiuejxqEdbHR8Tc1L92nmiijrse9OBpq` and `branchcordova` to the values in your [Branch Dashboard](https://dashboard.branch.io/settings/link) -
Cordova and PhoneGap and Ionic ```sh @@ -102,29 +101,29 @@ -
Cordova and PhoneGap ```js - // sample index.js var app = { initialize: function() { this.bindEvents(); }, - bindEvents: function() { - document.addEventListener("deviceready", this.onDeviceReady, false); + document.addEventListener('deviceready', this.onDeviceReady, false); + document.addEventListener('resume', this.onDeviceReady, false); }, onDeviceReady: function() { - BranchInit(true); + app.branchInit(); }, - - function BranchInit(isDebug) { - Branch.setDebug(isDebug); // for development and debugging only - Branch.initSession().then(function(res) { - console.log(res); - }).catch(function(err) { - console.error(err); + onDeviceResume: function() { + app.branchInit(); + }, + branchInit: function() { + // Branch initialization + Branch.initSession(function(data) { + // read deep link data on click + alert('Deep Link Data: ' + JSON.stringify(data)); }); } }; - + app.initialize(); ```
@@ -132,45 +131,55 @@ -
Ionic 1 ```js // sample app.js + angular.module('starter', ['ionic', 'starter.controllers', 'starter.services']) + .run(function($ionicPlatform) { $ionicPlatform.ready(function() { + if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); + cordova.plugins.Keyboard.disableScroll(true); + } + if (window.StatusBar) { + StatusBar.styleDefault(); + } - $ionicPlatform.on("deviceready", function(){ - BranchInit(true); + // Branch initialization + Branch.initSession(function(data) { + // read deep link data on click + alert('Deep Link Data: ' + JSON.stringify(data)); }); - - function BranchInit(isDebug) { - Branch.setDebug(isDebug); // for development and debugging only - Branch.initSession().then(function(res) { - console.log(res); - }).catch(function(err) { - console.error(err); - }); - } }); }) + // ... ```
-
Ionic 2 ```typescript // sample app.component.js + import { Component } from '@angular/core'; + import { Platform } from 'ionic-angular'; + import { StatusBar, Splashscreen } from 'ionic-native'; + import { TabsPage } from '../pages/tabs/tabs'; + + // Branch import declare var Branch; @Component({ - // ... + template: `` }) - export class MyApp { + rootPage = TabsPage; + constructor(platform: Platform) { platform.ready().then(() => { + StatusBar.styleDefault(); + Splashscreen.hide(); - // Branch - Branch.setDebug(isDebug); // for development and debugging only - Branch.initSession().then(function(res) { - console.log(res); - }).catch(function(err) { - console.error(err); + // Branch initialization + Branch.initSession(function(data) { + // read deep link data on click + alert('Deep Link Data: ' + JSON.stringify(data)); }); }); } @@ -178,36 +187,9 @@ ```
-- #### Listen Deep Link - - - `DeepLinkHandler` must be a global function and does not have to be in `index.html` - - -
Cordova and PhoneGap and Ionic - ```html - - - - - ``` -
- - #### Test Deep Link iOS - - Wait 30 minutes after saving changes on the [Branch Dashboard](https://dashboard.branch.io/settings/link) + - Wait 15 minutes after saving changes on the [Branch Dashboard](https://dashboard.branch.io/settings/link) - Create a deep link from the [Branch Marketing Dashboard](https://dashboard.branch.io/marketing) @@ -229,7 +211,7 @@ - #### Test Deep Link Android - - Wait 30 minutes after saving changes on the [Branch Dashboard](https://dashboard.branch.io/settings/link) + - Wait 15 minutes after saving changes on the [Branch Dashboard](https://dashboard.branch.io/settings/link) - Create a deep link from the [Branch Marketing Dashboard](https://dashboard.branch.io/marketing) @@ -252,16 +234,19 @@ -
Example ```js // for development and debugging only - Branch.setDebug(isDebug); + Branch.setDebug(true); // sync with Mixpanel if installed Branch.setMixpanelToken('your_mixpanel_token'); - // init Branch - Branch.initSession().then(function(res) { - console.log(res); + // Branch initialization + Branch.initSession(function(data) { + // read deep link data on click + alert('Deep Link Data: ' + JSON.stringify(data)); + }).then(function(res) { + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - console.error(err); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -289,18 +274,18 @@ ```js // only canonicalIdentifier is required var properties = { - canonicalIdentifier: "123", - canonicalUrl: "http://example.com/123", - title: "Content 123", - contentDescription: "Content 123 " + Date.now(), - contentImageUrl: "http://lorempixel.com/400/400", + canonicalIdentifier: '123', + canonicalUrl: 'http://example.com/123', + title: 'Content 123', + contentDescription: 'Content 123 ' + Date.now(), + contentImageUrl: 'http://lorempixel.com/400/400/', price: 12.12, - currency: "GBD", - contentIndexingMode: "private", + currency: 'GBD', + contentIndexingMode: 'private', contentMetadata: { - "custom": "data", - "testing": 123, - "this_is": true + 'custom': 'data', + 'testing': 123, + 'this_is': true } }; @@ -308,9 +293,9 @@ var branchUniversalObj = null; Branch.createBranchUniversalObject(properties).then(function(res) { branchUniversalObj = res; - alert("Response: " + JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert("Error: " + JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -435,29 +420,29 @@ ```js // optional fields var analytics = { - channel: "channel", - feature: "feature", - campaign: "campaign", - stage: "stage", - tags: ["one","two","three"] + channel: 'channel', + feature: 'feature', + campaign: 'campaign', + stage: 'stage', + tags: ['one', 'two', 'three'] }; // optional fields var properties = { - $fallback_url: "www.example.com", - $desktop_url: "www.desktop.com", - $android_url: "www.android.com", - $ios_url: "www.ios.com", - $ipad_url: "www.ipad.com", - more_custom: "data", + $fallback_url: 'www.example.com', + $desktop_url: 'www.desktop.com', + $android_url: 'www.android.com', + $ios_url: 'www.ios.com', + $ipad_url: 'www.ipad.com', + more_custom: 'data', even_more_custom: true, - this_is_custom: 41231 + this_is_custom: 321 }; branchUniversalObj.generateShortUrl(analytics, properties).then(function(res) { - alert(JSON.stringify(res.url)); + alert('Response: ' + JSON.stringify(res.url)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ``` @@ -474,23 +459,23 @@ ```js // optional fields var analytics = { - channel: "channel", - feature: "feature", - campaign: "campaign", - stage: "stage", - tags: ["one","two","three"] + channel: 'channel', + feature: 'feature', + campaign: 'campaign', + stage: 'stage', + tags: ['one', 'two', 'three'] }; // optional fields var properties = { - $fallback_url: "www.example.com", - $desktop_url: "www.desktop.com", - $android_url: "www.android.com", - $ios_url: "www.ios.com", - $ipad_url: "www.ipad.com", - more_custom: "data", + $fallback_url: 'www.example.com', + $desktop_url: 'www.desktop.com', + $android_url: 'www.android.com', + $ios_url: 'www.ios.com', + $ipad_url: 'www.ipad.com', + more_custom: 'data', even_more_custom: true, - this_is_custom: 41231 + this_is_custom: 321 }; var message = "Check out this link"; @@ -498,17 +483,17 @@ // optional listeners (must be called before showShareSheet) branchUniversalObj.onShareSheetLaunched(function(res) { // android only - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }); branchUniversalObj.onShareSheetDismissed(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }); branchUniversalObj.onLinkShareResponse(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }); branchUniversalObj.onChannelSelected(function(res) { // android only - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }); // share sheet @@ -520,35 +505,47 @@ - Retrieve Branch data from a deep link - - Best practice to receive data from `DeepLinkHandler` listener + - Best practice to receive data from the `listener` -
Example (listener) - > must be global functions - ```js - // required - function DeepLinkHandler(data) { - if (data) { - // window.location = "#/tab/chats/3"; // navigate to page based on data - alert("Data Link handler response: " + JSON.stringify(data)); - } - } + // Branch initialization within your deviceReady + Branch.initSession(function(deepLinkData) { + // handler for deep link data on click + alert(JSON.stringify(deepLinkData)); + }); + ``` +
- // optional - function NonBranchLinkHandler(data) { - if (data) { - alert("Non-branch link found: " + JSON.stringify(data)); - } - } + -
Example (listener) *[depreciated]* + ```html + + + + ```
-
Example (first data) ```js Branch.getFirstReferringParams().then(function(res) { - alert("Response: " + JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert("Error: " + JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -556,9 +553,9 @@ -
Example (latest data) ```js Branch.getLatestReferringParams().then(function(res) { - alert("Response: " + JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert("Error: " + JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -572,9 +569,9 @@ -
Example ```js branchUniversalObj.listOnSpotlight().then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -588,9 +585,9 @@ -
Example ```js branchUniversalObj.registerView().then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -601,11 +598,11 @@ -
Example (set) ```js - var userId = "email_or_id"; + var userId = 'email_or_id'; Branch.setIdentity(userId).then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -615,7 +612,7 @@ Branch.logout().then(function(res) { alert(JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ``` @@ -628,20 +625,20 @@ -
Example ```js - var eventName = "clicked_on_this"; - var metaData = { "custom_dictionary": 123 }; // optional + var eventName = 'clicked_on_this'; + var metaData = { custom_dictionary: 123 }; // optional Branch.userCompletedAction(eventName, metaData).then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ``` ```js var eventName = "clicked_on_this"; Branch.userCompletedAction(eventName).then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -670,37 +667,39 @@ -
Example (spend credits) ```js var amount = 10; - var bucket = "this_bucket"; // optional + var bucket = 'this_bucket'; // optional Branch.redeemRewards(amount, bucket).then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ``` + ```js var amount = 10; Branch.redeemRewards(amount).then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
-
Example (load credits) ```js - var bucket = "this_bucket"; // optional + var bucket = 'this_bucket'; // optional Branch.loadRewards(bucket).then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ``` + ```js Branch.loadRewards().then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -708,9 +707,9 @@ -
Example (load history) ```js Branch.creditHistory().then(function(res) { - alert(JSON.stringify(res)); + alert('Response: ' + JSON.stringify(res)); }).catch(function(err) { - alert(JSON.stringify(err)); + alert('Error: ' + JSON.stringify(err)); }); ```
@@ -748,9 +747,9 @@ ``` - **Update config.xml** - ```js + ```xml - ** + @@ -864,7 +863,7 @@ | | iOS | Details | Android | Details | --- | :-: | --- | :-: | --- | Facebook NewsFeed | ✅ | Works when [DeepViews](https://dashboard.branch.io/settings/deepviews) are enabled | ✅ | - | Facebook Messanger | ✅ | Works when [DeepViews](https://dashboard.branch.io/settings/deepviews) are enabled | ✅ | Works except the `app.link` domain is not clickable | + | Facebook Messanger | ✅ | Works when [DeepViews](https://dashboard.branch.io/settings/deepviews) are enabled | ✅ | Works except the `app.link` domain is not click-able | | Twitter | ✅ | | ✅ | | Pinterest | ✅ | Works when [DeepViews](https://dashboard.branch.io/settings/deepviews) are enabled | 🅾️ | | Slack | ✅ | | ✅ | | @@ -935,10 +934,8 @@ function DeepLinkHandler(data) { if (data) { // access the angular Factory("DeepLink") - angular.element(document.querySelector("[ng-app]")).injector().get("DeepLink").set(data); - console.log("Data Link handler response: " + JSON.stringify(data)); - } else { - console.error("Data Link handler no data"); + angular.element(document.querySelector('[ng-app]')).injector().get("DeepLink").set(data); + console.log('Data Link handler response: ' + JSON.stringify(data)); } } ``` @@ -982,11 +979,11 @@ ``` -- #### Link Data: Depreciated Methods +- #### Link Data: Global Listener Warning - - Before version `2.4.0`, Branch used globally defined listeners to pass events generated by clicking on links outside your cordova app into it. To make this behavior more explicit, we've shifted to event listeners passed to the branch object via the branch.initSession(onBranchLinkHook) and branch.onNonBranchLink(hook). If you don't want to use these new methods and instead prefer the old global hooks without seeing warnings, call branch.disableGlobalListenersWarning(). + - After Branch SDK `2.4.0`, deep link data is handled within `Branch.initSession(DeepLinkDataFunction);` - - `branch.disableGlobalListenersWarnings();` turns off warnings about using global listeners. + - Use `Branch.disableGlobalListenersWarnings();` to turn off the warning errors generated from `DeepLinkHandler` and `NonBranchLinkHandler` - #### Compiling: Updating the Branch SDK @@ -1047,12 +1044,13 @@ - Open Android Studio -> New project -> ... -> Run -> Create new emulator -> Nexus 6p 23 -> Finish ```sh - sudo cat >> ~/.bash_profile < - -
Genymotion *(optional)* + -
Genymotion *[optional]* - Install [Virtual Box](https://www.virtualbox.org/wiki/Downloads) - Install [Genymotion](https://www.genymotion.com/download/) diff --git a/testbed/www/js.es6/index.js b/testbed/www/js.es6/index.js index 365580fb..cbb3b89c 100644 --- a/testbed/www/js.es6/index.js +++ b/testbed/www/js.es6/index.js @@ -1,47 +1,42 @@ -'use strict'; - // app - var app = { - initialize: function initialize() { + initialize: function() { this.bindEvents(); }, - bindEvents: function bindEvents() { + bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); + document.addEventListener('resume', this.onDeviceReady, false); + }, + onDeviceReady: function() { + BranchInit(true); }, - onDeviceReady: function onDeviceReady() { + onDeviceResume: function() { BranchInit(true); } }; app.initialize(); // branch - function BranchInit(isDebug) { console.log('Trigger BranchInit()'); // for development and debugging only Branch.setDebug(isDebug); - // sync with mixpanel if installed + // sync with Mixpanel if installed Branch.setMixpanelToken('your_mixpanel_token'); - // init - Branch.initSession(BranchLinkData).then(function(res) { + // Branch initialization + Branch.initSession(function(data) { + // read deep link data on click + console.log('Trigger DeepLinkHandler()'); + alert('Deep Link Data: ' + JSON.stringify(data)); + }).then(function(res) { console.log(res); }).catch(function(err) { console.error(err); }); - // handler for deep link data - function BranchLinkData(data) { - console.log('Trigger BranchLinkData()'); - - if (data) { - alert(JSON.stringify(data)); - } - } - // optional Branch.onNonBranchLink(function NonBranchLinkHandler(data) { console.log('Trigger NonBranchLinkData()'); diff --git a/testbed/www/js/index.js b/testbed/www/js/index.js index b56ba0aa..8b1dff21 100644 --- a/testbed/www/js/index.js +++ b/testbed/www/js/index.js @@ -1,47 +1,44 @@ 'use strict'; // app - var app = { initialize: function initialize() { this.bindEvents(); }, bindEvents: function bindEvents() { document.addEventListener('deviceready', this.onDeviceReady, false); + document.addEventListener('resume', this.onDeviceReady, false); }, onDeviceReady: function onDeviceReady() { BranchInit(true); + }, + onDeviceResume: function onDeviceResume() { + BranchInit(true); } }; app.initialize(); // branch - function BranchInit(isDebug) { console.log('Trigger BranchInit()'); // for development and debugging only Branch.setDebug(isDebug); - // sync with mixpanel if installed + // sync with Mixpanel if installed Branch.setMixpanelToken('your_mixpanel_token'); - // init - Branch.initSession(BranchLinkData).then(function (res) { + // Branch initialization + Branch.initSession(function (data) { + // read deep link data on click + console.log('Trigger DeepLinkHandler()'); + alert('Deep Link Data: ' + JSON.stringify(data)); + }).then(function (res) { console.log(res); }).catch(function (err) { console.error(err); }); - // handler for deep link data - function BranchLinkData(data) { - console.log('Trigger BranchLinkData()'); - - if (data) { - alert(JSON.stringify(data)); - } - } - // optional Branch.onNonBranchLink(function NonBranchLinkHandler(data) { console.log('Trigger NonBranchLinkData()');