7

I want to implement deferred deep linking in my iOS app as a means of tracking referrals. When a user of my app wants to refer a friend, I'll generate a URL that has a unique referral code. When the other person receives the link and opens it, I want it to take them to my app's page in the App Store. Then if they install my app, when it first opens, I need a way for it to read the referral code from the original URL.

I've found may pages about deferred deep linking on the web but none that really explain how to do it. Instead, these pages all end up telling you to install some third-party code or use some commercial service. This isn't what I'm after. I want to learn how to do this myself.

There are lots of old pages out there that recommend convoluted and error-prone solutions, like tracking the user's IP address, putting the referral code into the clipboard, or somehow obtaining it from a cookie in a web view. I don't think these are the correct solutions to be using in 2022.

If anyone can recommend the appropriate resource, I'd appreciate it.

If it is the case that Apple simply doesn't want us to do this and doesn't provide any support for it, then I'd like to know that too. I was under the impression that they did, but maybe I'm wrong.

Thanks, Frank

Flarosa
  • 1,287
  • 1
  • 13
  • 27

2 Answers2

3

The good news is, I found a solution. I could construct a web page that redirects the user to the app store, but before doing so, copies some text into their clipboard (without telling them or asking them to do anything). Then later if they install my app I can get the text by pasting from the clipboard. I tested this idea and it works.

The bad news is, starting with iOS 16, Apple now asks you for permission to paste. So if you try to do this, your user will launch your app and immediately get promoted with a message asking them to allow a paste from Safari. I expect most users will deny the request and just the fact that they saw it will erode their trust in the app (I know I wouldn't trust an app that tried consume my clipboard without a direct command from me).

Flarosa
  • 1,287
  • 1
  • 13
  • 27
  • Yes, it looks like the only way is to ask the user to press the button to COPY credentials on your webpage, and then in the mobile app, mention that you will use one clipboard to paste credentials. – Sergey Kopanev Aug 28 '23 at 14:52
-1

Apple's Universal Links allow for this (would understand the difference between the typical URL Scheme and Universal Links as threshold). This assumes you're willing to do some lifting server-side along with other hurdles on the iOS side, largely administrative.

A benefit of Universal Links and the server-side work is that you're provided a fallback webpage if a user does not have the app installed. Since the app should open if downloaded, you could typically just redirect to the app store from this URL. In this case, though, before any redirects, you could execute an operation to decode the unique params passed in the URL and persist it in a remote data store. The data encoded needs to be required and verifiably unique during your registration -- email seems ideal.

If that's feasible, your standard registration flow could require email verification with a link to the app as a mandatory entry point (think slack magic link). When the user submits his/her email to verify, you could first check that email against your data store to see if it maps to any previously decoded referrals saved from the flow above. If so, you could generate a unique link for this email to your app with params that will direct the deferred/deep link.

Greg Brodzik
  • 1,765
  • 7
  • 9
  • I'm not following how my server would know the user's email address at the time it processes the URL and sends out the redirect. The URL would come from someone making a referral. That person is not asked to enter the email address of the person being referred. Even if they did, that person could end up registering with a different address. – Flarosa Oct 06 '22 at 15:19
  • My basic understanding is that if you hit iOS with a custom URL scheme for an app that is not installed, it is will cache the URL and deliver it to that app if it is installed later. Is this still accurate? – Flarosa Oct 06 '22 at 15:37
  • My apologies - there was some confusion on my end re exactly what you intended to track with your system. If there was any sort of cache, then this would seem trivial, and would expect it would be documented somewhere. I became the deep linking guy on a team I was on -- albeit a few years ago -- and I can't recall coming across anything like this. That said, fwiw, I recall running Charles/MITM helped surface network activity surrounding all this on device (debugging headache). Might be a place to start. wishing you luck and interested to see if there exists a caching solution as you suggest. – Greg Brodzik Oct 06 '22 at 18:19