ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web āš”ļø
https://capacitorjs.com
MIT License
11.54k stars 983 forks source link

bug: Deferred Deeplink not working and `App.getLaunchUrl()` return undefined. #6480

Open Saqib92 opened 1 year ago

Saqib92 commented 1 year ago

Bug Report

Capacitor Version

šŸ’Š   Capacitor Doctor  šŸ’Š 

Latest Dependencies:

  @capacitor/cli: 4.7.3
  @capacitor/core: 4.7.3
  @capacitor/android: 4.7.3
  @capacitor/ios: 4.7.3

Installed Dependencies:

  @capacitor/cli: 3.2.2
  @capacitor/core: 3.2.2
  @capacitor/ios: 3.2.2
  @capacitor/android: 3.2.2

[success] iOS looking great! šŸ‘Œ
[success] Android looking great! šŸ‘Œ

Platform(s)

Android iOS

Current Behavior

App.getLaunchUrl() return undefined.

Expected Behavior

it should return deferred deeplink when coming from playstore or app store after installing application.

Code Reproduction

async getAppLaunch(){
    const launchUrl = await App.getLaunchUrl();
    console.log(launchUrl)
    if (launchUrl && launchUrl.url) {
      // parse the launchUrl URL to extract the deep link data
      const deepLinkData = new URLSearchParams(launchUrl.url.split('?')[1]);
      console.log(deepLinkData.get('ddl')); // prints "mydeeplinkdata"
    }
  }

Other Technical Details

I am implementing deferred deeplink when user clicks on my link it and they dont have app installed it will take them to respective store after installation App.getLaunchUrl() is not returning original clicked link.

User clicks on this link which takes them to playstore: https://play.google.com/store/apps/details?id=com.example.myapp&deeplinkdata=mydeeplinkdata after installation how can i get data in my app? Normal deeplinks are working. if user have app installed and click any link it open my app and takes them to respective content / page.

npm --version output: 9.3.1

node --version output: v16.13.1

pod --version output (iOS issues only): 1.11.3

Additional Context

i tried to setup play.google.com as my intent filter. tried this ADC Command adb shell am start -W -a android.intent.action.VIEW -d "https://play.google.com/store/apps/details?id=com.example.myapp&ddl=mydeeplinkdata" com.example.myapp

Nothing is working. haven't tried on ios but i need this for iOS Too.

kpturner commented 10 months ago

It is very disappointing that nobody has responded to this at all. The implication is that "deferred" deeplinks are not possible without a third party like AppsFlyer or Branch.io or some other home made solution. @Saqib92 did you reach a conclusion yourself?

Saqib92 commented 10 months ago

It is very disappointing that nobody has responded to this at all. The implication is that "deferred" deeplinks are not possible without a third party like AppsFlyer or Branch.io or some other home made solution. @Saqib92 did you reach a conclusion yourself?

I ended up using AppsFlyer SDK.

kpturner commented 10 months ago

Out of interest did the vanilla capacitor solution work correctly when a "normal" deeplink was clicked and the app was not already installed? I mean did it automatically take the user to the relevant store to install the app even though the app had no clue what the details of the deeplink were when it started up?

Saqib92 commented 10 months ago

Out of interest did the vanilla capacitor solution work correctly when a "normal" deeplink was clicked and the app was not already installed? I mean did it automatically take the user to the relevant store to install the app even though the app had no clue what the details of the deeplink were when it started up?

I have no idea as i already had a website ready. If user have no app installed it will go to website version of that link. You can add install app link on your website.

kpturner commented 10 months ago

Oh I see - no I am referring to the type of deferred deep-link that the likes of AppFlyer and branch.io provide where, if clicked on a mobile device, will open the app if installed or go to the store (for the app to be installed) before doing so.

It sounds like you have implemented something different.

terencehonles commented 7 months ago

I hadn't heard of this, but it seems like those services are using https://developer.android.com/google/play/installreferrer/library / https://developers.google.com/analytics/devguides/collection/android/v4/campaigns for Android at least.

I would not classify this as a bug, because deep links don't imply deferred links which need cooperation from the device's app store to pass whatever parameters caused the install. If there is no communication between the device and the app store (even if it's locally on the device) then there's no way for the app to know how it was installed.

Instead this is a feature to support install referrers and you can see if there's a plugin that already exists that does this, or write your own. Collecting the referrer information looks relatively straightforward and could also be done in your main activity, but I'm not sure how trivial it would be to set the launch URL (you may need to expose this as a plugin method yourself).

tybro0103 commented 6 months ago

Tangent here, but I've noticed this official example here:

const checkAppLaunchUrl = async () => {
  const { url } = await App.getLaunchUrl();
  console.log('App opened with URL: ' + url);
};

Since the result of getLaunchUrl() can be undefined, this is going to throw an error every time the app is launched without a link/url. Perhaps a better example code would be like:

const checkAppLaunchUrl = async () => {
  const launch = await App.getLaunchUrl();
  console.log('App opened with URL: ' + launch?.url);
};