Firebase Cloud Messaging + DeepLinking

Ilia Pavlovskii
Bootcamp
Published in
4 min readAug 28, 2023

--

Not long ago, I started developing my projects and noticed that simply buying ads and urging users to return to the app may not be enough. I implemented a new feature and wanted to test the theory of how quickly users would find out about it. For such purposes, there is a section in Google Play called “What’s New.” However, most users have updates enabled in the background, and they don’t read what’s new. Afterward, I sent out an email newsletter — the result was a conversion rate of less than 10 percent. The conclusion is that people are lazy and don’t want to search for a new item in the description; they need everything to be done in one click.

Introduction

To address this issue, we need to teach the app to navigate to any point within the application based on just one message. Let’s remove all possible restrictions and formulate the task as follows: we must be able to open any screen of the application via a link. The solution is deep linking.

It might seem that sending an email with a hidden deep link should be more than enough. However, we can’t exclude the factor that not all users have their mail client set up on their phones. Not everyone can open it there. So, we narrow down the usage options and arrive at a suitable solution for us — push notifications.

Yes, I could use SMS for the distribution as well. However, it’s not cost-effective. SMS costs money, and only 25% of the users in the system registered via phone number. We would like to have a distribution method that reaches 100% of the users.

Problems

So, in order to implement this idea, all we need to do is add a deep link as a pending intent when the user clicks on our push notification. It seems like a simple task, but…

If you’ve taken the path of least resistance, like I did, and decided to stick with using a simple notification composer, then here’s the problem. In the classic notification composer, there is no built-in capability to pass a deep link. You can set your own custom arguments, but you’ll have to handle them manually. This means that if you want to do something custom, the value of the Firebase Cloud Messaging library is zero. Why would I bother with a library that doesn’t help at all?

All parameters from FCM Console will have to be manually captured and used to form the FCM message. But wait, could it be that Google didn’t include the possibility of handling deep links out of the box?

Actually, it does exist, but this feature is only open for use in sending messages through your own backend. I don’t want to set up my own backend just for this. I was hoping to stick with Firebase services alone. Furthermore, for a simple advertising campaign, I would have to implement not only user token tracking but also analytics. And that starts to resemble a full-fledged backend.

Research & reverse engineering

With research, I found several solutions, but they involved a significant amount of modification either to the application itself or to preprocessing and preparing the newsletter through our own backend. I couldn’t shake the thought that if there is still a solution through our own backend, why isn’t it implemented through the FCM interface?

And it turns out I was right. Such an option does indeed exist. Deep link processing is already built into the library, but it hasn’t been added to the FCM interface yet.

We dig deeper and find:

All you need to do is redefine the value under the key LINK_ANDROID, and the problem is solved. I’m trying, and…

Do you really have our own backend?

Solution

At some point, I became desperate and wrote a solution with custom processing. However, the idea that there could be an elegant way to send notifications never left me. And such a solution was found. The starting point for any intent processing is fun handleIntent(intent: Intent?). All you need is the ability to override this key. The Firebase frontend doesn't allow this, so there's only one way - the client. We override it through a custom value on the client and use the Firebase SDK to the fullest extent.

Conclusion

And in conclusion, I would like to ask the creators of such an API:

  • Why isn’t there the possibility to embed a deep link directly through the notification composer?
  • Why isn’t there the option to override pending intents and other functions of the notification manager?
  • If everything is done for encapsulation, I apologize — on top of that, where is the evidence that this hasn’t been done?

I’ll skip the full SDK review and touch on just one small point and a simple question — why hasn’t the option to handle PendingIntent for Android been made available? That’s all from me. Use the solution.

--

--