BranchMetrics / cordova-ionic-phonegap-branch-deep-linking-attribution

The Branch Cordova Ionic Phonegap SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/apps/cordova-phonegap-ionic/
MIT License
234 stars 144 forks source link

Deeplink not working when tracking be disabled on Android #731

Open qirong-zhang-ext opened 5 months ago

qirong-zhang-ext commented 5 months ago

Describe the bug

due to some reason we need to disable tracking for branch, but after that Android device cannot open deeplink.

before disableTracking we can receive deeplink params each time clicked the deeplink, after deeplink be disabled, we can never received the deeplink params.

Steps to reproduce

  1. init session and disable tracking
  2. terminate the app
  3. click any deeplink
  4. can only open the APP but cannot go to specific page

Expected behavior

Deeplink should work even tracking be disabled

SDK Version

5.2.0

Make and Model

Google pixcel 6a

OS

Android 14

Additional Information/Context

If move APP to background, there are several cases:

  1. the first deeplink can only open the APP and get params like this:
    params: {"+clicked_branch_link":false,"+is_first_session":true}

And the second time click the link can get correct params.

  1. If click different deeplink, then sometimes you will get previous params instead of latest one, example:
  2. click deeplink1 -> get deeplink1 params
  3. click deeplink2 -> still get deeplink1 params

But if terminate the APP, then deeplink not working at all, cannot get any params.

this issue may related to #455 and https://stackoverflow.com/questions/77899601/branch-sdk-deep-linking-does-not-work-when-tracking-is-disabled, there are three cases listed, and two can work, another one cannot. In my case, all cases cannot work

qirong-zhang-ext commented 5 months ago

Here is the log detail, the case is install app -> login -> terminate app -> click deeplink

log details for enable tracking , this is worked:

2024-06-20 14:07:58.816  4386-4386  FlutterBranchSDK        xxx              D  triggered onActivityPaused: yyy.MainActivity
2024-06-20 14:07:58.859  4386-4386  FlutterBranchSDK        xxx              D  triggered onActivityStopped: yyy.MainActivity
2024-06-20 14:07:58.883  4386-4386  FlutterBranchSDK        xxx              D  triggered onActivityDestroyed: yyy.MainActivity
2024-06-20 14:07:58.886  4386-4386  FlutterBranchSDK        xxx              D  triggered onDetachedFromActivity
2024-06-20 14:07:58.889  4386-4386  FlutterBranchSDK        xxx              D  triggered onDetachedFromEngine
2024-06-20 14:07:58.889  4386-4386  FlutterBranchSDK        xxx              D  triggered teardownChannels
2024-06-20 14:08:05.548  5555-5555  FlutterBranchSDK        xxx              D  triggered onAttachedToEngine
2024-06-20 14:08:05.548  5555-5555  FlutterBranchSDK        xxx              D  triggered setupChannels
2024-06-20 14:08:05.548  5555-5555  FlutterBranchSDK        xxx              D  SDK Init
2024-06-20 14:08:05.562  5555-5555  FlutterBranchSDK        xxx              D  triggered onAttachedToActivity
2024-06-20 14:08:05.562  5555-5555  FlutterBranchSDK        xxx              D  triggered setActivity
2024-06-20 14:08:05.887  5555-5555  BranchSDK               xxx              I  !SDK-VERSION-STRING!:io.branch.sdk.android:library:5.12.1
2024-06-20 14:08:05.890  5555-5555  BranchSDK               xxx              V  onActivityStarted, activity = yyy.MainActivity@eaf5d1a
2024-06-20 14:08:05.890  5555-5555  FlutterBranchSDK        xxx              D  triggered onActivityStarted: yyy.MainActivity
2024-06-20 14:08:05.890  5555-5555  FlutterBranchSDK        xxx              D  triggered SessionBuilder init
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  InitSessionBuilder setting BranchReferralInitListener withCallback with br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin$1@546271c
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  InitSessionBuilder setting withData with links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Beginning session initialization
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Session uri is links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Callback is br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin$1@546271c
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Is auto init false
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Will ignore intent null
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Is reinitializing false
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Session init is deferred until signaled by plugin.
2024-06-20 14:08:05.891  5555-5555  BranchSDK               xxx              V  Session initialization deferred until plugin invokes notifyNativeToInit()
                                                                                                    Caching Session Builder io.branch.referral.Branch$InitSessionBuilder@a715f25
                                                                                                    uri: links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id
                                                                                                    callback: br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin$1@546271c
                                                                                                    isReInitializing: false
                                                                                                    delay: 0
                                                                                                    isAutoInitialization: false
                                                                                                    ignoreIntent: null
