You are on page 1of 10

Firebase Dynamic Links

!" # $% !
Firebase Dynamic Links are links that work the way you want, on multiple platforms,
and whether or not your app is already installed.

With Dynamic Links, your users get the best available experience for the platform
they open your link on. If a user opens a Dynamic Link on iOS or Android, they can
be taken directly to the linked content in your native app. If a user opens the same
Dynamic Link in a desktop browser, they can be taken to the equivalent content on
your website.

In addition, Dynamic Links work across app installs: if a user opens a Dynamic Link
on iOS or Android and doesn't have your app installed, the user can be prompted to
install it; then, after installation, your app starts and can access the link.

How does it work?

You create a Dynamic Link either by using the Firebase console, using a REST API,
iOS or Android Builder API, or by forming a URL by adding Dynamic Link parameters
to a domain speciNc to your app. These parameters specify the links you want to
open, depending on the user's platform and whether your app is installed.

When a user opens one of your Dynamic Links, if your app isn't yet installed, the
user is sent to the Play Store or App Store to install your app (unless you specify
otherwise), and your app opens. You can then retrieve the link that was passed to
your app and handle the deep link as appropriate for your app.

Custom link domains

You can create Dynamic Links using your own domain name
(/docs/dynamic-links/custom-domains):

https://example.com/summer-sale
https://example.com/links/promos/summer-sale
https://links.example.com/summer-sale
https://ex.amp.le/summer-sale

Or, if you don't have a domain for your app, you can use a free custom page.link
subdomain:

https://example.page.link/summer-sale

Create your free subdomain in the Firebase console.

All Dynamic Links features, including analytics, post-install attributions, and SDK
integrations, work with both custom page.link domains and your own domain.

Implementation path

Set up Firebase and Enable Firebase Dynamic


the Dynamic Links Links for your Firebase project
1 SDK in the Firebase console. Then,
include the Dynamic Links
SDK in your app.

Create Dynamic You can create Dynamic Links


2 Links programmatically or by using
the Firebase console.

Handle Dynamic When your app opens, use the


Links in your app Dynamic Links SDK to check if
a Dynamic Link was passed to
3 it. If so, get the deep link from
the Dynamic Link data and
handle the deep link as
necessary.

View analytics data Track the performance of your


4 Dynamic Links in the Firebase
console.
Next steps

Learn about some of Firebase Dynamic Links' most common use cases
(/docs/dynamic-links/use-cases) and how to implement them.

Learn how to create Dynamic Links (/docs/dynamic-links/create-links) and


then receive them in your iOS (/docs/dynamic-links/ios/receive), Android
(/docs/dynamic-links/android/receive), Unity
(/docs/dynamic-links/unity/receive), and C++
(/docs/dynamic-links/cpp/receive) apps.

Use your own custom domain (/docs/dynamic-links/custom-domains) for


Dynamic Links.

Understand your Dynamic Links's performance with two analytics


(/docs/dynamic-links/analytics) tools.

