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

RudderStack supports Firebase as a mobile device mode to which you can seamlessly send your customer data for analytics.

Firebase device mode support is not available for the Cordova SDK.

Getting started

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

Connection ModeWebMobileServer
Device mode-Supported-
Cloud mode---
Firebase is a device mode-only integration. To learn 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, follow these steps:

  1. From your RudderStack dashboard, add a source. Then, from the list of destinations, select Firebase.
  2. Assign a name to the destination and click Next.

Connection settings

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 Next to complete the destination setup.

Adding device mode integration

Depending on your platform of integration, follow the steps below to add Firebase to your project:

Use the latest version of the Firebase Android device mode to get the latest updates, bug fixes, and performance enhancements.
Follow these steps to add Firebase to your Android project:
  1. Register your mobile app in the Firebase console.
  2. Once you have successfully created the app in the Firebase console, you will be prompted to download the google-services.json file.
  3. Copy this file in the app folder of your project. It contains all the necessary information about the project and the integration.
  4. Add the classpath under dependencies to your project level build.gradle, as shown:
    buildscript {
    repositories {
    google()
    }
    dependencies {
    // add this line
    classpath 'com.google.gms:google-services:4.3.3'
    }
    }
  5. Now, 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'
  6. Then, add the mavenCentral repository, as shown:
    repositories {
    mavenCentral()
    }
  7. Add the RudderStack-Firebase SDK extension along with the core SDK under dependencies, as shown:
    implementation 'com.rudderstack.android.sdk:core:1.+'
    implementation 'com.rudderstack.android.integration:firebase:2.+'
    //Firebase
    implementation platform('com.google.firebase:firebase-bom:28.4.2')
    implementation 'com.google.firebase:firebase-analytics'
  8. Next, 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" />
  9. Finally, change the SDK initialization in your Application class, as shown:
    val rudderClient = RudderClient.getInstance(
    this,
    <SOURCE_WRITE_KEY>,
    RudderConfig.Builder()
    .withDataPlaneUrl(<DATA_PLANE_URL>)
    .withFactory(FirebaseIntegrationFactory.FACTORY)
    .build()
    )
If you're using the Firebase iOS device mode v1.0.2, update to the latest version to get the latest updates, bug fixes, and performance enhancements.
Follow these steps to add Firebase to your iOS project:
  1. Register your app in the Firebase console. It will then prompt you to download the GoogleServices-Info.plist file.
  2. Add the file to the root of your XCode project.
  3. Go to your Podfile and add the Rudder-Firebase extension along with the core SDK using the following code:
    pod 'Rudder-Firebase', '~> 2.0.5'
  4. Rudder-Firebase version 2.0.5 is tested and fully compatible with Firebase/Analytics version 8.15.0.
  5. After adding the dependency followed by the pod install command, you can add the imports to your AppDelegate.m file, as shown:
    #import "RudderFirebaseFactory.h"
  6. Finally, change the SDK initialization, as shown in the following snippet:
    RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
    [builder withDataPlaneUrl:<DATA_PLANE_URL>];
    [builder withFactory:[RudderFirebaseFactory instance]];
    [builder withLoglevel:RSLogLevelDebug];
    [RSClient getInstance:<WRITE_KEY> config:[builder build]];
This device mode integration is supported for Firebase v8.15.0 and above.
Follow these steps to add Firebase to your iOS project:
  1. Add Firebase as a destination in the RudderStack dashboard.
  2. Register your app in the Firebase console. It will then prompt you to download the GoogleServices-Info.plist file.
  3. Download and place this file in your project.
  4. Install RudderFirebase (available through CocoaPods) by adding the following line to your Podfile:
    pod 'RudderFirebase', '~> 1.0.0'
  5. Run the pod install command.
  6. Then, import the SDK depending on your preferred platform:
    import RudderFirebase
    @import RudderFirebase;
  7. Next, add the imports to your AppDelegate file under the didFinishLaunchingWithOptions method, as shown:

    RSConfig *config = [[RSConfig alloc] initWithWriteKey:WRITE_KEY];
    [config dataPlaneURL:DATA_PLANE_URL];
    [[RSClient sharedInstance] configureWith:config];
    [[RSClient sharedInstance] addDestination:[[RudderFirebaseDestination alloc] init]];
    let config: RSConfig = RSConfig(writeKey: WRITE_KEY)
    .dataPlaneURL(DATA_PLANE_URL)
    RSClient.sharedInstance().configure(with: config)
    RSClient.sharedInstance().addDestination(RudderFirebaseDestination())