2024-06-20 14:08:05.896  5555-5555  BranchSDK               xxx              V  onActivityResumed, activity = yyy.MainActivity@eaf5d1a
2024-06-20 14:08:05.896  5555-5555  BranchSDK               xxx              V  onIntentReady yyy.MainActivity@eaf5d1a removing INTENT_PENDING_WAIT_LOCK
2024-06-20 14:08:05.896  5555-5555  BranchSDK               xxx              V  Read params uri: links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id bypassCurrentActivityIntentState: false intent state: READY
2024-06-20 14:08:05.896  5555-5555  BranchSDK               xxx              V  extractExternalUriAndIntentExtras links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id yyy.MainActivity@eaf5d1a
2024-06-20 14:08:05.896  5555-5555  BranchSDK               xxx              V  isIntentParamsAlreadyConsumed false
2024-06-20 14:08:05.897  5555-5555  BranchSDK               xxx              V  extractBranchLinkFromIntentExtra yyy.MainActivity@eaf5d1a
2024-06-20 14:08:05.898  5555-5555  BranchSDK               xxx              V  isIntentParamsAlreadyConsumed false
2024-06-20 14:08:05.900  5555-5555  BranchSDK               xxx              V  processNextQueueItem onIntentReady
2024-06-20 14:08:05.900  5555-5555  BranchSDK               xxx              V  Queue is: 
2024-06-20 14:08:05.900  5555-5555  FlutterBranchSDK        xxx              D  triggered onActivityResumed: yyy.MainActivity
2024-06-20 14:08:06.147  5555-5555  FlutterBranchSDK        xxx              D  triggered setupBranch
2024-06-20 14:08:06.147  5555-5555  FlutterBranchSDK        xxx              D  notifyNativeToInit()
2024-06-20 14:08:06.155  5555-5555  Uri                     xxx              W  Error parsing port string.
                                                                                                    java.lang.NumberFormatException: For input string: ""
                                                                                                        at java.lang.Integer.parseInt(Integer.java:807)
                                                                                                        at java.lang.Integer.parseInt(Integer.java:915)
                                                                                                        at android.net.Uri$AbstractHierarchicalUri.parsePort(Uri.java:1154)
                                                                                                        at android.net.Uri$AbstractHierarchicalUri.getPort(Uri.java:1141)
                                                                                                        at android.net.Uri.toSafeString(Uri.java:425)
                                                                                                        at android.content.Intent.toShortString(Intent.java:11552)
                                                                                                        at android.content.Intent.toString(Intent.java:11502)
                                                                                                        at android.content.Intent.toString(Intent.java:11495)
                                                                                                        at java.lang.String.valueOf(String.java:4092)
                                                                                                        at java.lang.StringBuilder.append(StringBuilder.java:179)
                                                                                                        at io.branch.referral.Branch.initializeSession(Branch.java:1429)
                                                                                                        at io.branch.referral.Branch.access$400(Branch.java:75)
                                                                                                        at io.branch.referral.Branch$InitSessionBuilder.init(Branch.java:2444)
                                                                                                        at io.branch.referral.Branch.notifyNativeToInit(Branch.java:2538)
                                                                                                        at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.setupBranch(FlutterBranchSdkPlugin.java:447)
                                                                                                        at br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin.onMethodCall(FlutterBranchSdkPlugin.java:251)
                                                                                                        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
                                                                                                        at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
                                                                                                        at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
                                                                                                        at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:959)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:100)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:232)
                                                                                                        at android.os.Looper.loop(Looper.java:317)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8501)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
2024-06-20 14:08:06.213  5555-5555  FlutterBranchSDK        xxx              D  triggered onAttachedToEngine
2024-06-20 14:08:06.213  5555-5555  FlutterBranchSDK        xxx              D  triggered setupChannels
2024-06-20 14:08:06.213  5555-5555  FlutterBranchSDK        xxx              D  SDK Init
2024-06-20 14:08:06.504  5555-5555  FlutterBranchSDK        xxx              D  triggered onListen
2024-06-20 14:08:07.464  5555-5555  FlutterBranchSDK        xxx              D  triggered onInitFinished
2024-06-20 14:08:07.465  5555-5555  FlutterBranchSDK        xxx              D  BranchReferralInitListener - params: {"$utm_medium":"link","$deeplink_path":"\/zzz","~creation_source":0,"+click_timestamp":1718863682,"$utm_targeting":"","$utm_source":"utm_source","~feature":"link","+match_guaranteed":true,"$utm_brand":"utm_brand","~tags":["link"],"$utm_campaign":"always-on","+clicked_branch_link":true,"$utm_content":"link","fromPage":"deeplink","~id":111,"~campaign":"always-on","+is_first_session":false,"~referring_link":"https:\/\/zzz.xxx.com\/ggg?__branch_flow_id=333","~channel":"utm_source","$utm_store":""}

