Firebase

Firebase is a popular mobile platform powered by Google. It helps you to quickly develop high-quality, enterprise-grade applications and grow your business.

Firebase is tightly integrated with Google Analytics and offers unlimited reporting for up to 500 events defined using the Firebase SDK. You can check the Firebase destination code on GitHub for Android and iOS platforms.

RudderStack lets you send your event data from your mobile apps to Firebase through its Android, iOS, Unity, and ReactNative SDKs. This guide will help you set up, configure, and use Firebase for your project.

Getting started

Before configuring Firebase as a destination in RudderStack, verify if the source platform is supported by Firebase, by referring to the following table:

Connection ModeWebMobileServer
Device mode-Supported-
Cloud mode---

Firebase is a device-mode only integration. To know more about the difference between cloud mode and device mode in RudderStack, refer to the RudderStack connection modes guide.

Once you have confirmed that the source platform supports sending events to Firebase, perform the steps below:

Refer to the Adding a source and destination in RudderStack guide for more information.

  • Assign a name to your destination and click on Next.

  • Then, connect this destination to your Android/iOS/Unity/React Native source. You should then see the following screen:

Firebase connection settings
  • As this is a device mode-only integration, click on Next to complete the destination setup.

  • Next, depending on your platform of integration follow the steps below to enable Firebase in your project:

Follow these steps to add Firebase to your Android project:
  • Register your mobile application in the Firebase console.
  • Once you have successfully created the application in the Firebase console, you will be prompted to download the google-services.json file.
  • Copy this file in the app folder of your project. It contains all the necessary information about the project and the integration.
  • Add the classpath under dependencies to your project level build.gradle
    buildscript {
    repositories {
    google()
    }
    dependencies {
    // add this line
    classpath 'com.google.gms:google-services:4.3.3'
    }
    }
  • Once you have completed the steps above, you can add the plugins and dependencies to your app/build.gradle file as shown:
    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'
  • Then, add the repository as shown:
    repositories {
    mavenCentral()
    }
  • Add the RudderStack-Firebase SDK extension along with core SDK under dependencies:
    implementation 'com.rudderstack.android.sdk:core:1.+'
    implementation 'com.rudderstack.android.integration:firebase:2.+'
  • Then, add the necessary permissions under AndroidManifest.xml as shown:
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  • Finally, change the initialization of your RudderClient in your Application class.
    val rudderClient = RudderClient.getInstance(
    this,
    <SOURCE_WRITE_KEY>,
    RudderConfig.Builder()
    .withDataPlaneUrl(<DATA_PLANE_URL>)
    .withFactory(FirebaseIntegrationFactory.FACTORY)
    .build()
    )
Follow these steps to add Firebase to your iOS project:
  • Register your app to the Firebase console. It will then prompt you to download the GoogleServices-Info.plist file.
  • Add the file to the root of your XCode project.
  • Go to your Podfile and add the Rudder-Firebase extension along with the core SDK using the following code:
    pod 'Rudder-Firebase'
  • After adding the dependency followed by pod install ,you can add the imports to your AppDelegate.m file as shown:
    #import "RudderFirebaseFactory.h"
  • Finally, change the intialization of your `RudderClient` as shown:
    RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
    [builder withDataPlaneUrl:DATA_PLANE_URL];
    [builder withFactory:[RudderFirebaseFactory instance]];
    [builder withLoglevel:RSLogLevelDebug];
    [RSClient getInstance:WRITE_KEY config:[builder build]];

RudderStack will bundle the Firebase/Core and FirebaseAnalytics by default with the Rudder-Firebase pod.

Follow these steps to add Firebase to your Unity project:
  • Register your project in the Firebase Console. Currently, RudderStack supports only Android and iOS for Unity.
  • After adding the project, Firebase will prompt you to download the google-services.json for Android and GoogleServices-Info.plist for iOS.
  • Add those two files to your Assets folder.
  • Integrate the RudderStack core SDK with your project. To know more, refer to the Getting Started with Unity SDK guide.
  • Download and import the Firebase Unity SDK and follow these instructions on adding the Firebase SDK to your project. Specifically, FirebaseAnalytics.unitypackage.
  • Download the Firebase extension for RudderStack from the GitHub page and import it into your project.
  • Attach the RudderPreferbs.prefab file from Rudder to your main GameObject
  • Finally, change the SDK initialization using the following code snippet:
    // Build your config
    RudderConfigBuilder configBuilder = new RudderConfigBuilder()
    .WithEndPointUrl(<DATA_PLANE_URL>)
    .WithFactory(RudderFirebaseIntegrationFactory.GetFactory());
    // get instance for RudderClient
    RudderClient rudderClient = RudderClient.GetInstance(
    <SOURCE_WRITE_KEY>,
    configBuilder.Build()
    );
