Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Universal links with redirects not working in iOS

Company domain links end up in the iOS app. Links with redirects through MailChimp to company's website from email website end up in the iOS app.

But links which redirect to company domain website through MailChimp tracking link tapped in mail app (Mail, Gmail etc) end up in Safari in company's web site.

Is there any workaround to make MailChimp email links with redirect work as universal links and bring up the iOS app?

like image 994
Yevheniia Zelenska Avatar asked Mar 13 '17 19:03

Yevheniia Zelenska


2 Answers

I have actually developed a workaround for this.

We created an app that had the function to allow a user to sign in by generating a magic access link. The user would download and install the app, enter their email address and the server would send them an email containing a link in the form of: https://www.example.com/app/accesslink/{{tokenHere}}

We created an AASA file and uploaded it to our domain (www.example.com) for example :) https://developer.apple.com/library/content/documentation/General/Conceptual/AppSearch/UniversalLinks.html

Most users could generate an access link fine, tap it and the app would load. We had handlers on the app to pick up the token and authenticate them etc.

The problem came when some email providers rewrote the access link in the email. This especially happened to corporate users who had URLblockers installed.

To work around this we created a rewrite rule on the server to rewrite www.example.com/app/accesslink/{{anythingHerer}} to a static file on the server called '404accesslink.html' (the filename is arbetary, the server was asp.net IIS in this case). We then edited the '404accesslink.html' as follows to include the following meta:

<script>
    document.writeln('<meta name="apple-itunes-app" content="app-id={{APP_ID_HERE}}, app-argument=' + document.location.href + '">');
</script>

Because the file was served over a rewrite the location.href value was an exact match for the access link. This tricked iOS into opening the app and passing the path to it. We could then pick it up in the handler as normal and authenticate the user.

We wrote some simple instructions in case opening the app wasn't automatic and the page was displayed (although in our tests this didn't happen).

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <script>
    document.writeln('<meta name="apple-itunes-app" content="app-id=XXXXXXXXXX, app-argument=' + document.location.href + '">');
  </script>
  <style>
    body {
        padding-top: 5%;
        color: #FFF;
        font-size: 1em;
        font-family: Arial, Helvetica, sans-serif;
        text-align: left;
        background: #00338D;
        margin: 50px;
    }
    h1 {
        font-weight: normal;
        font-size: 1.8em;
    }
    a {
        color: #FFF;
        font-weight: bold;
        text-decoration: none;
    }
  </style>
  <title>XXXXXXXXX</title>
  <body>
    <h1>Please select 'Open' in the app banner displayed at the top of this page to open the app with your access link.</h1>
    <p>If you do not see the app banner above then please close your browser and sign into the app using your email address and the password you used to register for the event.</p>
    <p>If you do not know your password then you can <a href="https://XXXXXXXXXXXXX/account/mobileforgot/">reset it by following this link</a>.</p>
    <p>Thank you,</p>
    <p>XXXXXXXXXXXXX team</p>
  </body>
</html>

The meta would probably be better if it was set and rendered server side as opposed to using JS client side, but it worked none the less.

Before this was done: If any system rewrote/wrapped the app link the app wasn't associated with the new URL and when the user tapped the URL it was opened in Safari.

After this was done: If any system rewrote/wrapped the app link the app wasn't associated with the new URL and when the user tapped the URL it was opened in the app.

like image 69
Ben Edge Avatar answered Nov 03 '22 01:11

Ben Edge


Universal Links are based on the actual URL of the link being opened. This means if you wrap the link in a redirect (as MailChimp does), Universal Links won't function.

To work around this, you'll need to disable click tracking on MailChimp. However, it may still not work in every app (Gmail, for example) if that app doesn't support Universal Links.

Branch.io (full disclosure: I'm on the Branch team) has been working with some of the larger email platforms to fix this issue and enable both Universal Links and click tracking, but up until this point MailChimp has not been interested. Feel free to let them know this is something you would like to see!

like image 43
Alex Bauer Avatar answered Nov 03 '22 02:11

Alex Bauer