log details for disable tracking, this is not working:

2024-06-20 14:16:18.001  7653-7653  BranchSDK               xxx              V  Callback is br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin$1@546271c
2024-06-20 14:16:18.001  7653-7653  BranchSDK               xxx              V  Is auto init false
2024-06-20 14:16:18.001  7653-7653  BranchSDK               xxx              V  Will ignore intent null
2024-06-20 14:16:18.001  7653-7653  BranchSDK               xxx              V  Is reinitializing false
2024-06-20 14:16:18.001  7653-7653  BranchSDK               xxx              V  Session init is deferred until signaled by plugin.
2024-06-20 14:16:18.001  7653-7653  BranchSDK               xxx              V  Session initialization deferred until plugin invokes notifyNativeToInit()
Caching Session Builder io.branch.referral.Branch$InitSessionBuilder@a715f25
uri: links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id
callback: br.com.rsmarques.flutter_branch_sdk.FlutterBranchSdkPlugin$1@546271c
isReInitializing: false
delay: 0
isAutoInitialization: false
ignoreIntent: null
2024-06-20 14:16:18.009  7653-7653  BranchSDK               xxx              V  onActivityResumed, activity = yyy.MainActivity@6e076be
2024-06-20 14:16:18.009  7653-7653  BranchSDK               xxx              V  onIntentReady yyy.MainActivity@6e076be removing INTENT_PENDING_WAIT_LOCK
2024-06-20 14:16:18.010  7653-7653  BranchSDK               xxx              V  Read params uri: links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id bypassCurrentActivityIntentState: false intent state: READY
2024-06-20 14:16:18.010  7653-7653  BranchSDK               xxx              V  extractExternalUriAndIntentExtras links://xxx:///zzz?_branch_referrer=referrer&link_click_id=link_click_id yyy.MainActivity@6e076be
2024-06-20 14:16:18.010  7653-7653  BranchSDK               xxx              V  isIntentParamsAlreadyConsumed false
2024-06-20 14:16:18.012  7653-7653  BranchSDK               xxx              V  extractBranchLinkFromIntentExtra yyy.MainActivity@6e076be
2024-06-20 14:16:18.012  7653-7653  BranchSDK               xxx              V  isIntentParamsAlreadyConsumed false
2024-06-20 14:16:18.014  7653-7653  BranchSDK               xxx              V  processNextQueueItem onIntentReady
2024-06-20 14:16:18.014  7653-7653  BranchSDK               xxx              V  Queue is:
2024-06-20 14:16:18.015  7653-7653  FlutterBranchSDK        xxx              D  triggered onActivityResumed: yyy.MainActivity
2024-06-20 14:16:18.267  7653-7653  FlutterBranchSDK        xxx              D  triggered setupBranch
2024-06-20 14:16:18.279  7653-7653  FlutterBranchSDK        xxx              D  notifyNativeToInit()
2024-06-20 14:16:18.283  7653-7653  FlutterBranchSDK        xxx              D  triggered setTrackingDisabled
2024-06-20 14:16:18.334  7653-7653  FlutterBranchSDK        xxx              D  triggered onAttachedToEngine
2024-06-20 14:16:18.334  7653-7653  FlutterBranchSDK        xxx              D  triggered setupChannels
2024-06-20 14:16:18.334  7653-7653  FlutterBranchSDK        xxx              D  SDK Init
2024-06-20 14:16:18.642  7653-7653  FlutterBranchSDK        xxx              D  triggered onListen
rex-iotum commented 4 months ago

@qirong-zhang-ext which param are you using to grab the deeplink path? We use this plugin with tracking disabled and are able to use both normal URL deeplinking and Branch deeplinks on Android and iOS.

For normal URLs +clicked_branch_link is false, so we grab the link from +non_branch_link. If it was a Branch deeplink then +clicked_branch_link is true and we grab the URL from $canonical_url.