React-native-branch-deep-linking-attribution: Branch doesnt recognise link on app launch Android

Created on 29 Aug 2017  路  3Comments  路  Source: BranchMetrics/react-native-branch-deep-linking-attribution

If there is a bug or error in this repo, please file the issue here.

If you need assistance integrating a Branch SDK, please email [email protected]. Thank you.
Question #1:
So basically if app is launched via user clicking a deep link https://*.app.link/*
it launches the app but branch.subscribe doesn't see it at all.

However if I execute
branch.getLatestReferringParams().then(params => console.log(params))
It returns the following:

+is_first_session: false
+clicked_branch_link: false
+non_branch_link: https://*.app.link/*

How can I properly react to an incoming deep link when app is completely closed?
On iOS it works just as expected even if app is completely closed.

Here is what I do on componentDidMount():

// Subscribe to incoming links (both Branch & non-Branch)
    this._unsubscribeFromBranch = branch.subscribe(({ error, params }) => {
      console.log({params, error}) // Doesnt do anything on first app launch :/
      if (params && !error) {
        if (!params['+clicked_branch_link'] && !params['+non_branch_link']) return
        this.navigate(params.$deeplink_path)
        // grab deep link data and route appropriately.
      }
    })
    branch.getLatestReferringParams().then(params =>  console.log(params)) // This returns the above

Question #2:
How can I use deeplinks within the app?
When app is in a foreground and deeplink is clicked, on Android I have to move an app into the background and bring it back to the foreground in order branch.subscribe grab it and navigate accordingly.

On iOS it just sends me to Safari where I click Get the app button (default branch template) and it brings me back to the app and navigates accordingly.

Thanks a lot in advance! 馃憤 馃憤 馃憤

Update:
Question #1:
I'm not too sure if it is a proper way of doing:

componentDidMount(){
    // Subscribe to incoming links (both Branch & non-Branch)
    this._unsubscribeFromBranch = branch.subscribe(({ error, params }) => {
      if (params && !error) {
        if (!params['+clicked_branch_link'] && !params['+non_branch_link']) return
        this.navigate(params.$deeplink_path)
        // grab deep link data and route appropriately.
      }
    })

if (Platform.OS === 'android') {
      branch.getLatestReferringParams().then(params => {
        if (!params['+clicked_branch_link'] && !params['+non_branch_link']) return
        this.navigate(params.$deeplink_path)
        return params
       })
}

}

So in that case if app is launched from the link, it will be handled by getLatestReferringParams().
If not it will be handled by branch.subscribe.
However on iOS in both cases its true, so the routing will happen twice, so I put Platform check.

Is this the right approach ? I guess in a scenario when I will want ot know if the app was installed by following the shared link, I wouldn't know if it was the case on iOS ?

Most helpful comment

I think this may essentially be a duplicate of #216. I do not recommend calling getLatestReferringParams inside the subscriber. This is another async call that adds response time. For now, if you have something working, use what you need to use. I'll try to expedite fixing that bug.

I'm working on adding a method to the SDK to programmatically open links, e.g. from a QR reader or a push notification. That should be available soon.

All 3 comments

Hi @Amurmurmur. Sorry for the delay. This seems to work fine in webview_example. Maybe you can see if you have the same problem using webview_example with your keys and domains. You might want to try comparing your setup to the examples in the repo to see what differs. I think the reason for your #2 is probably related to #1.

This is all handled at the native level. Whenever the native code receives notification that a link was opened, it passes an event to the RN runtime, which results in the branch.subscribe listener being called back. If this isn't happening, the native layer is probably not generating the event, which can happen if you forget certain setup steps. In particular, in your activity, you need to call RNBranch.initSession in onStart and setIntent in onNewIntent. I'd also double-check the settings in your Android manifest. Make sure that you are using singleTask for your main activity and that your keys and intent-filters are set up correctly. See the README in the repo for more details on setting up an Android project.

@jdee Just checked everything, and especially singleTask mode.
I guess its just the way it works, and my current approach is the only way to make it work. I copied exactly the setup for android from the example folder.

Last question:
@jdee How do you think would be the best to handle opening deeplinks inside the app.
The idea is that if you scan QR image with that branch link, and instead of Linking.openURL(branch_link_here) that you've read from the QR image
actually do a silent request to get the link data such as deeplinking url and other data set in the dashboard.

Is there any workaround that problem? Or maybe its best to just set the routing in the QR code and avoid branch completely, and manage analytics in a different way ?

I think this may essentially be a duplicate of #216. I do not recommend calling getLatestReferringParams inside the subscriber. This is another async call that adds response time. For now, if you have something working, use what you need to use. I'll try to expedite fixing that bug.

I'm working on adding a method to the SDK to programmatically open links, e.g. from a QR reader or a push notification. That should be available soon.

Was this page helpful?
0 / 5 - 0 ratings