Follow these steps to add Firebase to your React Native project:
  • Register your Android and iOS applications in the Firebase console.
  • Once you have successfully created the applications in the Firebase console, you will be prompted to download the google-services.json and GoogleServices-Info.plist files.
  • Add the RudderStack React Native SDK to your app by referring to the Getting Started with the ReactNative SDK guide.
  • Add the RudderStack-Firebase react native module to your app using the following command:
    npm install @rudderstack/rudder-integration-firebase-react-native
    // OR //
    yarn add @rudderstack/rudder-integration-firebase-react-native
  • Next, import the module you added above and add it to your SDK initialization code as shown:
    import rudderClient from '@rudderstack/rudder-sdk-react-native';
    import firebase from "@rudderstack/rudder-integration-firebase-react-native";
    const config = {
    dataPlaneUrl: <DATA_PLANE_URL>,
    trackAppLifecycleEvents: true,
    withFactories: [firebase]
    };
    rudderClient.setup(<SOURCE_WRITE_KEY>, config);
  • Navigate to your app's android folder and follow the following steps:
    • Copy the google-services.json file in the app folder of your android project. The file contains all the necessary information about the project and the integration.
    • Add the classpath under dependencies to your project level build.gradle
      buildscript {
      repositories {
      google()
      }
      dependencies {
      // add this line
      classpath 'com.google.gms:google-services:4.3.3'
      }
      }
    • Once you have completed the steps above, you can add the plugins and dependencies to your app/build.gradle file as shown:
      apply plugin: 'com.android.application'
      apply plugin: 'com.google.gms.google-services'
    • Then, add the necessary permissions under AndroidManifest.xml as shown:
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  • Finally, navigate to your app's iOS folder and follow these steps:
    • Install all the required pods using pod install
    • Add the GoogleServices-Info.plist file to the root of your XCode project.

Identify

The identify call sets the userId through the setUserId method from FirebaseAnalytics. RudderStack sets the other user properties from RudderTraits to Firebase using the setUserProperty method. RudderStack ignores age, gender and interest as these are reserved by Google.

[[RSClient sharedInstance] identify:@"test_user_id"
traits:@{@"foo": @"bar",
@"foo1": @"bar1",
@"email": @"test@gmail.com",
@"key_1" : @"value_1",
@"key_2" : @"value_2"
}
];

Track

The track call from RudderStack is mapped to the standard events of Firebase wherever possible. RudderStack maps the events as per the following table:

RudderStack EventFirebase Event
Payment Info Enteredadd_payment_info
Product Addedadd_to_cart
Product Added to Wishlistadd_to_wishlist
Application Openedapp_open
Checkout Startedbegin_checkout
Order Completedpurchase
Order Refundedrefund
Products Searchedsearch
Cart Sharedshare
Product Sharedshare
Product Viewedview_item
Product List Viewedview_item_list
Product Removedremove_from_cart
Product Clickedselect_content
Promotion Viewedview_promotion
Promotion Clickedselect_promotion
Cart Viewedview_cart

Apart from the above-mentioned events, the following Firebase standard events are not mapped to any RudderStack event. You can mention the exact names from the following list to be perceived as a standard event in Firebase.

  • number_of_nights
  • number_of_rooms
  • number_of_passengers
  • origin
  • destination
  • start_date
  • end_date
  • travel_class
  • item_list_name
  • creative_slot
  • location_id
  • transaction_id
  • screen_class

RudderStack passes all the properties from the event to Firebase. The nested value in the properties is converted to JSON using GSON.

RudderStack modifies the event property parameter names as per the following table:

Standard RudderStack NameStandard Firebase Name
categoryitem_category
cart_id,product_iditem_id
share_viamethod
querysearch_term
revenue, value, totalvalue
currencycurrency
taxtax
shippingshipping
couponcoupon
namename, promotion_name
quantityquantity
priceprice
payment_methodpayment_type
list_iditem_list_id
promotion_idpromotion_id
creativecreative_name
affiliationaffiliation

Along with the above list of the standard property names, RudderStack does the following in case of an Android source:

  • Converts the names to lower case.
  • Trims the white spaces from the start and the end.
  • Replaces space with underscore.
  • If the length of the key is more than 40, takes the substring of length 40 from the beginning.

Firebase enforces to have the value of length less than 100. RudderStack takes the substring of length 100 from the beginning if the length exceeds the permitted value.

A sample track call from the iOS SDK is shown below:

[[RSClient sharedInstance] track:@"simple_track_with_props" properties:@{
@"key_1" : @"value_1",
@"key_2" : @"value_2"
}];

Screen

The screen method allows you to record whenever a user sees the mobile screen along with any optional properties.

A sample screen call looks like the following:

[[RSClient sharedInstance] screen:@"Home Screen"
properties:@{
@"Width" : @"13"
}];

Reset

The reset method removes the user ID.

A sample reset call is shown in the following snippets:

  • In case of iOS:
[[RSClient sharedInstance] reset];
  • In case of Android:
MainApplication.rudderClient.reset()

Debugging

You can check the events and the properties along with it in the Firebase Debug View. To enable it for Android, fire the command below from your terminal:

$ adb shell setprop debug.firebase.analytics.app <your_package_name>

For iOS, specify the following in your command line argument in XCode:

-FIRAnalyticsDebugEnabled

FAQs

How do I disable automatic screen tracking while using this SDK?

  • For Android, nest the following setting within the <application> tag of the AndroidManifest.xml file:
<meta-data android:name="google_analytics_automatic_screen_reporting_enabled" android:value="false" />
  • In case of iOS, set FirebaseAutomaticScreenReportingEnabled to NO (Boolean) in the Info.plist.

For more information, visit the Firebase docs on this topic.

Contact us

If you come across any issues while configuring Firebase with RudderStack, you can contact us. You can also start a conversation on our Slack channel.