33

I'm looking for an easy solution to post one link of my app e.g. on Facebook and it should automatically redirect to the right app store if the user accesses it with a mobile device. Otherwise the users should be redirected to my website.

iOS app: http://itunes.apple.com/de/app/dawawas/id588285122

Android app: https://play.google.com/store/apps/details?id=de.conceptspace.dawawas.greenturtle&hl=en

Website: https://www.dawawas.com/

Florian
  • 401
  • 1
  • 4
  • 6

7 Answers7

51

If you want to roll your own and not use a third party, there's also a Javascript solution:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
<script>
function getMobileOperatingSystem() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

      // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/i.test(userAgent)) {
        return "Windows Phone";
    }

    if (/android/i.test(userAgent)) {
        return "Android";
    }

    // iOS detection from: http://stackoverflow.com/a/9039885/177710
    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        return "iOS";
    }

    return "unknown";
}</script>

<script>
function DetectAndServe(){
    let os = getMobileOperatingSystem();
    if (os == "Android") {
        window.location.href = "http://www.Androidexample.com"; 
    } else if (os == "iOS") {
        window.location.href = "http://www.IOSexample.com";
    } else if (os == "Windows Phone") {
        window.location.href = "http://www.WindowsPhoneexample.com";
    } else {
        window.location.href = "http://www.NowherLandexample.com";
    }
}
</script>
</head>
<body onload="DetectAndServe()">
</body>
</html>
Community
  • 1
  • 1
brianfit
  • 1,511
  • 1
  • 14
  • 31
21

U mean something like this?

Onelink

How to use onelink.to

onelink.to is the easy and fuss-free way to link to your app!

Just add the URLs to your app and we will determine which to use every time someone is using your onelink.to address.

You can use onelink.to free of charge, both for private and commercial use. We have no plans to change that.

And you can also add a fallback url to your website.

Hope this helps u out.

Strider
  • 4,044
  • 3
  • 18
  • 32
  • The objective is not to use third party´s. – Chirry Oct 30 '16 at 04:06
  • 10
    `The objective is not to use third party´s` where do u read this? He wants an **easy** solution, so third party can be the solution he wants. – Strider Oct 31 '16 at 08:52
  • can you navigate to a certain activity /page using this 3rd party if app is already installed? – Emil Jul 13 '17 at 00:02
  • 1
    The fallback url doesn't work well in oneline. I am redirected from my computer to the Play Store on the computer instead of the fallback link. – Guy Sela Dec 13 '17 at 18:44
  • I need to put appsflyer links in the apple/google link area but online blocks those links. Any way to overcome this? – Uri Abramson Dec 02 '18 at 12:11
17

In PHP you can use something like:

<?php

$iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS   = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");

//do something with this information
if( $iPod || $iPhone ){
    //browser reported as an iPhone/iPod touch -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($iPad){
    //browser reported as an iPad -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($Android){
    //browser reported as an Android device -- do something here
    $string = "Location: <<Google Play Link>>";
    header($string);
    die();
}else if($webOS){
    //browser reported as a webOS device -- do something here
    $string = "Location: <<Your Page link>>";
    header($string);
    die();
}else{
    //browser reported as PC -- do something here
    $string = "Location: <<Your Page link>>";
    header($string);
    die();
}


?>

You can use links for iTunes or Android, respectively:

itms-apps://itunes.apple.com/app/<<App ID>>
market://details?id=<<Package id>>

I don´t remember the source, but at least it works for me for sharing in other apps like Whatsapp, but unfortunately is not working on Facebook.

The problem in Facebook is that they use the metadata of the final link on the path of redirections, and the link points to GooglePlay store.

Chirry
  • 580
  • 5
  • 12
4

You can create a short link for iTunes and Google Playstore at once with http://toSto.re.

Just select a name and the enter the different app store urls you get a link like toSto.re/facebook which directs automatically to the right url depending on the user agent and even supports Google Analytics itegration for some stats.

Fabian
  • 165
  • 1
  • 2
4

We were looking for a solution to direct users to the proper App Store, plus carry along extra metadata, so when the app is launched after App Store install, it would know where the user came from and launch a specific activity.

So, if any others like me hits this Stack Overflow article, a hint for obtaining both the OP's requirements, plus the extra benefits of carrying along extra metadata (and track all the conversions) is to look at Firebase Dynamic Links: https://firebase.google.com/docs/dynamic-links

0

You can create that functionality by Backend.Just create one PHP script or what ever language your backend is using.Here I am asuming PHP.

Just Create one php script that will determine that you are using iphone or android or web.check this link for php script Mobile or desktop browser detection and redirect to respective web page

And redirect it to respective Url.Like You can use a url of site with php file https://www.dawawas.com/detect_mobile.php

a user will share this url and when another user will tap on above link then php script will determine whether it ios or android or web and repective link will open automatically via redirection

I have implemented this in our ios app.

Community
  • 1
  • 1
Anil solanki
  • 942
  • 4
  • 18
0

You can use simple javascript code

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<script>
    $(document).ready(function () {
        if (navigator.userAgent.toLowerCase().indexOf("android") > -1) {
            window.location.href = 'market://details?id=<appID>';
        }
        if (navigator.userAgent.toLowerCase().indexOf("iphone") > -1) {
            window.location.href = 'itms-apps://itunes.apple.com/app/<appID>';
        }
    });
</script>

Or if working with .net can use

Dim systOS = Request.UserAgent.ToString.ToLower
    
    If (systOS.IndexOf("android").ToString.ToLower > 0) Then
        Response.Redirect("market://details?id=com.manomayelectronics")
        
    ElseIf (systOS.IndexOf("iPod").ToString.ToLower > 0) Then
         Response.Redirect("itms-apps://itunes.apple.com/app/com.manomayelectronics")
 End if

OR if using PHP can use

<?php

$iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");


//do something with this information
if( $iPod || $iPhone ){
    //browser reported as an iPhone/iPod touch -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($iPad){
    //browser reported as an iPad -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($Android){
    //browser reported as an Android device -- do something here
    $string = "Location: <<Google Play Link>>";
    header($string);
    die();
}

Regards Multicore Solutions. https://multicoresolutions.in/

Rohitkumar
  • 131
  • 1
  • 6