Redirect users to iTunes app store or google play store?
Asked Answered
C

8

52

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.

Clarkclarke answered 16/2, 2016 at 10:42 Comment(0)
L
74

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: https://mcmap.net/q/48374/-detect-if-device-is-ios
    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>
Lanfranc answered 28/9, 2016 at 14:10 Comment(1)
Doesn't work starting with iPad 7Bethina
G
24

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.

Gymnosperm answered 16/2, 2016 at 10:57 Comment(6)
The objective is not to use third party´s.Wallflower
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.Gymnosperm
can you navigate to a certain activity /page using this 3rd party if app is already installed?Ripp
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.Strongroom
I need to put appsflyer links in the apple/google link area but online blocks those links. Any way to overcome this?Cabala
I am having an issue with Google Ads blocking onelink to Apple Store, is there a way to write middleware that would handle this?Fra
W
20

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.

Wallflower answered 15/8, 2016 at 23:2 Comment(0)
K
7

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

Kitchen answered 16/9, 2019 at 13:34 Comment(1)
Firebase Dynamic Links are being decommissioned in August 2025. From the link provided, they state: "The service will shut down on August 25, 2025." They recommend other alternatives, including Universal Links, among others, and point to the evolution of the ecosystem of app links as their reason for sunsetting this service.Bresee
C
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.

Carmelinacarmelita answered 16/2, 2016 at 10:45 Comment(1)
One of the biggest disadvantages is that you can't edit the created url.Unsought
P
1

Plain javascript version:

<script>
window.addEventListener('DOMContentLoaded', (event) => {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('android') > -1) {
    window.location.href = 'https://play.google.com/store/apps/details?id=de.winterworks.ultimate_puzzle.winterworksGmbH.game';
  } else if (userAgent.indexOf('iphone') > -1 || userAgent.indexOf('ipod') > -1 || userAgent.indexOf('ipad') > -1) {
    window.location.href = 'https://apps.apple.com/us/app/puzzles-for-toddlers-kids/id1463362222';
  }
});

</script>
Popup answered 31/5, 2022 at 12:1 Comment(0)
S
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.

Sansculotte answered 16/2, 2016 at 11:37 Comment(0)
O
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/

Offcenter answered 23/5, 2021 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.