11 comments

[ 2.9 ms ] story [ 19.9 ms ] thread
Is this a whole blog post for a simple backend that just routes based on the User-Agent?
I thought it was something clever, but it shows as URL which redirects from browser to App Store, after two several tabs.

TL;DR: it is HTTP redirect based on User-Agent header

it's just a server side redirect based on the user agent headers
Err wut... redirecting based on user agents?
I hate QR codes. I don't trust them.
Use a standalone app to scan it, inspect the URL before open, easy as that.
For our apps Slyp and SlypBusiness, we had the same QR code for each app open Playstore/Appstore page of the app depending on the phone.

Just have a branded link (like https://slyp.app/Slyp or https://slyp.app/SlypBusiness) to the official web page and have the js in that page open the original Playstore/Appstore page.

And yes, we used userAgent for identifying the platform.

If anyone is interested, here is the code

    window.addEventListener('DOMContentLoaded', (event) => {
        let app = 'Slyp'

        var userAgent = navigator.userAgent.toLowerCase();
        if (userAgent.indexOf('android') > -1) {
          window.location.href = `https://play.google.com/store/apps/details?id=com.ndcurve.${app}`;
        } else if (userAgent.indexOf('iphone') > -1 || userAgent.indexOf('ipod') > -1 || userAgent.indexOf('ipad') > -1 || userAgent.indexOf('mac') > -1) {
              if (app === "Slyp")
                window.location.href = 'https://apps.apple.com/app/id6504203214';
              else if (app === "SlypBusiness")
                window.location.href = 'https://apps.apple.com/app/id6504781331';
              else
                window.location.href = 'https://slyp.app';
        } else {
          window.location.href = `https://play.google.com/store/apps/details?id=com.ndcurve.${app}`;
        }
    });
I agree with the other commenters that this is a pretty simple engineering problem, but I still enjoyed reading about edge cases the author worked to address (they could have taken the easy road with this but tried not to). I forgot that Safari on iPad doesn't specify iPad in user agent headers