Git Product home page Git Product logo

node-deeplink's Introduction

node-deeplink Build Status styled with prettier

Easily create express endpoint to handle mobile deeplinks in your web server

Takes away the pain of forwarding users to the right app store / mobile app depending on their platform.

Important update

In ios >= 9, Apple has made it impossible to provide a smooth user experience to redirect user to app / fallback to app store from javascript. Their clear direction is pushing towards using Universal Links instead.

For more details, see issue #9 and this blog post.

To get the best user experience, it's probably better to look at Universal Links for ios and App Links for Android.

If you already started using Universal Links, you can still use this module as a fallback mechanism for older ios versions.

Use case

Suppose you have a custom url scheme app:// handled by your mobile apps. You want to create a universal "smart" link that will know where to send the user:

  • If the user has the app installed, open the app with the deeplink.
  • If the user doesn't have the app installed, send to the app store to download the app (google play / itunes).
  • If the user doesn't have a supported phone, send to a fallback url.

Usage

Example:

var express = require('express');
var deeplink = require('node-deeplink');

var app = express();

app.get(
  '/deeplink',
  deeplink({
    fallback: 'https://cupsapp.com',
    android_package_name: 'com.citylifeapps.cups',
    ios_store_link:
      'https://itunes.apple.com/us/app/cups-unlimited-coffee/id556462755?mt=8&uo=4',
  })
);

This example creates an endpoint GET /deeplink in your web server.

Assuming your server address is https://acme.org, you can use the link https://acme.org/deeplink?url=app://account so when users will open it the app will open with app://account deeplink or the users will be redirected to download the app in case they don't have it.

