Firebase Destination

Segment makes it easy to send your data to Firebase (and lots of other destinations). Once you've tracked your data through our open source libraries we'll translate and route your data to Firebase in the format they understand. Learn more about how to use Firebase with Segment.

Getting Started

This destination is currently in beta. If you are interested in joining, let us know!

Android

To start sending data to Firebase Analytics from your Android project, you’ll need to follow a few simple steps:

  • Register your mobile app with Firebase at https://console.firebase.google.com
  • Once your app is registered, you’ll be prompted to download a google-services.json file. Place this in your Application’s “app” folder. This file contains all necessary configurations and cannot be used across multiple apps. If you’re configuring Firebase for other apps, you should create a new view in your Firebase console and download a unique google-services.json file for each.

Module-level build.gradle: Add the Segment-Firebase SDK and apply the Google Services plugin at the end of the file:

buildscript {
    dependencies {
        // Add these lines
        compile 'com.segment.analytics.android:analytics:4.+'
        compile 'com.segment.analytics.android.integrations:firebase:+'
    }
}

// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

Project-level build.gradle: Add Google Services dependency and their Maven repo location to repositories:

buildscript {
    dependencies {
        // Add this line
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        // Add this line
        maven { url 'https://maven.google.com' }
    }
}

Add these permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK” />

Finally, register the dependency with the Segment SDK in your application subclass, as seen here in our Android library documentation:

Analytics analytics = new Analytics.Builder(context, writeKey)
  .use(FirebaseIntegration.FACTORY)
  ...
  .build();

By default, we bundle only Firebase/Core which is Firebase’s Analytics offering. You can see the other available Firebase dependencies and features here.

iOS

  • Register your app in the Firebase console and add the GoogleService-Info.plist to the root of your Xcode project.

  • First add the following dependency to your Podfile:

    pod 'Segment-Firebase'
    
  • After adding the dependency, import the integration:

#import <Segment-Firebase/SEGFirebaseIntegrationFactory.h>
  • Finally, register the dependency with the Segment SDK:
[config use:[SEGFirebaseIntegrationFactory instance]];

By default, Segment only bundles Firebase/Core which is Firebase’s Analytics offering. You can see the other available Firebase pods and features here.

Identify

When you call identify Segment will map to the corresponding Firebase Analytics calls:

  • If there is a userId on your identify call, Segment triggers setUserId via the Firebase SDK
  • If there are traits included, Segment will set user properties for each trait you include on the identify call

You can use these traits to create audiences and views to analyze your users’ behavior.

Note: Google prohibits sending PII to Firebase unless “robust notice” is given to your app users. For iOS apps, you must include the iAD Framework to automatically collect the Age, Gender, and Interests Firebase properties.

Learn more about Firebase’s reporting dashboard here.

Firebase has strict requirements for User Property names; they must:

  • Begin with a letter (not a number or symbol, including an underscore)
  • Contain only alphanumeric characters and underscores
  • Be no longer than 40 characters

User Property values must be fewer than 100 characters.

You are limited to 25 unique user properties per Firebase Console.

Segment automatically:

  • Trims leading and trailing whitespace from user property names
  • Replaces spaces with underscores
  • Trims property names to 40 characters (Android only)

Firebase automatically collects these user properties.

Track

When you call track Segemtn will log the event with Firebase. Firebase automatically tracks the events listed here and it will still do so when bundling with Segment.

Firebase has a limit of 500 distinctly named events so it pays off to be intentional in what you track.

When you call track, Segment maps from the Segment spec to those that match Firebase’s spec. For anything that does not match, Segment will pass the event to Firebas as a custom event. Custom parameters cannot be seen directly in the Firebase Analytics dashboard but they can be used as filters in Audiences.

Like with user properties, Segment will perform the following transformations on both your event names and event parameters. Unlike user properties, you do not need to pre-define event parameters in your Firebase dashboard.

  • Trims leading and trailing whitespace from property names
  • Replaces spaces with underscores
  • Trims property names to 40 characters (Android only)

Event parameter values must be fewer than 100 characters.

Event Mappings

Segment adheres to Firebase’s semantic event specification and maps the following Segment specced events (left) to the corresponding Firebase events (right):

Segment EventFirebase Event
Products Searchedsearch
Product List Viewedview_item_list
Product Viewedview_item
Product Clickedselect_content
Product Sharedshare
Product Addedadd_to_cart
Product Added To Wishlistadd_to_wishlist
Checkout Startedbegin_checkout
Promotion Viewedpresent_offer
Payment Info Enteredadd_payment_info
Order Completedecommerce_purchase
Order Refundedpurchase_refund

Property Mappings

Segment maps the followed Segment specced properties (left) to the corresponding Firebase event parameters (right):