Except as otherwise noted, the content of this page is licensed under the Creative
Commons Attribution 4.0 License (https://creativecommons.org/licenses/by/4.0/),
and code samples are licensed under the Apache 2.0 License
(https://www.apache.org/licenses/LICENSE-2.0). For details, see the Google
Developers Site Policies (https://developers.google.com/site-policies). Java is a
registered trademark of Oracle and/or its a\liates.

Last updated 2021-09-08 UTC.


Create Dynamic Links
There are four ways you can create a Dynamic Link:

Using the Firebase console. This is useful if you're creating promo links to
share on social media. This way you can select a custom su?x and a name
for the link in the Firebase console. You can track the performance of these
Dynamic Links in the Firebase console or via the Analytics REST API.

Using the Dynamic Link Builder API on iOS and Android. This is the preferred
way to dynamically create links in your app for user-to-user sharing or in any
situation that requires many links. You can track the performance of Dynamic
Links created with the Builder API using the Dynamic Links Analytics API.

Using the REST API. This is the preferred way to dynamically create links on
platforms that don't have a Builder API. The Analytics REST API can be used
to track the performance of promo campaigns created in the console.

Manually. If you don't need to track click data and you don't care if the links
are long, you can manually construct Dynamic Links using URL parameters,
and by doing so, avoid an extra network round trip.

Next steps

After you create Dynamic Links, you need to set up your app to receive Dynamic
Links and send users to the right place in your app after a user opens them.

To receive Dynamic Links in your app, see the documentation for iOS, Android, C++,
and Unity.

Except as otherwise noted, the content of this page is licensed under the Creative
Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0
License. For details, see the Google Developers Site Policies. Java is a registered
trademark of Oracle and/or its a?liates.

Last updated 2021-09-22 UTC.


Set up a custom domain for
Dynamic Links
You can have greater control over your Dynamic Links' branding by using your own
domain instead of a page.link subdomain. With custom domains, you can create
Dynamic Links like the following examples:

https://example.com/link-suffix
https://example.com/links/promos/link-suffix
https://links.example.com/link-suffix
https://ex.amp.le/link-suffix

The part of the URL before link-su(x is called the URL pre(x, and contains both
your custom Dynamic Link domain and a path preDx. You will need to provide a URL
preDx when you create Dynamic Links.

Setting up a custom domain requires Editor or Owner permission on your Firebase


project.

! Note: To use a custom domain for Dynamic Links, the domain must point
to Firebase Hosting. If you have a domain you want to use with Dynamic
Links and the domain points to a different host, you can either move to
Firebase Hosting or create a subdomain hosted by Firebase, which you
can use for Dynamic Links.

Using your web domain for Dynamic Links

You can use the same domain for your Dynamic Links and your web pages,
Universal Links, and App Links, but if you do, you must take care that your Dynamic
Link URLs don't conNict with your web URLs. When you conDgure Dynamic Links to
use a particular URL preDx, all URLs that begin with that preDx are treated as
Dynamic Links, so you can't use URLs with that preDx to point to ordinary hosted
content.

For example, if you want to create a Dynamic Link to the resource


https://example.com/my-resource (a web page, Universal Link, or App Link),
you can't use https://example.com/ as the Dynamic Links URL preDx, because
doing so would cause https://example.com/my-resource to be treated as a
Dynamic Link. Instead, you must use a URL preDx with either a different domain or a
different path preDx.

So, the following long-form Dynamic Links (and equivalent short links) won't work
as intended because the URLs speciDed by the link parameter start with the
Dynamic Link URL preDx, https://example.com/ :

" https://example.com/?link=https://example.com/my-resource

" https://example.com/?
link=https://example.com/resources/my-resource

But the following long-form Dynamic Links (and equivalent short links) can work,
because the URL preDxes don't conNict with the link URLs:

# https://link.example.com/?link=https://example.com/my-
resource

# https://example.com/links/?link=https://example.com/my-
resource

# https://ex.amp.le/?link=https://example.com/my-resource

Set up a custom domain in the Firebase console

You can usually set up a custom domain completely in the Firebase console. To do
so:

1. If you haven't set up Firebase Hosting for your project, open the Hosting page
of the Firebase console, click Get Started, and click through the setup
instructions. You don't have to complete the indicated steps at this time.

2. Open the Dynamic Links page of the Firebase console.

3. If you haven't used Dynamic Links before, click Get Started. Otherwise, click
Add URL pre1x from the drop-down menu.

Then, complete the setup wizard, specifying the domain and path preDx you
want to use when prompted.

! Note: You can't use the same URL preDx for both Dynamic Links
and regular hosting. If you want to use the same branding for
both, consider using a path preDx (for example,
example.com/links) or subdomain (links.example.com/) in your
Dynamic Links URL preDx.

4. iOS only: In your Xcode project's Info.plist Dle, create a key called
FirebaseDynamicLinksCustomDomains and set it to your app's Dynamic
Links URL preDxes. For example:

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://example.com/link</string>
<string>https://example.com/promos</string>
</array>

Set up a custom domain manually

In some situations, such as when you already have a custom domain set up for
Dynamic Links and want to add another domain, or when you are adding a domain
already connected to a Hosting site, you have to set up your custom domain
manually.

To do so:

1. Connect your domain to Firebase Hosting if you haven't already done so.

Setting up your domain with Firebase Hosting includes creating the


conDguration Dle firebase.json in your local project directory.

2. Update to the latest version of the Firebase CLI (v6.5.0 or later).

3. ConDgure your Hosting site for Dynamic Links in your project's


firebase.json Dle. If your project has multiple sites, be sure to conDgure
the site connected to the domain you want to use.

Set appAssociation to AUTO . With this setting, Hosting


dynamically generates assetlinks.json and apple-app-site-
association Dles when they are requested.

Specify the path preDxes you want to use for Dynamic Links by setting
rewrite rules with dynamicLinks set to true . Requests to these
paths get proxied to Dynamic Links.

Unlike rules that rewrite paths to URLs, Dynamic Link rewrite rules can't
contain regular expressions.

If you have multiple rewrite rules for your site, be aware that Hosting
executes the Drst rewrite rule that matches the request.

For example:

"hosting": {
// ...
"appAssociation": "AUTO",
"rewrites": [
{
"source": "/promos/**",
"dynamicLinks": true
},
{
"source": "/links/share/**",
"dynamicLinks": true
}
]
}

With the above conDguration, you can create Dynamic Links with URL
preDxes like the following examples:

https://your-domain/promos/link-suffix
https://your-domain/links/share/link-suffix

! Note: You can't use the same URL preDx for both Dynamic Links
and regular hosting. If you want to use the same branding for
both, consider using a path preDx (for example,
example.com/links) or subdomain (links.example.com/) in your
Dynamic Links URL preDx.

If you use this domain only for Dynamic Links, you can use a source path of
/** to create Dynamic Links with no path preDx:

{
"source": "/**",
"dynamicLinks": true
}

With the above rule, you can create Dynamic Links like the following example:

https://your-domain/link-suffix

4. Deploy your Hosting conDguration changes:

$ firebase deploy --only hosting

(optional) You can check the deployed firebase.json content using the
Hosting REST API.

5. iOS only: In your Xcode project's Info.plist Dle, create a key called
FirebaseDynamicLinksCustomDomains and set it to your app's Dynamic
Links URL preDxes. For example:

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://example.com/promos</string>
<string>https://example.com/links/share</string>
</array>

Priority order for Dynamic Links and Hosting

For Dynamic Links, be particularly aware of hosting priority order.

Ensure that your Dynamic Links URL preDx doesn't conNict with higher priority
hosting conDgurations (for example, hosted static content always has priority
over rewrites).

Within the rewrites attribute, the Hosting response will obey the rule
speciDed by the (rst source glob that captures the requested path.

For example, if you set up a Dynamic Link for your-domain/source-path/link-


suffix but you also have static content at your-domain/source-
path/index.html , the static content takes precedence. An end-user will see
index.html rather than the Dynamic Link. Similarly, if you have static content at
your-domain/source-path/link-suffix , the end-user will see the static
content rather than the Dynamic Link.

If you want to use the same branding for both Dynamic Links and Hosting, consider
one of the following options for your Dynamic Links URL preDx:

Set your source attribute to match a path preDx. For example, if you have a
custom domain of example.com , your rewrite rule could be:

// Domain is example.com
"rewrites": [ {
"source": "/links/**", // Dynamic Links start with
"https://example.com/links/"
"dynamicLinks": true
} ]

Set up a subdomain to use for Dynamic Links, then set your source
attribute to match that subdomain. For example, if you have a subdomain of
links.example.com , your rewrite rule could be:

// Domain is links.example.com
"rewrites": [ {
"source": "/**", // Dynamic Links start with
"https://links.example.com/"
"dynamicLinks": true
} ]

! Note: You can check the deployed firebase.json content using the
Hosting REST API.

Except as otherwise noted, the content of this page is licensed under the Creative
Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0
License. For details, see the Google Developers Site Policies. Java is a registered
trademark of Oracle and/or its aaliates.

Last updated 2021-09-08 UTC.

You might also like