Firebase Dynamic links setup and using guide + Firebase dynamic links generator based on Google Sheets

Andrey Osypov
Beards Analytics 🇺🇦
7 min readSep 7, 2020

--

There are currently two approaches to attributing mobile app installs:

  • Getting a device identifier from an advertising network (for example, idfa for IOS) on which the user clicks on the ad.
  • Fingerprinting, i.e. linking a click on an advertisement and the fact of installation based on device parameters.

Current mobile attribution systems use either both of these approaches or only link by identifier. With the advent of IOS 14, for Apple devices, the ability to attribute by idfa will disappear and the task of attributing installs somehow or another will be solved through fingerprint.

This article is considered the possibility building of attribution and a referral program based on dynamic links from Firebase. Since Firebase or App + Web allows you to solve any problems in mobile / web analytics and marketing automation, dynamic links make it possible to build a complete analytics system without using other services.

How dynamic links work

It is important to understand a dynamic link is not just a link that leads the user to a specific application. It is a constructor into which we can set our own logic of work. Below is a diagram of a possible work for the IOS link.

That is, we can use one link for both IOS and Android. If necessary, you can set the conditions for opening for different versions of operating systems.

Installation in the application

This part is pretty simple, Google prepares the excellent documentation. On my own, I want to add that there are implementations for Cordova, on which there are more and more applications lately.

Basically, dynamic links allow you to open your application from a link while preserving the utm_source, utm_medium, and utm_campaign parameters. Also, it is possible, using Universal links for IOS or App links for Android, to open a specific application screen. This is especially useful for remarketing campaigns, including push notifications.

In Firebase console, add the domain on which our links will be displayed:

Also, it is possible to bind your subdomain or the domain on which these links will be displayed. It does not give anything but beauty, but it looks more serious.

An important point to prevent attackers from using your links is to add your domain (or domains) and links to Google play Store / App Store of your applications to the white list.

Creating dynamic links

There are four ways to create a link:

- from Firebase Console.

This method is suitable for creating test or static links. From the advantages of this method, when you use these links, you have statistics right in the Firebase console.

- collect the link manually.
In real situation, this is the most convenient way that allows you to quickly collect the necessary link from a template and automate their creation:

https://example.page.link/?link=https://www.example.com/someresource&apn=com.example.android&amv=3&ibi=com.example.ios&isi=1234567&ius=exampleapp

- using the rest API.

Using the rest API you can make a long link into a short one.

- create a link in the application.

This method is great for creating a referral program, where in utm_campaign, you can pass the user_pseudo_id or user_id of the user to which this link belongs.

Debugging links

If you add the? D = 1 or & d = 1 parameter to your link, you will see the entire script for its opening, as well as possible errors, if any.

Firebase dynamic links generator

To make it easier to create links through the REST API, I wrote a small extension to Google Sheets scripts that generates them automatically.

To install, create a new Google Sheets, go to Tools -> Script Editor and paste the code from this repository:

https://github.com/snegireff/firebase_dynamic_links_generator

In the code, you need to change it:

sheet.getRange(‘A2’).setValue — just a test url (specify your website domain)

Firebase_url — your domain for short links

Apn — The package name of the Android app

Afl — The link to open when the app isn’t installed (usually url on Android Store)

Ibi — The bundle ID of the iOS app to use to open the link.

Ifl — The link to open when the app isn’t installed (usually url on IOS Store).

Api_key — can be taken in the Firebase console in the settings section.

After that, call the onOpen function:

Which will create a context menu in your document:

Where the first item clears the sheet from the created links, and the second generates them.

Working with dynamic links in Firebase / App + Web

When a user clicks on a dynamic link, the following events happen:

dynamic_link_first_open — the moment, the user opens the application for the first time.

dynamic_link_app_open — the moment, the user opens the application the second and more times.

dynamic_link_app_update — the moment, when the application is updated, after clicking on the link, but only for Android.

Also, in event_params these events save the parameters source, medium, campaign, which can be used, for example, like this:

SELECT

user_pseudo_id,

event_name,

concat((select value.string_value from t0.event_params where key = ‘source’),’ / ‘, (select value.string_value from t0.event_params where key = ‘medium’)) as sourceMedium

FROM

XXX.events_intraday_20200903 t0

where

event_name like ‘%dynamic%’

An important addition. The attribution model is currently first click, i.e. in the traffic_source parameters, there will always be data on the initial traffic source.

In this case, dynamic links can be used as a marker for changing the source and consider any attribution model to your choosing.

If the link was not created manually, but through the console / API / SDK, then the data for click, install, re-open, redirect and first open can be obtained through the corresponding API.

Website Script

An important case is the ability to understand the number of installs through your website. For example, if you have campaigns for both the site and the installation.

In this case, you can save any source, campaign and other parameters when transitioning cookies and dynamically generate a unique link for each client by inserting its parameters into the link.

I give an example based on the Sbjs script. Despite the fact that it is large, it does its job well.

This is how we can realize via GTM:

- Insert all the code or a link to the script into a new GTM tag of the custom html type and activate it with the sbjs.init () command. Trigger is Page Load.

- We create variables of js type, which correspond to source, medium, etc. All possible variables can be found in this document.

- We make another tag, such as custom html, which will contain the substitution algorithm. Trigger is Window load.

<script>

var link = “https://page.page.link/?link=https://play.google.com/store/apps/details?id=ua.page.app&utm_source=web_"+{{current.src}}+"&utm_medium="+{{current.mdm}}+"&utm_campaign="+{{current.cmp}}+"&gclid="+{{gclid}}+"&utm_term="+{{current.trm}}

$(‘[href=”https://play.google.com/store/apps/details?id=ua.page.app"]').attr('href', link)

var link2 = “https://page.page.link/?link=https://itunes.apple.com/us/app/id111111&utm_source=web_"+{{current.src}}+"&utm_medium="+{{current.mdm}}+"&utm_campaign="+{{current.cmp}}+"&gclid="+{{gclid}}+"&utm_term="+{{current.trm}}

$(‘[href=”https://itunes.apple.com/us/app/id111111"]').attr('href', link2)

</script>

Now, for the user, the links will be generated dynamically, taking into account their last non direct traffic source. In Firebase analytics, such transitions will contain the web_ prefix.

Features of Facebook ads

Google Ads is natively integrated with Firebase analytics and you just need to link your accounts. On Facebook and other ad systems, you need to insert dynamic links.

There are no problems to insert dynamic links into advertising systems, but Facebook has some peculiarity.

Since when forming dynamic links, our website goes first, then when inserting dynamic links, Facebook validator goes to the site and looks for the presence of meta tags, with a description of the application, and in their absence, does not allow publishing an ad, therefore, it is necessary to publish on the website tags (by inserting the actual values into the content):

<meta property=”al:ios:url” content=”example://applinks” />

<meta property=”al:ios:app_store_id” content=”12345" />

<meta property=”al:ios:app_name” content=”Example App” />

<meta property=”al:android:url” content=”example://applinks” />

<meta property=”al:android:package” content=”com.example” />

<meta property=”al:android:app_name” content=”Example App” />

After that, the ad will be successfully moderated.

Join our channel in telegrams: https://t.me/firebase_app_web_bigquery

--

--