Note on url encoding: to avoid problems with url parsing libraries, the deep link (app://... part) has to be url encoded. node-deeplink will decode the url correctly. So, in the above example, the link is actually https://acme.org/deeplink?url=app%3A%2F%2Faccount. Here's an example of url encoder/decoder.

Available options

node-deeplink currently only supports Android and ios.

Options to pass on to node-deeplink are:

  • url: mandatory. The deeplink url you want the user to be directed to e.g. app://account.
  • fallback: mandatory. A fallback url in case the user is opening the link via an unsupported platform like desktop / windows phone etc. In such case, the fallback url will be opened in the user's browser like a normal link.
  • android_package_name: optional. In case you want to support Android deep links, pass your app's package name.
  • ios_store_link: optional. In case you want to support ios deep links, pass your app's itunes url. You can get it here.
  • title: optional. Title for the intermediate html page. Defaults to an empty string.

Query params

When a request comes in, the following query params are checked:

  • url: optional. If available, will prefer this deeplink url over the one from the options.
  • fallback: optional. If available, will prefer this fallback address over the one from the options.

Behaviour

node-deeplink works by first sending the user to an html page with a user-agent sniffing script. After figuring out the user's device, it redirects them to the predefined deeplink. In practice, after clicking the link, the browser will be opened for a very short moment and then the redirect will happen.

TODO

  • Better user-agent discovery.
  • Enable non-express use.

node-deeplink's People

Contributors

damiankorem avatar egg- avatar linx05 avatar mderazon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-deeplink's Issues

it doesn't work for me

For some reason on android just nothing happens.

Only in fallback desktop browser is executed

Can anyone tell me what's going on?

Struggling to get simple case working

I am trying to do "Connect Instagram" in my React Native iOS app. Instagram API doesn't allow URL schemes as valid redirect_uri's, so I assume I need to redirect to my server first, then use this library to redirect back to my app.

First I set up the URL scheme in xcode as: myapp

Then I am able to hit: myapp://

In Instagram Manage API, I set the redirect_uri to: https://myserver.com/linkinstagram?url=myapp%3A%2F%2F

My server has:

app.get('/linkinstagram', deeplink({
  fallback: 'https://myfallback.com'
}));

However hitting https://myserver.com/linkinstagram?url=myapp%3A%2F%2F ends up going to the fallback. I tried this in iOS simulator as well as on an actual device. Any suggestions?

Incorrect behaviour on ios devices

Hey,

Thanks for the great package. We haven't updated our codebase for a while (everything was working just fine before), but now I have noticed that on iOS when the default browser is Safari - you never get redirected to the app. You just go to the App store (the app is installed).

If I set my default browser to chrome - it works just fine. It also doesn't work as expected on Opera though.

And - Safari used to work fine some time ago, but that was probably the case before iOS 14.

add fallback url as query param

In addition to setting the fallback url as an option when setting up the endpoint, give the ability set the fallback url from a query param.

When a request comes GET /deep?url=...&fallback=..., if a fallback is available in the query params, use it instead of the hard coded fallback address from the options. Otherwise, use the options fallback.

Firefox on Android endless redirects

Using node-deeplink, Firefox on android constantly redirects to the web version of the play store in an infinite loop.
I have not experienced this issue on other android browsers such as Chrome, Opera, webview.

Firefox version: 68.7.0
node-deeplink version: 0.6.0

Better Android Intent url

I'm trying access the url directly from google chrome on my phone and it just stays on a blank page. After some research, I found out that the problem is with android_intent it's missing S.browser_fallback_url parameter. here's the full var:

var android_intent = 'intent://' + path + '#Intent;scheme=' + scheme + ';package=' + androidPackageName + ';S.browser_fallback_url=' + fallback + ';end;'

Getting an alert dialog saying download faild

screen shot 2015-08-13 at 9 33 47 am

Hey,

I am a newbie at node and javascript. If you could help me out here that would be great.

I am getting the attached dialog when I hit the deeplink url.

I have made a deeplink function in the core server middleware. Whenever the server hits http://localhost:3000/deeplink\* the following gets executed. The url query parameter is encoded but still this issue persists.

exports.deeplink = function(req, res, next) {
  var link = deeplink({
      fallback: 'http://' + req.headers.host,
      ios_store_link: 'https://itunes.apple.com/us/app/cups-unlimited-coffee/id556462755?mt=8&uo=4',
  });
  link(req, res, next);
};

How implement same model with node http end point

I have created one http server and listening on port 2000.My deeplink is http://host:2000/deep?url=fb
Now My server is handling request as

var http = require('http'); 
var deeplink = require('node-deeplink');
http.createServer(handleRequest).listen(2000);
function handleRequest(request, response){
    try {
        //log the request on console
        console.log(request.url);
       if(request.url=="/deep"){
		    console.log("deeplink:-   "+deeplink);
			deeplink({ 	
				fallback: 'https://na.nofer.com',
				android_package_name: 'com.na.nofer'	
			});

	   }
    } catch(err) {
        console.log(err);
    }
}

app is not installed in my android device .once i have requested in android browser ,request is landing but it is not directing to nieghter fallback nor app store.
Can some one suggest on same.

No longer working on Android marshmallow devices

I just testing my deeplink implementation, that working fine on Android 4 and Android 5, but found the deeplink is not working properly on Nexus 5 with Android marshmallow. It seems the redirection does not work anymore on Android 6.

Critical security vulnerability in html-inline

There is a critical vulnerability in html-inline caused by security issues on several modules, most of them abandoned or unmaintained.
I've taken care of that by removing html-inline and reimplementing this task.
I will provide a PR

not working with chrome & how the smart link work ?

I just making some simple project with node-deeplink packatge. it work only when i open it with my phone browser (non-chrome) . but it keep throwing me to the application store, dispite of when i have the app, it should opening the app directly right ? or there is someting i missing with the 'smart' link ?

Why sending url in params is require ?

Hello,

I dont' understand why should I send url in params while doing a get request to my server. Here's my code for example.

app.get('/deeplink', deeplink({
  fallback: 'https://www.my-site.com',
  android_package_name: 'com.my-site.gramlopa',
  ios_store_link: 'https://itunes.apple.com/us/app/my-site'
}))

Why should I send url in params ?

http://my-site.com/deeplink?url=cups%3A%2F%2Fmain

it said in the documentation

so when users will open it the app will open with app://account deeplink or the users will be redirected to download the app in case they don't have it.

So does account should be the apple id of the user in case of the user is using an Apple device and doesn't have the app ?

Thanks

Please Verify My Code

I am trying to pass the request parameter to the URL. But it is returning undefined.


var express = require('express');
var deeplink = require('node-deeplink');

var app = express();

let anuncioId;
app.get(
'/anuncio/:codigo',
function (request, response, next) {
anuncioId = request.params.codigo;
console.log('primeiro ' + anuncioId)
return next();
},
deeplink({
url: detroca.app://detroca/anuncio/${anuncioId},
fallback: 'https://www.detroca.com.br',
android_package_name: 'com.app.detroca',
title: Anuncio: ${anuncioId}
})
);

app.listen(3000);
console.log('deeplink service listening on port 3000');

Don't open playstore if app is not installed.

I have different path rules that I can open App Store or not open.

If i want to open the App Store when my app is not installed to my phone, I just set the ios_store_link. But if I want to redirect to fallback url instead of opening the App Store, I omit the ios_store_link.

This is possible on ios but not on android.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.