Google Firebase Analytics

Unlock real-time insights, user behavior tracking, and integration with other Firebase services.

Google Firebase Analytics provides powerful insights into user behavior within your app, helping you understand how users engage and interact.

It offers essential app metrics such as average revenue per user (ARPU), active users, retention reports, and event counts, along with detailed user properties like device type, app version, and OS version. By combining these data points, Firebase Analytics enables data-driven decision-making to optimize app performance and user experience.

👍

Developer Demo

Display our demo page in your app to test during development https://median.dev/firebase-analytics/

Google Firebase and App Configuration

Google Firebase Project Setup

If you do not have an active Google Firebase project, you may need to create a new project after signing into your Google Firebase Account.

Once your project is setup you can start the integration by choosing either the iOS or Android logo in your Project Overview screen.

Google Firebase - Project Overview

Google Firebase - Project Overview

Android Setup

You can register your app in Firebase by providing the Android Package Name. The Android Package Name of your app can be found and configured in the App Studio under the Build & Download > App Identifiers section. You can learn more about your package name in the App Identifiers documentation.

Register your Android app

Register your Android app

Once your app is registered you can download your google-services.json file. This configuration file will be used to configure your app in the App Configuration step.

Download the google-services.json configuration file

Download the google-services.json configuration file

🏁

Setup Complete

Once you download the configuration file the Google Firebase setup for Android is complete. You do not need to complete the remaining step of adding the Firebase SDK as this step is performed by our plugin.

iOS Setup

You can register your app in Firebase by providing the Apple Bundle ID. The Apple Bundle ID of your app can be found and configured in the App Studio under the Build & Download > App Identifiers section. You can learn more about your Bundle ID in the App Identifiers documentation.

Register your iOS app

Register your iOS app

Once your app is registered you can download your GoogleService-Info.plist file. This configuration file will be used to configure your app in the App Configuration step.

Download the GoogleService-Info.plist configuration file

Download the GoogleService-Info.plist configuration file

🏁

Setup Complete

Once you download the configuration file the Google Firebase setup for iOS is complete. You do not need to complete the remaining steps of adding the Firebase SDK and initialization code as those steps are performed by our plugin.

App Configuration

You mobile app can be configured to use Google Firebase Analytics by following the following two steps:

  1. Plugin Activation: Ensure that the plugin is enabled. You can check the status in the App Studio via Native Plugins > Google Firebase Analytics > Settings
  2. Consent Configuration: In the Plugin Settings configure your default consent value as one of the options below:
    1. Allow - Grant consent.
    2. Deny - Deny consent.
    3. Follow EU Consent Policy - Deny for users in regions subject to the EU User Consent Policy.
  3. Google Services Configuration: Ensure that the GoogleService-Info.plist (iOS) and google-services.json (Android) are set up in the Build & Download > Google Services setting. You can upload the files provided from Firebase directly in the App Studio referencing the example below. Alternatively, you can open the file and copy & paste its contents into the App Studio.
Upload your GoogleService-Info.plist and google-services.json configurations

Upload your GoogleService-Info.plist and google-services.json configurations

🏁

Finalizing the App Build

Once the configuration files are uploaded please ensure that you save the changes and rebuilt your app.

Implementation Guide

Consent Management

Configure the individual consent for ad storage, analytics storage, ad user data and ad personalization at runtime.

↔️Median JavaScript Bridge

median.firebaseAnalytics.event.setConsent({
  "adStorage": true|false,
  "analyticsStorage": true|false,
  "adUserData": true|false,
  "adPersonalization": true|false
});

Default Event Logging

By default, Firebase Analytics automatically logs key events such as:

  • first_open_time
  • session_start
  • screen_view

For a complete list of automatic events, refer to the Google Analytics documentation.

Advanced Event Logging with JavaScript Bridge

Use the Median JavaScript Bridge to log additional events for enhanced or customized analytics tracking.

Analytics Management

Enable/disable all event logging including "automatic" app events. Logging is enabled by default and thus an initial call would be to disable logging by setting to false. The effect of the function is persistent and once disabled logging can only be re-enabled by invoking the function again.

↔️Median JavaScript Bridge

median.firebaseAnalytics.event.collection({'enabled':BOOLEAN});

User Management

You can set customize the user ID for any given user (e.g. after a successful user login; as the user is no longer anonymous to you) by using the following JavaScript bridge command.

↔️Median JavaScript Bridge

median.firebaseAnalytics.event.setUser({'ID':STRING});

Additionally, you can use the method below to associate additional properties to the user.

↔️Median JavaScript Bridge

median.firebaseAnalytics.event.setUserProperty({'key':STRING, 'value':STRING});

Event Logging

The following method allows you to set default event parameters. Those parameters are logged alongside any other information for the log event command.

↔️Median JavaScript Bridge

median.firebaseAnalytics.event.defaultEventParameters(data);
//data is an object of key-value pairs converted into bundle params

You can log custom events by using the following JavaScript bridge command. The data object is flexible to accommodate any data you want to log.

↔️Median JavaScript Bridge

median.firebaseAnalytics.event.logEvent({
  'event':STRING, 
  'data': OBJECT
});
//called with the fixed screenClass="MainActivity"

You log a customized screen view event (in addition to the one logged by the default logging) by using the following JavaScript bridge command.

↔️Median JavaScript Bridge

median.firebaseAnalytics.event.logScreen({'screen':STRING});

eCommerce Events

🛒

eCommerce Events

Firebase offers a special command set that is tailored for ecommerce integrations. You can learn more about the commands in the Firebase Measure ecommerce documentation.

↔️Median JavaScript Bridge

Log item views

median.firebaseAnalytics.event.viewItem({'data':JsonProductItem, 'currency': STRING, 'price': FLOAT});
// JsonProductItem is an encoded map of ProductItem*
// currency is the 3-letter currency code in upper-case
// price is the cost per item in the given Currency

Log wishlist additions

median.firebaseAnalytics.event.addToWishlist({'data':JsonProductItem, 'currency': STRING, 'price': FLOAT, 'quantity': INTEGER});
// JsonProductItem is an encoded map of ProductItem*
// currency is the 3-letter currency code in upper-case
// price is the cost per item in the given Currency
// quantity is the count of the product. It multiplies the price for the total amount.

Log add to cart events

median.firebaseAnalytics.event.addToCart({'data':JsonProductItem, 'currency': STRING, 'price': FLOAT, 'quantity': INTEGER});
// JsonProductItem is an encoded map of ProductItem*
// currency is the 3-letter currency code in upper-case
// price is the cost per item in the given Currency
// quantity is the count of the product. It multiplies the price for the total amount.

Log remove from cart events

median.firebaseAnalytics.event.removeFromCart({'data':JsonProductItem, 'currency': STRING, 'price': FLOAT, 'quantity': INTEGER});
// JsonProductItem is an encoded map of ProductItem*
// currency is the 3-letter currency code in upper-case
// price is the cost per item in the given Currency
// quantity is the count of the product. It multiplies the price for the total amount.

*Note:
ProductItem may include the following fields. All fields are optional though it is recommended to provide at least an item_id or item_name.

String item_id
String item_name
String item_category
String item_variant
String item_brand
String item_list_name
String item_list_id
double price

Next Steps