How to Create Firebase Dynamic Links using Google Sheets
Create and manage hundreds of Firebase dynamic links using Google Sheets.
Firebase dynamic links are great. It allows controlling the link redirection depending upon the app installation status. If the app is installed open the app if not, open the app store or the website, whatever is the campaign objective.
The process of creating the dynamic link is also pretty straightforward.
1- Provide the link
2- Decide link behavior based on app install status
3- Set UTMs
And done.
Even though it is simple, doing the same process for many links is quite a cumbersome task. Imagine dynamic links for thousands of products on an e-commerce website. No way!
In this article, I will explain how we can utilize Google Sheets, app scripts, and Firebase dynamic link API to mass create and manage Firebase dynamic links with ease.
Use Google Appscript to Generate Firebase Dynamic Links
We will employ App Script to read values from Google Sheets and send them to Firebase Dynamic API to get us the links generated automatically.
In Google Sheets go to Tools then App Script to allow us to add our code to interact with Firebase APIs.
Paste the below code as it is in the Code. Update the API key in the code from your Firebase console.
function createFirebaseDynamicLink(base_url,utm_source,utm_medium,utm_campaign,iosBundleId,androidPackageName,domainUriPrefix) {
var api_key= "<your api key here>"
var post_url = 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key='+api_key
var data = {
"dynamicLinkInfo": {
"domainUriPrefix": domainUriPrefix,
"link": base_url,
"androidInfo": {
"androidPackageName": androidPackageName,
"androidFallbackLink": base_url,
},
"iosInfo": {
"iosBundleId": iosBundleId,
"iosFallbackLink":base_url
},
"analyticsInfo": {
"googlePlayAnalytics": {
"utmSource": utm_source || "",
"utmMedium": utm_medium || "",
"utmCampaign": utm_campaign || "",
}
}
},
"suffix": {
"option": "SHORT"
}
};
var options = {
'method' : 'post',
'contentType': 'application/json',
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(post_url, options);
var object = JSON.parse(response.getContentText());
return object['shortLink'];
}
Our custom function createFirebaseDynamicLink
expects 7 values that we need to pass from the Google sheet. These are
- Url: The URL that we need to convert to Firebase Dynamic Link.
- utm_source: UTM source for the link.
- utm_medium: UTM medium for the link.
- utm_campaign: UTM campaign for the link.
- iOS Bundle Id: Bundle of the iOS app for which to generate Firebase dynamic links.
- Android Package Name: Bundle of the Android app for which to generate Firebase dynamic link.
- Domain Uri Prefix: Your Firebase dynamic link prefix URL.
We will now call a function, as any other function of Google Sheets, and pass the above values to get us the Dynamic link. Here is how the function call will look based on the sheet here
=createFirebaseDynamicLink(C2,D2,E2,F2,G2,H2,I2)
And DONE!
Have as many URLs as you required in the Google sheet and generate Firebase dynamic links in seconds.
Final Thoughts
In this article, I present an innovative solution that allows you to effortlessly generate and manage hundreds of Firebase dynamic links using the familiar interface of Google Sheets. By adopting this approach, you can save valuable time and effort while reaping the numerous benefits of dynamic linking.