Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Can universal links work in a SPA scenario? #36

Closed
TonivdW opened this issue Jan 22, 2016 · 16 comments
Closed

Can universal links work in a SPA scenario? #36

TonivdW opened this issue Jan 22, 2016 · 16 comments

Comments

@TonivdW
Copy link

TonivdW commented Jan 22, 2016

I have the following use case:
My application is a SPA. The same code that is running the site is also running the app.
I do not want my site crawled and indexed via Google, except for the home page, so I have

<META NAME="ROBOTS" CONTENT="INDEX, NOFOLLOW">

in the index.html
I have tens of thousands of subpages like: https://ttapp.nl/#/poule/1011994
I want all these pages to open in the app, wherever on the internet such a link is clicked.
For Android I have configured universal-links and tested it locally through adb. These subpages all work as expected. But I can't get my head around what to configure for the

<link  rel='alternate' ...>

tag. Surely I can't possible list all subpages, and since there is just one occurrence of the HEAD- tag, being a SPA, all the subpages share this same declaration.

Can this be made to work? Any advice would be appreciated.

@nikDemyankov
Copy link
Member

If you want the app to be open on all links, like https://ttapp.nl/#... then probably your config.xml is something like:

<universal-links>
    <host name="ttapp.nl" scheme="https" />
</universal-links>

When you execute cordova build plugin generates ul_web_hooks/android/android_web_hook.html in your Cordova project. It's content will be:

<head>
    <link rel="alternate" href="android-app://<YOUR_APP_PACKAGE_NAME>/https/ttapp.nl" />
    <!-- Your other stuff from the head tag -->
</head>
<body>
    <!-- Your page content -->
</body>

So my guess is that you need to add on your index.html that <link /> tag.

If you don't want to do any changes in index.html - you can use Sitemap. This way, you can define this link tag in it, and avoid your web content being crawled by Google.

@TonivdW
Copy link
Author

TonivdW commented Jan 22, 2016

That was also my first thought, but I don't seem to get it to work.
I am assuming that it is the index.html on the website that needs this <link rel='alternate' ..> in order for the Google crawler to see the reference to the app? The index.html in my app does not contain this setting.
I have seen the Google crawler come by and retrieve the index.html from my site, but still no luck.
I must be missing something obvious...

@nikDemyankov
Copy link
Member

In more details regarding web integration of the Android app and website you can read in this section of the documentation. You need 3 things:

  • Add <link /> tag on your website.
  • Verify your website on webmaster tools.
  • Connect your app in the Google Play console.

Also, a good video about all of that is that one.

I am assuming that it is the index.html on the website that needs this <link rel='alternate' ..> in order for the Google crawler to see the reference to the app? The index.html in my app does not contain this setting.

Your app's index.html doesn't have to hold the <link /> tag. It is only for the website. Or, you can create a Sitemap, if you don't want to modify the actual pages.

From the google documentation:

To indicate which app content you’d like Google to index, simply add link elements either to your existing Sitemap file or in the element of each web page in your site, in the same way as you would for web pages.

I see, that you already added link tag for your website (https://ttapp.nl). So my guess is that this should be enough. Now you need to do Webmaster tools verification, publish the app and connect it on google play console. Not sure, that you can test the app on the real links without that. That's why there is a local testing available.

@TonivdW
Copy link
Author

TonivdW commented Jan 23, 2016

I did all these steps, except 'publish the app'. I normally want to see things work before I publish, but I gather that won't work for these kind of applications. Now I can only hope I can do a 'test' by publishing the app to the beta-channel of the Play Store...

@TonivdW
Copy link
Author

TonivdW commented Jan 24, 2016

Hmm, all this time I used Chrome for testing. I was visiting a webpage that contains a deep link to my website-address. Chrome just opened the page on the site. However, if I visit this same page from the default browser on my phone it opens the app. Using the same link in an e-mail or in a Whatsapp conversation all open the app perfectly. Chrome however does not. Is this a Chrome bug/issue? Or is it supposed to work like this? (but then, why?)

@nikDemyankov
Copy link
Member

Sorry for not answering sooner: been really busy...

That's an interesting notice. If it works for email and other browsers - then it's totally has something to do with the Chrome. After some googling found, that you are not the only one, who stumbled upon "Chrome not supporting deep linking". For example, this and that. But in your case you are using regular https scheme, so it should work in chrome... Will try to do some more research.

By the way, have you tried that on other devices with chrome? Tried to reinstall chrome on the device?

@TonivdW
Copy link
Author

TonivdW commented Jan 25, 2016

I have now tested this with a fresh install of Chrome on another device and there I see the same behavior. Firefox does the same, it also opens the site, ignoring the installed app.

@nikDemyankov
Copy link
Member

Thanks for the testing. Don't have a way to test it at the moment myself.

That is a strange behaviour from those browsers. Logically, if a link is opened fine from email or messenger, or some default browser - then the intent is sent properly by those apps and captured as it should by yours. When you open the browser and tries to open the link as a search result in Chrome/Firefox - then they are not sending any intents to the app, or ignoring it at all. Why they are doing so - that's a good question. For example, they just handle all http/https links on they're own and don't care about other stuff. Another reason can be that the app is not actually connected to the site via Google Play console as stated here. Can't find anything more useful at the moment. Will keep looking as well.

@TonivdW
Copy link
Author

TonivdW commented Jan 27, 2016

(comment moved from wrong issue)
For the record: I also tested with a hyperlink to my app in a Facebook posting, and there you get yet another behavior. The link first opens in a kind of internal browser, you have no choice. After that you can open the menu on the top right and then you are presented the option to open the link in the app.

_44gkim23ob5mhzpygdhv7ck0heiju9-mydacgcyrysnuishfusyn7i1hd0ukrm2xpggmqp3r4d8dizh7josdqka2gq s853

@ivansoldoid90t
Copy link

Hi, I am having the same problem as TonivdW.
When i click my app link from Chrome browser it doesn't work but if i open it from my default browser or email application it will open the application. Could someone resolved this issue?
Thanks.

@nikDemyankov
Copy link
Member

Hi,

@TonivdW did you manage to solve this somehow?

@TonivdW
Copy link
Author

TonivdW commented Mar 3, 2016

No, I have not. Apparently it is up to the app (in this case Chrome) to decide how to handle plain https url schemes. Chrome decides to ignore the presence of a UL config and seems to decide: if you browsing within Chrome, you want to stay in Chrome, even if a UL config for the site is present. Like I showed some comments back, Facebook has yet another approach, opening is an own webview within Facebook and then offering the possibility to switch to the app. It's a mess...

@nikDemyankov
Copy link
Member

Understood, thanks for the info.

@conor-mac-aoidh
Copy link

See "Universal Links Still Don’t Work Everywhere" at the end of this post:

https://blog.branch.io/ios-9.2-deep-linking-guide-transitioning-to-universal-links

@nikDemyankov
Copy link
Member

@conor-mac-aoidh good info, thanks.

@nordnet-deprecation-bot
Copy link
Contributor

👋 Hi! Thank you for your interest in this repo.

😢 We are not using nordnet/cordova-universal-links-plugin anymore, and we lack the manpower and the experience needed to maintain it. We are aware of the inconveniece that this may cause you. Feel free to use it as is, or create your own fork.

🔒 This will now be closed & locked.

ℹ️ Please see #160 for more information.

@nordnet nordnet locked and limited conversation to collaborators Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants