SUMIT CHANDEL: Hey, Android developers, I'm Sumit Chandel.
Have you heard about the magic of Firebase Dynamic Links
and want to learn how to add them into your app?
Well, look, no further.
We're going to give you the goods
on getting started with Firebase Dynamic Links right here
in this episode of "Firecasts."
[MUSIC PLAYING]
Firebase Dynamic Links.
They're deep links that work the way you want them to.
With a single link, you can take users
directly to your app on Android or iOS,
or to your app's Play Store or App Store
to install the app if it isn't installed already.
And better yet, that link survives the app installation
process.
So your app can still grab the original link context
after your users have finished installing your app,
and you can take them exactly where you
want them to go in your app right
after they finish installing it.
Pretty cool, right?
Yes, it is.
In fact, we should build a Firebase Dynamic Link
right now.
Now, you can actually start using Firebase Dynamic Links
by completing three very simple steps.
Sound too good to be true?
It's not.
Setting up Firebase Dynamic Links is surprisingly easy.
First, we'll need to do some configuration
on both the Firebase console and in our Android project
to start using Firebase Dynamic Links.
Next, we'll actually create a real dynamic link.
And finally, we'll receive a dynamic link in our own app,
and add code to handle taking the user
to the right section of our app when they
click on that dynamic link.
Now, for this video, we're going to focus on steps one and two.
And we'll go over receiving a Firebase Dynamic
Link in the next part of this video series.
So stay tuned for that.
Now, before we go into these steps
to set up our Firebase Dynamic Links,
it might be helpful to understand just
how these links work and how they get passed into your app.
So let's take a moment to talk about that.
So one part of how Firebase Dynamic Links work
is very similar to App Links.
Now, you might already know App Links and you might not.
But if not, don't worry.
Here's all you need to know about them.
App Links provide a mapping between links on your website
to your Android app.
This is great when you have a website
with a whole lot of content that your users might
want to view directly on the web,
but for which you could also provide an even deeper and more
contextualized experience within your installed Android
application.
So if a user clicks on a link pointing
to your website on their Android device
and has your app installed, App Links will say, hm,
do we want to bring this user to an Android app instead?
If the mapping is there, App Links
can bring the user to your app.
And if your app isn't installed, they'll just go to the website
directly.
One of the key things that allows App Links to do this
is by looking up an assetlinks.json file.
This file contains the mapping for all the URL patterns from
your domain that should send the user to your app,
and it lives at your domain name/.well
known/assetlinks.json.
Now, as you might have guessed, Firebase Dynamic Links
work in a very similar way to App Links.
Based on matching your old patterns,
Firebase Dynamic Links will know to take your users who
click on a dynamic link to your Android app
or directly to the web.
Now, you might be thinking, wait a minute,
I don't have App Links configured.
I don't have an assetlinks.json file.
No!
But don't worry about that.
You don't need to have them configured.
One nice thing about the way Firebase Dynamic Links works
is that the links are hosted on a customizable subdomain that
looks a little something like this.
Note the dot page dot link subdomain.
Firebase actually creates something
like a mini website at this subdomain
automatically to host your Firebase Dynamic Links.
And on that mini website, it also includes
an automatically generated assetlinks.json file all ready
to map your Dynamic Links straight to your app.
So you don't need to worry about creating one yourself.
On the other hand, maybe you already
are using App Links in your app.
And you're like, hey, Sumit, I already
have App Links configured.
Can't I reuse them in Firebase Dynamic Links?
The answer is yes.
And it's actually pretty easy to set up.
We'll talk about that in the second video in this series
when we talk about receiving Dynamic Links into your app.
So if you are using App Links, just stay tuned.
We've got you covered.
Now that we know a bit more about how Firebase Dynamic
Links actually work, I think we're
ready to start creating some.
Let's go through those three steps
I mentioned to get our first Firebase Dynamic Links working.
The first step is the configuration steps,
both in your Android project and in the Firebase console.
Now, I've already set up and configured a Firebase product
with my Android app that I'll be working with here to set up
our Firebase Dynamic Links.
The project I've set up is a language learning app
called Learn Miwok, a Native American language
originating in what is now Northern California.
If you've ever taken Android courses on Udacity,
it'll probably be familiar to you.
So I'll go ahead and use this one for this "Firecast."
Haven't created and configured a Firebase project yourself yet?
No problem.
Just check out this video for more details
on configuring a Firebase project on Android
and come right back here when you're done.
One quick note, if you do follow the video up there
to create and configure your Firebase project,
when setting up your SHA certificate fingerprints,
note that Firebase Dynamic Links requires
using a SHA-256 fingerprint instead of a SHA-1 fingerprint,
as shown in that video.
So be sure to add the SHA-256 fingerprint to your project
as well.
OK.
We've got a Firebase project and Android app ready.
So let's now set up our app to enable Firebase Dynamic Links.
We'll start by first configuring our Android project.
So we've got our project open here in Android Studio
and the handy Firebase developer docs available to us.
First, I'll need to add the Firebase Dynamic Links
dependency to my Android project.
And I can do that like so by copying
this here dependency into my app level bill.gradle file.
Once we've done that, we just need
to sync our project with the updated gradle files,
and we should be ready for our next step.
Next, I'll go into the Firebase console
to configure our Firebase project
and provide Firebase with a bit more information
about which domain I would like to use for my Dynamic Links.
I'll start by going to the Firebase console
and selecting my project.
Next, let's select Dynamic Links from the menu just down
below here.
Now, before you hit that big blue Get Started button,
it's important to take note of the consent form there.
We'll want to make sure our app is properly configured
with the package name we intend to use,
as these will publicly be available
once we start creating our first Dynamic Links.
If you've already created a project
or followed the previously mentioned video guiding
you through it, you should already
have a package name set and ready to go.
If it's not one that you want to be made public
after creating your first Dynamic Links,
go ahead and change that first before moving ahead.
Similarly, if you're Firebase project
is also connected to an iOS app, you'll
want to make sure the bundle ID and team
ID are appropriately set.
Otherwise, let's do as the big blue box says
and click Get Started.
The first thing Firebase will ask
us is what subdomain you'd like to use for your Firebase
project.
One really cool thing to mention here
is what happens if you don't want
to use a dot page dot link subdomain,
but instead want to use your own domain
name, like MyAwesomeCompany.com.
Well, here's some exciting news.
Firebase Dynamic Links actually supports
using your own custom domains.
Setting up a custom domain requires
a few additional configuration steps
that might be too much to get into for this first Getting
Started video.
So we'll use the dot page dot link subdomain instead.
Don't worry, though.
We will be covering how to set up Firebase Dynamic Links using
custom domains in an upcoming video in this series.
So stay tuned for that.
And if you really, really want to use custom domains
for your Dynamic Links now, just check out
the blog post and documentation links in the description,
and you'll be on your way.
For now, we'll use a dot page dot link subdomain.
Now, there are a couple of things
to note when you go about choosing the subdomain you want
to use for your Dynamic Links.
First, remember that there should be a subdomain specific
to this Firebase project.
So rather than using something like your company name,
I'd recommend using something like your app name.
Also note that depending on which domain name you choose,
there may be additional verification
steps needed to make sure that you are indeed
the owner of the name in the subdomain name.
So you can't register something like YouTube.page.link.
Good try, though.
In my case, I've chosen learnmiwok.page.link.
And you'll want to choose something that
works for your project, too.
Once you've selected a suitable name, hit Continue, and bam,
you're Firebase Dynamic Links subdomain and mini web page
should be set and ready to go.
In fact, you can even check to see that the correct
assetlinks.json file was generated by visiting this
newly created web page at the name you chose.page.link/.well
known/assetlinks.json.
So go ahead and do that now.
For our Learn Miwok project, we can see the assetlinks.json
file right here at learnmiwok.page.link/.well
known/assetlinks.json.
The assetlinks.json file provides a configuration
for handling all URLs that are sent to this domain
and redirecting to my Android app designated by the Android
package name com.sumitchandel.miwok.
If you followed up until this point in the video,
you should see the same thing here
in the assetlinks.json file living at your Firebase Dynamic
Links subdomain with your Android package name.
OK.
Now that we've created the subdomain we're going to use,
tested that the assetlinks.json file was correctly created,
completed our configuration steps,
we're now ready to move to step two,
creating our very first Dynamic Link.
Note, there are many ways to create Firebase Dynamic
Links, including creating them programmatically.
This can be done using our client libraries or REST APIs,
and most likely will be the way you'll create
most of your own Dynamic Links.
We'll be covering that in more detail in another video.
For now, we'll go for the easiest
and most straightforward method for creating a Dynamic Link,
creating them straight from the Firebase console.
Creating Dynamic Links via the console
is great for when you want to create a link that you
can easily promote in a social media campaign,
to bring your users to a warm user experience,
or take them through some kind of promotion flow
within your app.
So let's do that.
So now that we've got a subdomain, all we need to do
is click this nifty New Dynamic Link button,
and we're off to the races.
Here you can see that the subdomain we've created
is already filled in with the domain field.
And we also have a prepopulated short link
that we can go ahead and use.
If you are going to use this Dynamic
Link for promotional purposes, you
could change that to something more meaningful,
like promo or summersale.
For my example, I'll use the word learn,
for a learning campaign, and put that here, and then click Next.
Now we're presented with the section
to name our Dynamic Link for tracking purposes.
I'll use Learn Miwok, since that's
what I'll be using this Dynamic Link to help users do.
And then just above that, we have the deep link URL box.
Hm.
What does this mean?
So the deep link URL is the data that
actually gets passed to your Android or iOS app when
your Dynamic Link is clicked.
You might think this would be a JSON blob or something,
but it isn't, and that's because Firebase Dynamic Links require
that your deep link is a well-formatted URL that
leads to an actual website, so that if a user who
isn't on Android or iOS clicks on your Dynamic Link,
they'll be taken to a real website on their browser
and still have a good experience.
If your company has a website with content
that very closely mirrors what's in your app,
here would be an ideal place to use those web page
URLs as your deep link URL parameter.
In fact, this situation is exactly when you
might want to use App Links.
So if you already have them set up,
you could reuse those deep link URLs here.
The deep link parameter you set here
will allow your Android or iOS app
to get that deep link URL when a user clicks on your Dynamic
Link from Android or iOS, or go straight
to your web page in a browser experience
if they're on some other platform.
If you don't have real web pages that you can map to,
you can just use any old URL here for your domain,
and redirect those back to something like your home page.
To make this easier, you can use the same root directory
for any incoming Dynamic Links, and set up your redirect rule
to redirect any URLs to that root directory back
to your home page.
So for my deep link URL, I'll just use any old URL,
like https://www.example.com/, and then pass in a URL
parameter curPage=1, and hit Next,
which takes me to the section for how we want the link
to behave for iOS.
Since I don't have an iOS app attached to this project,
I'll leave this on open the deep link
URL in a browser, which will open the deep link
URL that I specified earlier.
But if you did have an iOS app, you
can select that here after configuring your iOS project
for Firebase Dynamic Links.
Oh, and if you're wondering how to do that,
check out this video here when you're
ready to set up your project for iOS.
Now, I'll hit Next to get into the section
for defining the link behavior for Android.
Now, there are a few options here.
The first option is the primary behavior
I'd like this Dynamic Link to have for Android, which would
be to open my Android app.
So I'll select that option, and then select my Android app
from the dropdown, like so.
Next, I can choose what I would like
to have happen if the app is not installed.
Normally, this would be to take them to the Play Store
to download the app.
But if the user who clicked the link isn't running
the minimum required version of Android to run my app
or if I have a Google Play Instant
experience available for my app, I
might want to send the user there instead.
The Google Play Instant experience
allows my user to get even faster access
to the contextual call to action that we'd
like them to experience.
But I digress.
So let's just leave it to sending users to my Android app
and move on to the last section to create our Dynamic Link.
Here we have some advanced options we can set.
The first part here is for adding social meta tags that
can help improve the sharing experience for users
who receive this Dynamic Link.
We can provide a title, image, and description
for our social meta tag parameters.
Now, these tags are used in two places.
First, they are used in many popular social networks
to populate the ImageView and text that
will be shown in any social network
posts along with this link.
And second, they'll be shown in the preview interstitial on iOS
devices that tell the user, hey, we're
about to go to the App Store, are you cool with that,
when they click on that link.
To provide the best experience in both cases,
we'll definitely want to have these values filled in.
So let me just get these filled in.
Ah, all done.
And now let's jump to the final section
below on tracking a campaign for UTM parameters.
These will let you specify the source, medium,
and name of the campaign associated with this deep link.
And this is used both in Play Store campaign tracking
and in Google Analytics for Firebase.
Finally, the skip the app preview page is an option
to skip that, hey, we're going to the App Store preview
interstitial I mentioned earlier on iOS.
But also, as I mentioned earlier,
that page can be really useful to provide a better user
experience.
So let's take their recommendation,
and not skip this preview page, and leave this unchecked.
And we are cleared for takeoff.
I'll click on the Create button, and bam, we
have our first Dynamic Link ready to go.
All right.
Now, there are some neat info and tools
we can use to check out the details of the link we've just
created and to see what flows a user who clicks on the link
might see after they click on it.
First, by clicking on the Link details section,
I can see the expanded Dynamic Link, including
all the URL parameters that are added
on that enable the magic of Firebase Dynamic Links.
Whenever I create Firebase Dynamic Links by hand,
this is a helpful reference guide
that I'll often refer to to see what
parameters I can use that I might want to add onto my link.
Next, there's also this handy Link preview.
We can click on this to help debug our Dynamic Link.
And that will show you how the Dynamic Link will behave
when a user clicks on it.
For example, in this case, we can
see that when an Android user clicks on the link,
they'll be taken to the app itself
if it's already installed or to the Play Store if it's not
installed already.
For iOS or desktop users, they'll
just go straight to the web link provided in the link
parameter I specified earlier.
OK.
We've configured our project and created our first Dynamic Link.
Now we just need to test it out.
The easiest way to test a Dynamic Link
is literally to click on it from an app
like Gmail, Twitter, an SMS messaging app, or so forth.
In this case, I've prepared a super handy app that basically
just displays the Firebase Dynamic Link I just
created on a clickable page.
So I'll just load that up.
Voila.
The app is loaded with my clickable Dynamic Link.
And I'll just click it, and bam, we've
now jumped into our Learn Miwok language learning app,
and it loaded to the current page.
Now, you might have guessed that the fact that the Learn Miwok
app is not just loading up for my dynamic link
but to the correct page means that it actually received
and unpacked a Dynamic Link.
And you would be correct.
Good catch.
We haven't talked about doing that part yet.
But as I mentioned, this will be in a following video.
In fact, it'll be in the very next video of this series.
So stay tuned for that.
So to recap, here's what we've checked out so far.
We've learned a little bit more about how Firebase Dynamic
Links work and then performed the needed configuration steps
to enable Dynamic Links in our project
by adding the Firebase Dynamic Link dependency to our Android
project and selecting the subdomain we want to use
for our Firebase Dynamic Links.
Then we created our very first Dynamic Link
in the Firebase console and then tested out
that it actually opens up our app.
Next up, let's look at how we can actually
receive and interpret a Dynamic Link in our app.
The critics' reviews are in.
And it's rated four stars.
Best video about links on the internet.
So stick around and check it out.
[MUSIC PLAYING]