Written by - Yash Nagda

10 Years back when we used to click on the link (given below). What would happen?

https://www.google.com

We simply go to a web page, complete our task and YAY !! But then the mobile phone happened and now when we click on any link we can go to a website or Android app or IOS app. To solve this problem and make our life easier here comes the deep link.

 

What is the deep link?

So, basically a deep link is the link that can redirect the user to an app or to some specific content in the app. For example, when you click on an advertisement of a sneaker on some website and when you click on that link, the product page opens in the Amazon app, it's the magic of deep linking.

 

Problems with the deep link?

So there are number of problems with deep links.

  1. You need different links for IOS and Android app.

  1. No way to track how many people clicked the link and buy the product.

  1. What if user doesn't have the app installed in their mobile phone.

To solve all these problems the Firebase dynamic links come into the play.

 

What is Firebase dynamic link?

To solve all the above problems, we can use firebase dynamic links. By using dynamic links we can specify different behavior for different platforms like IOS, Android or web and we can provide a fallback URL so if the user doesn't have the app, he can install it from the store. The best thing is we can track all the clicks and conversion on the firebase console.

 

Configuring Android Project

So let's get started, first we have to configure our android project and then we will create the dynamic links.

  1. Visit the https://console.firebase.google.com/

  1. Create a new project or click on an existing project

  1. Now we have to configure the project in our android app. There are 2 ways to do this either you can use built-in firebase assistant in android studio or setup manually by following this guide

  1. After this, you have to add firebase dynamic link dependency in app/build.gradle file

implementation 'com.google.firebase:firebase-dynamic-links:19.0.0'

 

5. now we have to add intent filter to the activity which will receive and handle the dynamic link

<intent-filter>
	<action android:name="android.intent.action.VIEW"/>
	<category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data
	  android:host="shinyshoes.page.link"
	  android:scheme="https"/>
</intent-filter>

This intent filter allows our app to handle all the links that are from the domain name shinyshoes.page.link and the scheme is https.

Now our app is ready so it's time to create the dynamic link and the simplest way to create them is by using the firebase console.

 

Creating our first dynamic link

1. Go to your firebase project and click on dynamic link on the right side and click on "New Dynamic Link" button.

 

2. Now choose default sub domain or add your own custom domain.

3. If everything goes right you will see this success dialog.

4. Now we have setup short link. You can enter any name according to your app.

5. You have to give a deep link URL. On desktop user will be redirected to this link. You can provide link to you website here or you can provide any old url.

6. Here define behaviour of the link on android or IOS app. Make sure the app is connected to the firebase project.

7. We will enter our dynamic link title,image, description to finish things off. You can also add UTM parameter if you want to track the campaign. As of now we will skip that.

8. YAY !! Our link is ready. To test it just copy the link and open it in your browser or send it to anyone on mail or WhatsApp.

Passing data with dynamic links

  1. In some cases, you need to pass data through your link as well. For example product id of shoe in our shiny shoe app. For this, you can add parameters directly in your link in the following way.

https://shinyshoes.page.link/?link=https://example.com/?shoeid=123

as you can see here we have added "shoeid" parameter in the link. Make sure that parameter is the deep link(example.com) and not in the dynamic link(shinyshoes.page.link)

2 Now you can retrieve these parameters in the activity which is handling the links. (an activity with intent filter)

FirebaseDynamicLinks.getInstance()
                .getDynamicLink(getIntent())
                .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
                    @Override
                    public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                        // Get deep link from result (may be null if no link is found)
                        Uri deepLink = null;
                        if (pendingDynamicLinkData != null) {
                            deepLink = pendingDynamicLinkData.getLink();
                            String shoeid=deepLink.getQueryParameter("shoeid");
                        }
                    }
                })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.w(TAG, "getDynamicLink:onFailure", e);
                    }
                });

Here we have used getLink() method to get the link and getQueryParameter(your_param_name) to get the parameter from that link.

 

Conclusion

I hope you found this blog useful and learned how to use the firebase dynamic link. For more information, you can contact me on yash@gkmit.co or you can drop your queries in the comment section below. I will be really glad to assist you.