Google Firebase

Google Analytics vs. Google Firebase

If you are a free customer, please as follow the guide below as Google Analytics has been deprecated for free users. If you are a paying Google Analytics customer, please refer to our data integration for Google Analytics.

Overview

With a push of a button you can send your Branch data to your Google Analytics dashboard, helping you understand the power of Branch as an acquisition pathway. If you're interested in the segment of users coming into your apps through Branch and want to measure their events against your other cohorts, this guide can help.

Prerequisites

Events Sent to Google Firebase

Branch will send referred installs and opens, as well as any custom events you track with Branch. Non-referred events, clicks, web session starts, and pageviews will be excluded. Branch also sends over analytics data that is attached to the link, whether it's UTM tags or fields set on the Branch Dashboard (e.g. Campaign, Channel, Feature). This will allow you to analyze which campaigns, channels, etc. are helping you acquire and engage users.

Below is the full list of fields:

Property Name Value Sourced from Example Req
v API version [fixed] 1 Y
tid Tracking ID Google Analytics Dashboard UA-XXXXXX-Y Y
ds Source (mobile SDK) [fixed] app Y
an Application Name [fixed] BRANCH-APP Y
t Type [fixed] event Y
ec Event Category [fixed] BranchEvent Y
uid User Id $google_analytics_user_id User A N
cn Campaign Name utm_campaign -or- Branch campaign "Beaches and breezes" N
cs Campaign Source utm_source -or- Branch channel "Twitter" N
cm Campaign Medium utm_medium -or- Branch feature "480banner" N
ck Campaign Keywords utm_term -or- Branch $keywords ["Keyword1", "keyword3"] N
cc Campaign Content utm_content -or- Branch tags "Some content" N
ea Event Action (Name) event name install Y
uip User’s IP Address collected by Branch SDK 111.111.111.111 N
z Cache buster [unix time + random number] 1461878903666 N

Setup

Android

  1. Ensure you've completed the Firebase SDK implementation as documented here
  2. Ensure you've completed the Branch SDK implementation as documented here.
  3. In the LauncherActivity#onStart() method of the Branch Android SDK, update the implementation as below:
@Override
     public void onStart() {
         super.onStart();

         // Branch init
         Branch.sessionBuilder(this).withCallback(new Branch.BranchReferralInitListener() {
             @Override
             public void onInitFinished(JSONObject referringParams, BranchError error) {
                 if (error == null) {
                     if (referringParams != null) {
                         try {
                             // check if the session is from a Branch link
                             if (referringParams.getBoolean(""+clicked_branch_link"")) {

                                 // create FirebaseAnalytics instance
                                 FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics
                                         .getInstance(getApplicationContext());
                                 Bundle bundle = new Bundle();

                                 bundle.putBoolean(""clicked_branch_link"",
                                         referringParams.getBoolean(""+clicked_branch_link""));
                                 // get the click timestamp
                                 bundle.putString(""click_timestamp"",
                                         referringParams.getString(""+click_timestamp""));
                                 // get the link OG title
                                 bundle.putString(""link_title"",
                                         referringParams.getString(""$og_title""));
                                 // get the link OG image
                                 bundle.putString(""link_image"",
                                         referringParams.getString(""$og_image_url""));
                                 // get the link campaign
                                 bundle.putString(""utm_campaign"",
                                         referringParams.getString(""~campaign""));
                                 // get the link feature
                                 bundle.putString(""utm_medium"",
                                         referringParams.getString(""~feature""));
                                 // get the link channel
                                 bundle.putString(""utm_source"",
                                         referringParams.getString(""~channel""));

                                 // you can use the local shared preference to detect if this is an install session or open session as below
                                 SharedPreferences sharedPreferences = getApplication()
                                         .getSharedPreferences(""local_sharefpref"",
                                                 Context.MODE_PRIVATE);
                                 SharedPreferences.Editor editor = sharedPreferences.edit();
                                 boolean isFirstSession = sharedPreferences
                                         .getBoolean(""is_first_session"", true);
                                 if (isFirstSession) {
                                     editor.putBoolean(""is_first_session"", false);
                                     editor.apply();
                                 }

                                 // check if the session is install or open
                                 String eventName =
                                         isFirstSession ? ""branch_install"" : ""branch_open"";

                                 // log the event to the firebase
                                 firebaseAnalytics.logEvent(eventName, bundle);
                             }
                         } catch (JSONException ignore) {
                         }
                     }
                 }
             }
         }).withData(this.getIntent().getData()).init();
     }

iOS

  1. Ensure you've completed the Firebase SDK implementation as documented here
  2. Ensure you've completed the Branch SDK implementation as documented here.
  3. In the AppDelegate of the Branch iOS SDK, update the implementation as below:
    FirebaseApp.configure()
    Branch.getInstance().initSession(launchOptions: launchOptions) { (params, error) in
    // do stuff with deep link data (nav to page, display content, etc)
    if(error == nil && params != nil){
      // create and add properties that you want to track in Firebase
      var firebase_params = [String: Any]()
      firebase_params["clicked_branch_link"] =  params?["+clicked_branch_link"] ?? ""
      // get the click timestamp
      firebase_params["click_timestamp"] = params?["+click_timestamp"] ?? ""
      // get the link OG title
      firebase_params["link_title"] = params?["$og_title"] ?? ""
      // get the link OG image
      firebase_params["link_image"] =  params?["$og_image_url"] ?? ""
      // get the link campaign
      firebase_params["utm_campaign"] = params?["~campaign"] ?? ""
      // get the link feature
      firebase_params["utm_medium"] = params?["~feature"] ?? ""
      // get the link channel
      firebase_params["utm_source"] = params?["~channel"] ?? ""
      // check if this is an open or and install event
      if(UserDefaults.standard.object(forKey: "is_first_session") == nil){
        UserDefaults.standard.set(true, forKey: "is_first_session")
      }
                    else{
        UserDefaults.standard.set(false, forKey: "is_first_session")
      }
      let event_name = UserDefaults.standard.bool(forKey: "is_first_session") == true ? "branch_install" : "branch_open"
      // track the event to Firebase
      Analytics.logEvent(event_name, parameters: firebase_params)
    }
    }

mParticle for Android and/or iOS

If you use the mParticle plugins alongside the Branch SDK, you must ensure Firebase authenticates before the Branch session is initialized with mParticle. When the Branch session is initialized with mParticle prior to Firebase authentication, the deep link data is not returned.

Using Firebase DebugView

To debug the events and their metadata, you can enable the DebugView on Firebase to verify the setup. Please refer to Google's official instructions here.

image

Common Discrepancies Between Firebase & Branch

  • When the attribution of the custom events occurs in the following sessions after the click (i.e not the session after the immediate click). For example, Click -> app open -> app close -> app open -> Purchase -> Purchase sent to Firebase.

    The above purchase event on Branch might be attributed based on the attribution window, but on the Firebase this will always be organic as the SDK will not have the attribution data.

  • SAN attribution support, for Google UAC (no deep linking) and Facebook App Install (not so reliable deferred deep links), the Firebase installs would miss the attribution data.

NOTE

Please ensure you’ve reviewed your agreements with any ad network (for example Facebook, Snap and Twitter) to ensure your handling of attribution data and use of third party analytics tools is in compliance.

  • As per your account settings, it may be the case where the Fingerprinting attribution is disabled. This means that the deep link will return the link data, but no attribution data will be recorded at Branch’s end. If this is the case (ensure to check with your Account Manager).

Updated 2 months ago

Google Firebase


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.