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 Mode | Web | Mobile | Server |
|---|---|---|---|
| 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:
- From your RudderStack dashboard, add the source. From the list of destinations, select Firebase.
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:
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:
- 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.jsonfile. - Copy this file in the
appfolder of your project. It contains all the necessary information about the project and the integration. - Add the
classpathunderdependenciesto your project levelbuild.gradlebuildscript {repositories {google()}dependencies {// add this lineclasspath 'com.google.gms:google-services:4.3.3'}} - Once you have completed the steps above, you can add the
pluginsanddependenciesto yourapp/build.gradlefile 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
coreSDK underdependencies:implementation 'com.rudderstack.android.sdk:core:1.+'implementation 'com.rudderstack.android.integration:firebase:2.+' - Then, add the necessary
permissionsunderAndroidManifest.xmlas shown:<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> - Finally, change the initialization of your
RudderClientin yourApplicationclass.val rudderClient = RudderClient.getInstance(this,<SOURCE_WRITE_KEY>,RudderConfig.Builder().withDataPlaneUrl(<DATA_PLANE_URL>).withFactory(FirebaseIntegrationFactory.FACTORY).build())
- Register your app to the Firebase console. It will then prompt you to download the
GoogleServices-Info.plistfile. - Add the file to the root of your XCode project.
- Go to your
Podfileand add theRudder-Firebaseextension 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 yourAppDelegate.mfile 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.
- 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.jsonfor Android andGoogleServices-Info.plistfor iOS. - Add those two files to your
Assetsfolder. - 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.prefabfile fromRudderto your mainGameObject - Finally, change the SDK initialization using the following code snippet:// Build your configRudderConfigBuilder configBuilder = new RudderConfigBuilder().WithEndPointUrl(<DATA_PLANE_URL>).WithFactory(RudderFirebaseIntegrationFactory.GetFactory());// get instance for RudderClientRudderClient rudderClient = RudderClient.GetInstance(<SOURCE_WRITE_KEY>,configBuilder.Build());
- 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.jsonandGoogleServices-Info.plistfiles. - 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
androidfolder and follow the following steps:- Copy the
google-services.jsonfile in theappfolder of your android project. The file contains all the necessary information about the project and the integration. - Add the
classpathunderdependenciesto your project levelbuild.gradlebuildscript {repositories {google()}dependencies {// add this lineclasspath '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.gradlefile as shown:apply plugin: 'com.android.application'apply plugin: 'com.google.gms.google-services' - Then, add the necessary permissions under
AndroidManifest.xmlas shown:<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- Copy the
- Finally, navigate to your app's
iOSfolder and follow these steps:- Install all the required pods using
pod install - Add the
GoogleServices-Info.plistfile to the root of your XCode project.
- Install all the required pods using
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 Event | Firebase Event |
|---|---|
Payment Info Entered | add_payment_info |
Product Added | add_to_cart |
Product Added to Wishlist | add_to_wishlist |
Application Opened | app_open |
Checkout Started | begin_checkout |
Order Completed | purchase |
Order Refunded | refund |
Products Searched | search |
Cart Shared | share |
Product Shared | share |
Product Viewed | view_item |
Product List Viewed | view_item_list |
Product Removed | remove_from_cart |
Product Clicked | select_content |
Promotion Viewed | view_promotion |
Promotion Clicked | select_promotion |
Cart Viewed | view_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_nightsnumber_of_roomsnumber_of_passengersorigindestinationstart_dateend_datetravel_classitem_list_namecreative_slotlocation_idtransaction_idscreen_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 Name | Standard Firebase Name |
|---|---|
category | item_category |
cart_id,product_id | item_id |
share_via | method |
query | search_term |
revenue, value, total | value |
currency | currency |
tax | tax |
shipping | shipping |
coupon | coupon |
name | name, promotion_name |
quantity | quantity |
price | price |
payment_method | payment_type |
list_id | item_list_id |
promotion_id | promotion_id |
creative | creative_name |
affiliation | affiliation |
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
spacewithunderscore. - 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:
-FIRAnalyticsDebugEnabledFAQs
How do I disable automatic screen tracking while using this SDK?
- For Android, nest the following setting within the
<application>tag of theAndroidManifest.xmlfile:
<meta-data android:name="google_analytics_automatic_screen_reporting_enabled" android:value="false" />- In case of iOS, set
FirebaseAutomaticScreenReportingEnabledtoNO(Boolean) in theInfo.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.