Get Started with Firebase Dynamic Links for C++

Firebase Dynamic Links are deep links into an app that work whether or not users have installed the app yet. When users open a Dynamic Link into an app that is not installed, the app's store page opens, where users can install the app. After users install and open the app, the app displays the deep-linked content.

To write your cross-platform Firebase Dynamic Links client app with C++, use the Firebase Invites C++ API.

The C++ SDK works for both Android and iOS, with some additional setup required for each platform.

Before you begin

Android

  1. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
  2. Add Firebase to your Android project.
  3. Add the dependency for Firebase Invites to your app-level build.gradle file:
    dependencies {
         compile 'com.google.firebase:firebase-invites:9.6.1'
    }
  4. Link the libapp.a and libinvites.a static library, from the C++ SDK.

iOS

  1. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
  2. Add Firebase to your iOS project.
  3. The Firebase Invites C++ client library uses custom URL schemes on iOS to process links. You must add custom URL schemes to your app to support receiving Dynamic Links:
    1. To open your project configuration, double-click the project name in the left tree view. Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section.
    2. Click the + button, and add a URL scheme for your reversed client ID. To find this value, open the GoogleService-Info.plist configuration file, and look for the REVERSED_CLIENT_ID key. Copy the value of that key, and paste it into the URL Schemes box on the configuration page. Leave the other fields blank.
    3. Click the + button, and add a second URL scheme. This one is the same as your app's bundle ID. For example, if your bundle ID is com.example.app, type that value into the URL Schemes box. You can find your app's bundle ID in the General tab of the project configuration (Identity > Bundle Identifier).
  4. Include the following Pod in your Podfile:
    pod 'Firebase/Invites'
  5. Run pod install
  6. Add firebase.framework and firebase_invites.framework, from the C++ SDK, to your Xcode project.

Receiving a Dynamic Link

Create and initialize App

Before you can check for received Dynamic Links, you'll need to create and initialize a firebase::App object.

Include the header file for firebase::App:

#include "firebase/app.h"

The next part varies depending on your platform:

Android

Create the firebase::App, passing the JNI environment and a jobject reference to the Java Activity as arguments:

app = ::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"), jni_env, activity);

iOS

Create the firebase::App:

app = ::firebase::App::Create(::firebase::AppOptions("APPLICATION NAME"));

Use InvitesReceiver to check for Dynamic Links

The Firebase Invites C++ library is also used for receiving Dynamic Links. To check for a received Dynamic Link, use the firebase::invites::InvitesReceiver class.

Include the header file for receiving Invites:

#include "firebase/invites/receiver.h"

Create an new instance of firebase::invites::InvitesReceiver, and fetch incoming invitations.

receiver = new firebase::invites::InvitesReceiver(*app);
receiver->Fetch();

Fetch() returns immediately and checks for the invitation asynchronously. It returns its results via firebase::Future, which you can query to find out whether an invitation (or Dynamic Link) was received.

You can also obtain the most recent firebase::Future by calling FetchLastResult(). This returns the same result as the most recent call to Fetch().

auto future_result = receiver->FetchLastResult();
if (future_result.Status() == firebase::kFutureStatusComplete) {
    if (future_result.Error() == 0) {
        // Fetch succeeded, let's find out what we received.
        auto result = *future_result.Result();
        if (result.deep_link != "") {
            // We received a Dynamic Link. This may have come from an invitation (if
            // result.invitation_id is set), or it might have been sent using
            // Firebase Dynamic Links.
            // In any event, you can now act on this link as your app sees fit.
        }
        if (result.invitation_id != "") {
            // We received an invitation ID. See the Firebase Invites documentation
            // for more information.
        }
        if (result.invitation_id == "" && result.deep_link == "") {
            // We did not receive any invitation or Dynamic Link, so carry on as normal.
        }
    } else {
        // Error() is nonzero, which means an error occurred. You can check
        // future_result.ErrorMessage() for more information.
    }
} else {
    // The Fetch() operation has not completed yet, so the Invites library is
    // still checking for an incoming invitation. Check FetchLastResult()'s Status()
    // again soon.
}

You can also use an OnCompletion callback to determine when the Fetch() is completed, instead of polling FetchLastResult()'s Status(). See the firebase::Future documentation for more details.

Creating a Dynamic Link

The easiest way to create a Dynamic Link is by using the Firebase console. You can also create a Dynamic Link programmatically by constructing a URL that includes the Dynamic Link parameters.

