Firebase Dynamic Links: Cross-Platform Deep Links That Survive Install
In this tutorial, you will learn about Firebase Dynamic Links: Cross. We cover key concepts, practical examples, and best practices to help you master this topic.
Firebase Dynamic Links are smart URLs that route users to the most relevant content in your app or website, adapting to platform, install status, and link preferences.
What You'll Learn
How to create Dynamic Links, handle deep linking in web and mobile apps, configure link behavior for different platforms, track link performance, and use analytics attribution.
Why It Matters
Traditional deep links break when the app isn't installed. Dynamic Links survive the install flow — the user installs the app, opens it, and sees the intended content. DodaTech uses Dynamic Links for referral campaigns and threat alert sharing.
Real-World Use
A user receives a threat alert notification with a Dynamic Link. If the app is installed, it opens to the threat details. If not, the link opens the Play Store, and after install, opens the correct screen.
flowchart LR
A["Dynamic Link\nCreated"] --> B{"App Installed?"}
B -->|Yes| C["Open App\nDeep Link"]
B -->|No| D["Play Store /\nApp Store"]
D --> E["Install App"]
E --> F["Open Deep Link\nAfter Install"]
C --> G["Show Content"]
F --> G
style A fill:#dbeafe,stroke:#2563eb
style C fill:#bbf7d0,stroke:#16a34a
style F fill:#fef3c7,stroke:#d97706
Creating Dynamic Links
const admin = require("firebase-admin");
async function createThreatLink(scanId, threatName) {
const link = await admin.dynamicLinks().createLink({
longDynamicLink: "https://dodatech.page.link",
dynamicLinkInfo: {
domainUriPrefix: "https://dodatech.page.link",
link: `https://dodatech.com/threats/${scanId}`,
androidInfo: {
packageName: "com.dodatech.antivirus",
fallbackLink: "https://play.google.com/store/apps/details?id=com.dodatech.antivirus"
},
iosInfo: {
bundleId: "com.dodatech.antivirus",
appStoreId: "123456789",
fallbackLink: "https://apps.apple.com/app/durga-antivirus/id123456789"
},
socialMetaTagInfo: {
socialTitle: `Threat Alert: ${threatName}`,
socialDescription: "A security threat was detected on your device",
socialImageLink: "https://dodatech.com/images/threat-alert.png"
}
}
});
console.log("Dynamic Link created:", link);
return link;
}
createThreatLink("scan_abc123", "Trojan.Generic");
// Expected output: Dynamic Link created: https://dodatech.page.link/abc123
Handling Dynamic Links on Web
import { getDynamicLink } from "firebase/dynamic-links";
// Handle incoming dynamic links
async function handleDynamicLink() {
const dynamicLink = getDynamicLink();
if (dynamicLink) {
const link = dynamicLink.link;
console.log("Dynamic link received:", link);
// Parse link and navigate
const scanId = link.split("/threats/")[1];
if (scanId) {
navigateToScan(scanId);
}
}
}
// On app startup
handleDynamicLink();
Short Links
// Create shorter links for sharing
const { default: fetch } = await import("node-fetch");
async function createShortLink(longLink) {
const response = await fetch(
"https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=YOUR_API_KEY",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
longDynamicLink: longLink,
suffix: { option: "SHORT" }
})
}
);
const data = await response.json();
console.log("Short link:", data.shortLink);
return data.shortLink;
}
// Expected output: Short link: https://dodatech.page.link/xyz
Link Analytics
// Get link stats from Firebase Console
// Analytics tab shows:
// - Total clicks
// - App installs
// - First opens
// - Re-opens
// - Platform breakdown (Android, iOS, Web)
// - Geographic distribution
async function getLinkStats(linkId) {
// Firebase Console > Dynamic Links > Analytics
console.log("View link analytics at:");
console.log(`https://console.firebase.google.com/project/durga-antivirus/dynamiclinks/${linkId}/analytics`);
}
Common Mistakes
1. Not Testing on Fresh Installs
Dynamic Links after install need end-to-end testing. Use a device that doesn't have the app installed to verify the full install-then-open flow.
2. Missing Fallback URLs
Without fallback URLs, users without the app see a blank page. Always provide fallback URLs for both Android and iOS.
3. Incorrect Domain URI Prefix
The domain prefix must match the configured domain in Firebase Console. Mismatched prefixes cause link creation failures.
4. Not Handling Links on Cold Start
Dynamic Links may arrive during cold start (app not running). Handle the link event both in the app initialization and as a separate event listener.
5. Ignoring Social Preview Tags
Links shared on social media without preview tags look generic. Set socialMetaTagInfo to show title, description, and image in shared previews.
Practice Questions
- How do Dynamic Links survive app installation?
- What is the difference between long and short Dynamic Links?
- How do you configure platform-specific behavior for a Dynamic Link?
- How do you track Dynamic Link performance?
Answers:
- The link redirects to the Play/App Store for install. After installation, the Google Play Services or iOS reads the pending link and passes it to the app.
- Long links are full URLs with query parameters. Short links are compressed versions (20-30 chars) for sharing. Both resolve to the same behavior.
- Set
androidInfoandiosInfoin the link payload with package/bundle IDs and fallback URLs for each platform. - Firebase Console > Dynamic Links > Analytics shows clicks, installs, opens, and platform breakdown for each link.
Challenge: Build a Dynamic Links system for threat alert sharing: create a link with threat details as deep link data, configure Android/iOS fallbacks, shorten for SMS sharing, and handle the link on cold start to navigate to the threat report.
FAQ
Mini Project
Build a Dynamic Link system: create links for each threat alert (with social preview), configure Android/iOS/web routing, shorten for SMS sharing, handle deep link navigation on app launch, and track link analytics in Firebase Console.
What's Next
Firebase Remote Config — change app behavior without deploying updates.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro