0

I am trying to send my app's link form my website with a token in the link like this :

branch.link({
  stage: 'new user',
  data: {
       token: 543322
   }},
   function(err, link) {
    console.log(err, link);
});

then when the app is installed by user after clicking on the link, i want to get this token to register the user. I tried by reading Branch.io docs and implementing it but it's not working. Can somebody tell me an Example to how to make it work? Code in my app controller is like this

(():void => {
  'use strict';
  angular
    .module('xyz')
    .controller('abc', abc);

    function abc (
      $window
    ) {
      let vm = this;

      $window.Branch.setDebug(true);
      $window.Branch.initSession().then(function (res) {
        console.log(res);
        alert('Response: ' + JSON.stringify(res));
       }).catch(function (err) {
         console.error(err);
         alert('Error: ' + JSON.stringify(err));
      });

      $window.Branch.getFirstReferringParams().then(function (res) {
        // Success Callback
        alert('res'+res);
      }).catch(function (err) {
        // Error Callback
        alert('err'+err);
      });

      $window.Branch.getLatestReferringParams().then(function (res) {
        // Success Callback
        alert(res);
      }).catch(function (err) {
        // Error Callback
        alert(err);
      });

      function DeepLinkHandler (data) {
       alert('Data from initSession: ' + data.data);
      }

      $window.DeepLinkHandler = DeepLinkHandler;

})();
d512
  • 32,267
  • 28
  • 81
  • 107

1 Answers1

1

Alex from Branch here: there are three steps to this process:

1. Create the link

You're doing this already with the code you provided in your question.

2. Integrate the Branch SDK into your app

The docs page covering the steps for this is here: https://dev.branch.io/getting-started/sdk-integration-guide/guide/cordova/

3. Watch for the incoming link, and route it

The docs page covering what you need for this is here: https://dev.branch.io/getting-started/deep-link-routing/advanced/cordova/

Basically, it is a function that will look something like this:

function DeepLinkHandler(data) {
    console.log("received data: " + JSON.stringify(data));
    for (key in data) {
        if ((key != "type" && key != "source" && key != "bubbles" && key != "cancelBubble") && data[key] != null) {
            console.log(key + ": " + data["key"]);
        }
    }

    if (data["token"]) {
        // load the view to register the user based on your token
    } else {
        // load your normal view
    }
}
Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • I am already doing all this. But DeepLinkHandler is not invoked after initSession. I have added the code to question. Tell me what am i doing wrong. – sandeep chhoker Apr 20 '16 at 06:16