Segment PropertyFirebase PropertyAccepted Value(s)
categoryitem_category(String) “kitchen supplies”
product_iditem_id(String) “p1234”
nameitem_name(String) “Le Creuset pot”
priceprice(double) 1.0
quantityquantity(long) 1
querysearch_term(String) “Le Creuset”
shippingshipping(double) 2.0
taxtax(double) 0.5
totalvalue(double) 3.99 or (long) 3.99
revenuevalue(double) 3.99 or (long) 3.99
order_idtransaction_id(String) “o555636”
currencycurrency(String) “USD”

Passing Revenue and Currency

Ecommerce events containing “revenue” or “total” must also include the appropriate ISO 4217 “currency” string for revenue data to populate to the Firebase dashboard. If a “currency” value is not included, Segment default to “USD”.

Properties properties = new Properties()
        .putValue("orderId", "p966540")
        .putValue("revenue", 25.00)
        .putCurrency("USD");


Analytics.with(this).track("Order Completed", properties);

Screen

Segment doesn’t map screen events to Firebase - that’s because Firebase’s SDK collects screen information out of the box for you.

For Android, Segment passes contextual screen information into each screen view on each activity’s onResume callback. To ensure that screen names are labeled properly, Segment recommends adding a label value to each of your activities in your app’s AndroidManifest.xml file. At the moment, Firebase does not allow disabling automatic screen tracking for Android.

For iOS, you can configure recordScreenViews which will automatically track screen views, or pass in a screen manually via a screen call. You should be able to disable the Automatic Screen reporting by adding the plist flag FirebaseScreenReportingEnabled to Info.plist and set its value to NO (Boolean).

Google Analytics for Firebase iOS does NOT support the case of manual-only screen reporting. Firebase only supports automatic + manual screen reporting or no screen reporting at all.

Firebase Dynamic Linking (iOS only)

Firebase Dynamic Links are smart URLs that can change behavior dynamically depending on the platform where the user clicks them. Use them in web, email, social media, referral and physical promotions to increase user acquisition, retention and lifetime value. Key features include ability to survive app installs, controlling user experience depending on what platform they access the link on and knowing which content and campaigns are working via tracking in the Firebase console. Check out Firebase’s Docs here.

To use Firebase Dynamic Links, add the below to your podfile.

pod 'Firebase/DynamicLinks'

Then, enter the deep link URL scheme in your Segment Firebase destination settings. Here’s a sample app delegate that shows how to implement the Dynamic Linking Logic.

Conversion Tracking and Adwords Conversions

Firebase is now Google’s recommended method for reporting conversions to Adwords! To do so, simply track the conversion events as you normally would with Segment and Segment will send them through to Firebase! Follow this documentation from Firebase to set up your conversions in Firebase and to have them forwarded to Adwords.

Troubleshooting

Firebase has great logging. If you are having any issues, you can enable debug mode as outlined here.

Changes from iOS v1 to v2 Beta

We have been working hard bringing our Firebase iOS beta integration up to date with the native Firebase SDK. The new version 2.0.0-beta has a number of changes that you should be aware of before you upgrade.

  • Bumps to Firebase version 4.0. (we were a major version behind)
  • Removes subspec which pulls in the deprecate pod appIndexing .
  • Fixes a crash when passing a non NSString value through traits on Identify.
  • Fixes Mapping to Firebase logEvent and Firebase reserved Params and Constants.

The last point is important, as the mappings are different in this new version and will change which events you seen in your Firebase dash. We suggest you make this upgrade, as this new naming convention coincides with Firebase’s semantic Constants and Params.

Even more exciting is that this new iOS SDK will have parity with the new Segment-Firebase Android SDK.

As a current user of Segment-Firebase iOS, you will be able to pull in the latest version by pinning pod 'Segment-Firebase', '~>2.0. While we don’t suggest this, if you are not ready to upgrade you can pin the old beta version at pod 'Segment-Firebase', '~>1.0.0``'

For details on the new mapping, you can check out our documentation here.

Please let us know if you have any questions. We recommend upgrading as soon as possible, and please let us know if you have any feedback about both the Firebase iOS and Android betas.


Supported Sources and Connection Modes

WebMobileServer
📱 Device-based
☁️ Cloud-based

To learn more about about Connection Modes and what dictates which we support, see here.

This destination requires a Device-based Connection Mode for Mobile data. Follow the steps above to ensure you have packaged the Firebase SDK with Segment’s.

Settings

Segment lets you change these destination settings via your Segment dashboard without having to touch any code.

For iOS, if you’re using Firebase for Deep Linking, we’ll set this as the deepLinkURLScheme before initializing Firebase.


If you have any questions or see anywhere we can improve our documentation, please let us know or kick off a conversation in the Segment Community!