Follow these steps to add Firebase to your Unity project:
  1. Register your project in the Firebase Console. Currently, RudderStack supports only Android and iOS platforms for Unity.
  2. After adding the project, Firebase will prompt you to download the google-services.json for Android and GoogleServices-Info.plist for iOS.
  3. Add those two files to your project's Assets folder.
  4. Integrate the RudderStack core SDK with your project. For more information, refer to the Unity SDK documentation.
  5. Download and import the Firebase Unity SDK and follow the instructions to add the Firebase SDK (specifically, FirebaseAnalytics.unitypackage) to your project.
  6. Download the RudderStack Firebase Extension from the GitHub page and import it in your project.
  7. Attach the RudderPreferbs.prefab file from Rudder to your main GameObject
  8. 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()
    );
Use the latest version of the Firebase React Native device mode to get the latest updates and performance enhancements.
Follow these steps to add Firebase to your React Native project:
  1. Register your Android and iOS applications in the Firebase console.
  2. 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.
  3. Add the RudderStack React Native SDK to your app by referring to the React Native SDK documentation.
  4. 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
  5. 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);
  6. Navigate to your app's android folder and follow the steps below:
    1. Copy the google-services.json file in the app folder of your Android project. This file contains all the necessary information about the project and the integration.
    2. Add the classpath under dependencies to your project level build.gradle file, as shown:
      buildscript {
      repositories {
      google()
      }
      dependencies {
      // add this line
      classpath 'com.google.gms:google-services:4.3.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'
    4. 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" />
  7. Finally, navigate to your app's iOS folder and follow these steps:
    1. Install all the required pods using the pod install command.
    2. Add the GoogleServices-Info.plist file to the root of your XCode project.
Follow the below steps to add Firebase to your Flutter Project:
  1. Add the following dependency to the dependencies section of your pubspec.yaml file.
    rudder_integration_firebase_flutter: ^1.0.1
  2. Run the below command to install the dependency added in the above step:
    flutter pub get
  3. Import the RudderIntegrationFirebaseFlutter in your application where you are initializing the SDK.
    import 'package:rudder_integration_firebase_flutter/rudder_integration_firebase_flutter.dart';
  4. Change the initialization of your RudderClient as shown:
    final RudderController rudderClient = RudderController.instance;
    RudderConfigBuilder builder = RudderConfigBuilder();
    builder.withFactory(RudderIntegrationFirebaseFlutter());
    rudderClient.initialize(<WRITE_KEY>, config: builder.build(), options: null);
  5. Navigate to your app's android folder and follow the below steps:
    • Copy the google-services.json file in the app folder of your Android project. This file contains all the necessary information about the project and the integration.
    • Add the classpath under dependencies to your project level build.gradle file, as shown:
      buildscript {
      repositories {
      google()
      }
      dependencies {
      // add this line
      classpath 'com.google.gms:google-services:4.3.3'
      }
      }
    • Add mavenCentral() as a repository under buildscript.repositories and allprojects.repositories to your project level build.gradle file, as shown:
      buildscript {
      repositories {
      google()
      // should be added
      mavenCentral()
      }
      dependencies {
      classpath 'com.google.gms:google-services:4.3.3'
      }
      }
      allprojects {
      repositories {
      google()
      // should be added
      mavenCentral()
      }
      }
    • Next, 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'
    • 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" />
  6. Finally, navigate to your app's iOS folder and 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 properties 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

RudderStack's track events are mapped to the standard Firebase events wherever possible.

Event mapping

RudderStack maps the following events to the standard Firebase events:

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

The following Firebase events are not mapped to any RudderStack event:

  • 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 event-related properties to Firebase. The nested values in the properties are converted to JSON using GSON.

Property mapping

RudderStack maps the following event properties to the standard Firebase properties:

RudderStack propertyFirebase property
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 mapping the above list of the standard property names, RudderStack exhibits the following behavior:

  • Converts the event names to the lower case.
  • Trims the whitespaces at the start and the end.
  • Replaces a space with an underscore.

Firebase enforces a strict event name length limit of 40 characters. RudderStack takes a substring of 40 characters (from the beginning) if the event names exceed this permitted value.

A sample track call sent 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 lets you record whenever a user sees their mobile screen along with any optional properties about the viewed screen.

A sample screen call is as shown:

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

Reset

The reset method resets the user identification.

A sample reset call is shown below:

[[RSClient getInstance] reset];
RudderClient.getInstance()?.reset()

Debugging

You can check the events and their properties in the Firebase DebugView. To enable it for Android, run the following command 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

FAQ

How do I disable automatic screen tracking while using the RudderStack SDKs?

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

For more information, refer to the Firebase documentation.


Contact us

For more information on the topics covered on this page, email us or start a conversation in our Slack community.

On this page