Yes, this is possible. However it requires some workarounds, because you can't actually detect if an app is installed in situations like this. Apple and Google have limited that for obvious privacy reasons.
The basic flow is this:
- Attempt to open the app via a deep link (Universal Links in most situations, or a custom URI scheme redirect wrapped inside a regular HTTP/HTTPS link in rare cases)
- If this attempt fails, use your fallback URL (the actual URL of a Universal Link, or the page where you wrapped your custom URI scheme redirect) to then forward the user to the App Store to download.
The real magic happens when you are able to do deferred deep linking. This means storing the value of the deep link remotely so you can send the user to the right place in your app, even when the app is not installed yet.
This is exactly how Branch.io (full disclosure: I'm on the Branch team) works. You can find a much better overview of the process on this page.