Create a Dynamic Link in the Firebase console

  1. Open the Firebase console.
  2. Open the Dynamic Links page by clicking Dynamic Links on the sidebar menu. On this page, you can see a list of your Dynamic Links and their click rates.
  3. Click New Dynamic Link and ensure that Generate Dynamic Link is selected.
  4. Provide basic information for the Dynamic Link:
    Basic Dynamic Link parameters
    Link Name A name for the Dynamic Link
    Link URL

    The link your app will open. You can specify any URL your app can handle, such as a link to your app's content, or a URL that initiates some app-specific logic such as crediting the user with a coupon, or displaying a specific welcome screen. This link must be a well-formatted URL, be properly URL-encoded, and use the HTTP or HTTPS scheme.

    Android App The package name of the Android app to use to open the link. The app must be connected to your project from the Overview page of the Firebase console. Required for the Dynamic Link to open an Android app.
    iOS App The bundle ID of the iOS app to use to open the link. The app must be connected to your project from the Overview page of the Firebase console. Required for the Dynamic Link to open an iOS app.
    Specifying these parameters creates a Dynamic Link with basic functionality: the link will be opened with the specified app, possibly after prompting the user to install the app first.
  5. Optional: you can also fine-tune the behavior of the Dynamic Link by specifying advanced options:
    Advanced Android parameters
    Fallback link The link to open when the app isn't installed. Specify this to do something other than install your app from the Play Store when the app isn't installed, such as open the mobile web version of the content, or display a promotional page for your app.
    Minimum version code The versionCode of the minimum version of your app that can open the link. If the installed app is an older version, the user is taken to the Play Store to upgrade the app.
    Custom app location The link to open on Android. This link can use any scheme, and, if specified, takes priority over the link parameter on Android.
    Advanced iOS parameters
    Fallback Link The link to open when the app isn't installed. Specify this to do something other than install your app from the App Store when the app isn't installed, such as open the mobile web version of the content, or display a promotional page for your app.
    iOS Custom Scheme Your app's custom URL scheme, if defined to be something other than your app's bundle ID
    iPad App The bundle ID of the iOS app to use on iPads to open the link. The app must be connected to your project from the Overview page of the Firebase console.
    iPad Fallback Link The link to open on iPads when the app isn't installed. Specify this to do something other than install your app from the App Store when the app isn't installed, such as open the web version of the content, or display a promotional page for your app.

Create a Dynamic Link programmatically

You can also create a Dynamic Link programmatically by constructing a URL with the following form:

https://app_code.app.goo.gl/?link=your_deep_link&apn=package_name[&amv=minimum_version][&ad=1][&al=android_link][&afl=fallback_link]
Android Parameters
link

The link your app will open. You can specify any URL your app can handle, such as a link to your app's content, or a URL that initiates some app-specific logic such as crediting the user with a coupon, or displaying a specific welcome screen. This link must be a well-formatted URL, be properly URL-encoded, and use the HTTP or HTTPS scheme.

apn The package name of the Android app to use to open the link. The app must be connected to your project from the Overview page of the Firebase console. Required for the Dynamic Link to open an Android app.
ad Declares that the Dynamic Link is used in an advertisement. If you use a Dynamic Link in an advertisement, you must set this parameter to 1. This disables the functionality that allows you to get the link parameter when a user must first install the app on iOS.
al Optional: The link to open on Android. This link can use any scheme, and, if specified, takes priority over the link parameter on Android.
afl Optional: The link to open when the app isn't installed. Specify this to do something other than install your app from the Play Store when the app isn't installed, such as open the mobile web version of the content, or display a promotional page for your app.
amv Optional: The versionCode of the minimum version of your app that can open the link. If the installed app is an older version, the user is taken to the Play Store to upgrade the app.
  • utm_source
  • utm_medium
  • utm_campaign
  • utm_term
  • utm_content
  • gclid
Optional: Custom campaign parameters. These parameters are passed through to deep links and to the referrer parameter of Play Store links.
iOS Parameters
link

The link your app will open. You can specify any URL your app can handle, such as a link to your app's content, or a URL that initiates some app-specific logic such as crediting the user with a coupon, or displaying a specific welcome screen. This link must be a well-formatted URL, be properly URL-encoded, and use the HTTP or HTTPS scheme.

ibi The bundle ID of the iOS app to use to open the link. The app must be connected to your project from the Overview page of the Firebase console. Required for the Dynamic Link to open an iOS app.
ius Optional: Your app's custom URL scheme, if defined to be something other than your app's bundle ID
ad Declares that the Dynamic Link is used in an advertisement. If you use a Dynamic Link in an advertisement, you must set this parameter to 1. This disables the functionality that allows you to get the link parameter when a user must first install the app on iOS.
ifl Optional: The link to open when the app isn't installed. Specify this to do something other than install your app from the App Store when the app isn't installed, such as open the mobile web version of the content, or display a promotional page for your app.
ipbi Optional: The bundle ID of the iOS app to use on iPads to open the link. The app must be connected to your project from the Overview page of the Firebase console.
ipfl Optional: The link to open on iPads when the app isn't installed. Specify this to do something other than install your app from the App Store when the app isn't installed, such as open the web version of the content, or display a promotional page for your app.
  • utm_source
  • utm_medium
  • utm_campaign
  • utm_term
  • utm_content
  • gclid
Optional: Custom campaign parameters. These parameters are passed through to the App Store.
  • at
  • ct
  • mt
  • pt
Optional: App Store affiliate link parameters. These parameters are passed to the App Store.
d Optional: Instead of loading the Dynamic Link, generate a flowchart you can use to preview your Dynamic Links' behavior on different platforms and configurations.

For example:

https://example.app.goo.gl/?link=https://www.example.com/someresource&apn=com.example.android&amv=3&ad=1

Debug your Dynamic Links

To help you debug your Dynamic Links, you can preview your Dynamic Links' behavior on different platforms and configurations with an automatically-generated flowchart. Generate the flowchart by adding the d=1 parameter to any long Dynamic Link.

View Analytics data

To help you gauge the effectiveness of your promotions and campaigns, the following Analytics events are automatically logged when you open a short Dynamic Link in your app. You can create short Dynamic Links in the Firebase console.

Analytics events
dynamic_link_first_open Logged when a user opens the app for the first time via a Dynamic Link.
dynamic_link_app_open Logged when a user opens the app via a Dynamic Link.
dynamic_link_app_update Logged when the app is updated to a new version via a Dynamic Link. Android only.

You can then view the logged data in the Analytics section of the Firebase console.

Dynamic Links events in Firebase Analytics If you mark Dynamic Link events as conversions, you can see how your Dynamic Links are performing on the Attribution page.

Send feedback about...

Need help? Visit our support page.