Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Analytics Kotlin Firebase Plugin


Firebase is Google's platform for mobile apps. The Segment Firebase destination requires that you bundle the Firebase SDK with your project. The Segment-wrapped destination code then runs on the user's device, and sends its tracking calls to the Firebase API endpoints, and a copy to Segment for archiving.

Firebase's destination plugin code is open source and available on GitHub(link takes you to an external page).


Adding the dependency

adding-the-dependency page anchor

To install the Segment-Firebase integration, add this line to your gradle file:

implementation 'com.segment.analytics.kotlin.destinations:firebase:<latest_version>'

Or the following for Kotlin DSL:

implementation('com.segment.analytics.kotlin.destinations:firebase:<latest_version>')

Using the plugin in your app

using-the-plugin-in-your-app page anchor

Open the file where you set up and configure the Analytics-Kotlin library. Add this plugin to the list of imports.

import com.segment.analytics.kotlin.destinations.firebase.FirebaseDestination

Under your Analytics-Kotlin library setup, call analytics.add(plugin = ...) to add an instance of the plugin to the Analytics timeline.

1
analytics = Analytics("<YOUR WRITE KEY>", applicationContext) {
2
this.flushAt = 3
3
this.trackApplicationLifecycleEvents = true
4
}
5
analytics.add(plugin = FirebaseDestination(applicationContext))

Your events will now begin to flow to Firebase in device mode.


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

  • If there is a userId in your Identify call, Segment triggers setUserId using 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(link takes you to an external page). For iOS apps, some Analytics features, such as audiences and campaign attribution, and some user properties, such as Age and Interests, require the AdSupport framework(link takes you to an external page) to be enabled.

Learn more about Firebase's reporting dashboard here(link takes you to an external page).

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.

Firebase automatically collects these user properties(link takes you to an external page).


When you call Track Segment will log the event with Firebase. Firebase automatically tracks the events listed here(link takes you to an external page) 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 Firebase 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 don't 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

event-mappings page anchor

Segment adheres to Firebase's semantic event specification and maps the following Segment spec-matching events to the corresponding Firebase events:

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 Completedpurchase
Order Refundedpurchase_refund

Segment maps the followed Segment spec-matching properties to the corresponding Firebase event parameters:

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

passing-revenue-and-currency page anchor

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".

1
analytics.track("Order Completed", buildJsonObject {
2
put("orderId", "order-123")
3
put("revenue", 23.00)
4
put("currency", "USD")
5
});

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

For iOS, you can configure recordScreenViews which will automatically track screen views, or pass in a screen manually using a screen call. You can 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.

Conversion tracking and Adwords conversions

conversion-tracking-and-adwords-conversions page anchor

Firebase is Google's recommended method for reporting conversions to Adwords. To use Firebase, track the conversion events as you normally would with Segment and Segment will send them through to Firebase.

Firebase has great logging. If you're having any issues, you can enable debug mode as outlined in Google'd Debug view(link takes you to an external page) documentation.