> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Firebase Analytics

> Track user behavior in your app with Google Firebase Analytics: consent, user properties, custom events, screen views, and e-commerce events.

Google Firebase Analytics provides 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.

## Why use Google Firebase Analytics?

* **Real-time insights**: User behavior tracking and integration with other Firebase services.
* **Essential metrics**: ARPU, active users, retention, event counts, device type, app version, OS version.
* **Consent management**: Configure ad storage, analytics storage, ad user data, and ad personalization at runtime.
* **JavaScript Bridge**: Enable/disable logging, set user ID and properties, log custom events and screen views, and use e-commerce events.

## Prerequisites

* [ ] A Median app with the JavaScript Bridge enabled
* [ ] A Google Firebase project ([Firebase Console](https://firebase.google.com/docs/android/setup))
* [ ] Android Package Name (from Median App Studio > Build & Deploy > App Identifiers) for Android
* [ ] Apple Bundle ID (from App Studio > Build & Deploy > App Identifiers) for iOS
* [ ] `google-services.json` (Android) and `GoogleService-Info.plist` (iOS) from Firebase after app registration
* [ ] Plugin enabled in App Studio (Native Plugins > Google Firebase Analytics)

> [!TIP]
>
> **Test  with our demo page**
>
> We host a ready-made demo page at
>
> that calls the  features through the Median JavaScript Bridge.
> Load it inside your Median app during development, either by setting it
> as your app's website URL in App Studio or by navigating to it from your
> own site, and use it to confirm  works on a real device before
> you add it to your own pages.
>
> The demo page only works inside a Median app with  enabled.
> Opened in a regular mobile or desktop browser, the native features
> won't respond. Remember to switch your app back to your own URL before
> release.

## Implementation guide

### 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](https://firebase.google.com/docs/android/setup).

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

![Firebase Project Overview screen with iOS and Android app options](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/46ef6fb8d46545a2932510d97dc46948e6842e4dd7116335c9e7b44aaf89956e-image.png?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=cf669cadd23cb3dadcb396581415e537)

Google Firebase project overview

### Register your Android app in Firebase

Provide the Android Package Name (found in Median App Studio under Build & Deploy > App Identifiers). See [App identifiers](https://docs.median.co/docs/app-identifiers.md).

![Register your Android app](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/a021258f82c253d383e2c581ba9e3e4f8e95b187335a72c05786edaf8fa21f1f-image.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=fb901f52be76233ef4cd6217467a963d)

Once registered, download `google-services.json` for the App Configuration step. You do not need to add the Firebase SDK manually; the plugin performs that step.

![Download the google-services.json configuration file](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/d53334aad2a9b9e48dc0a5f626170b2fefe0107fb535c3d7a541c6b9b1fbe21c-image.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=3f97cf8ce706590f6bbd3648bf2409ce)

### Register your iOS app in Firebase

Provide the Apple Bundle ID (found in App Studio under Build & Deploy > App Identifiers). See [App identifiers](https://docs.median.co/docs/app-identifiers.md).

![Register your iOS app](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/671bb9f6ec99ef90911d38732eddd9109b6cf5fade2aee0d619942b52adc7fb2-image.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=32b671d22aca6cc2aca3d1c6265e986d)

Once registered, download `GoogleService-Info.plist` for the App Configuration step. You do not need to add the Firebase SDK or initialization code; the plugin performs those steps.

![Download the GoogleService-Info.plist configuration file](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/febb23bbeaa07a30a5006d3eb6c44c8f76acf440b7de2e46ff14d720ddf4e136-image.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=87b91a6900ac233dee57f95a3a6d573c)

### Enable the plugin

1. **Google Services configuration**: Upload GoogleService-Info.plist (iOS) and google-services.json (Android) in Build & Deploy > Google Services in App Studio. You can upload files from Firebase or copy and paste their contents.
2. **Consent configuration**: In Plugin Settings, set your default consent value: **Follow EU Consent Policy** (deny for users in regions subject to the EU User Consent Policy), **Deny** (deny consent), or **Allow** (grant consent).
3. **Plugin activation**: Enable the plugin in App Studio via Native Plugins > Google Firebase Analytics > Settings.

#### Finalizing the app build

Once you upload the configuration files, save the changes and rebuild your app.

![Upload your GoogleService-Info.plist and google-services.json configurations](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/673adab78087bd5a5039f6da1ecab94c9b409bde8d0b665e064586218b4a35ff-analytics.gif?s=090fff4304eff74b85f9a76d2ae5c78c)

> [!TIP]
>
> **Use your AI agent**
>
> Use the Median MCP with your AI agent to enable Firebase Analytics and add your Firebase configuration files to your mobile app. See
> [Median MCP server](https://docs.median.co/docs/mcp-server.md) to set it up.

### JavaScript Bridge functions

#### Consent management

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

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseAnalytics.event.setConsent({
  adStorage: true | false,
  analyticsStorage: true | false,
  adUserData: true | false,
  adPersonalization: true | false,
});
```

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| Consent object | `object` | Yes | Boolean keys: `adStorage`, `analyticsStorage`, `adUserData`, `adPersonalization` |

#### Analytics management

Enable or disable all event logging (including automatic app events). Logging is enabled by default. Effect is persistent; once disabled, re-enable by calling again with `true`.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseAnalytics.event.collection({ enabled: BOOLEAN });
```

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `enabled` | `boolean` | Yes | Wrapped in `{ enabled: ... }` |

#### User management

Set a custom user ID (for example, after sign-in when the user is no longer anonymous).

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseAnalytics.event.setUser({ ID: STRING });
```

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `ID` | `string` | Yes | Passed as `'ID'` on the object |

#### Set user property

Associate additional properties with the user.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseAnalytics.event.setUserProperty({ key: STRING, value: STRING });
```

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `key` / `value` | `string` | Yes | Property name and value |

#### Event logging

Set default event parameters logged alongside other information for log event.

Median JavaScript Bridge

```javascript JavaScript theme={null}
// data is an object of key-value pairs converted into bundle params
median.firebaseAnalytics.event.defaultEventParameters(data);
```

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `data` | `object` | Yes | Key-value pairs |

#### Log event

Log a custom event. The `data` object is flexible.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseAnalytics.event.logEvent({ event: STRING, data: OBJECT });
```

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `event` | `string` | Yes | Event name |
| `data` | `object` | No | Arbitrary event payload |

#### Log screen

Log a customized screen view event (in addition to default logging).

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.firebaseAnalytics.event.logScreen({ screen: STRING });
```

**Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `screen` | `string` | Yes | Screen name |

### E-commerce events

Firebase offers a special command set that is tailored for e-commerce integrations. You can learn more about the commands in the [Firebase Measure e-commerce documentation](https://firebase.google.com/docs/analytics/measure-ecommerce).

Log item views

Median JavaScript Bridge

```javascript JavaScript theme={null}
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 JavaScript Bridge

```javascript JavaScript theme={null}
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 JavaScript Bridge

```javascript JavaScript theme={null}
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 JavaScript Bridge

```javascript JavaScript theme={null}
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`.

```java ProductItem theme={null}
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
```

## Default event logging

By default, Firebase Analytics automatically logs key events such as `screen_view`, `session_start`, and `first_open_time`. For a complete list of automatic events, see [Google Analytics documentation](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/analytics/FirebaseAnalytics.Event).

## Testing checklist

**Basic functionality**

* [ ] Plugin is enabled in App Studio (`Native Plugins > Google Firebase Analytics > Settings`)
* [ ] `google-services.json` (Android) and `GoogleService-Info.plist` (iOS) are uploaded in `Build & Deploy > Google Services`
* [ ] App rebuilt after configuration changes
* [ ] Firebase Analytics initializes without JavaScript Bridge errors

**Platform testing**

* [ ] `median.firebaseAnalytics.event.setConsent(...)` behaves as expected for your test scenario
* [ ] `median.firebaseAnalytics.event.collection({'enabled': false})` then `true` changes logging behavior

**Configuration testing**

* [ ] Default consent option in Plugin Settings matches your policy (`Follow EU Consent Policy`, `Deny`, or `Allow`)
* [ ] `setUser`, `setUserProperty`, `logEvent`, `logScreen`, and e-commerce calls appear in Firebase Analytics as expected

**User experience**

* [ ] Consent and analytics behavior align with your privacy disclosures
* [ ] Custom events and screen views do not block core web flows

## Troubleshooting

### Firebase Analytics functions are undefined or not working

Enable the JavaScript Bridge in App Studio, then call Firebase methods after the `median_library_ready()` event. In App Studio (`Native Plugins > Google Firebase Analytics`), confirm the plugin is enabled and that `GoogleService-Info.plist` (iOS) and `google-services.json` (Android) are uploaded under `Build & Deploy > Google Services`. Save and rebuild after configuration changes.

### Custom events are not appearing in Firebase Analytics

Verify event collection is enabled with `median.firebaseAnalytics.event.collection({'enabled': true})`. Then trigger a known test event, for example `median.firebaseAnalytics.event.logEvent({'event': 'test_event', 'data': {...}})`, and confirm your app build includes the latest plugin and Google Services configuration files.

### Consent behavior does not match the selected policy

Check the default consent option in Plugin Settings (`Follow EU Consent Policy`, `Deny`, or `Allow`) and confirm you are not overriding it unexpectedly at runtime. If you call `setConsent`, verify each key (`adStorage`, `analyticsStorage`, `adUserData`, `adPersonalization`) is set to the intended boolean value.

### User ID or user properties are missing from analytics data

Set the user ID only after the user is authenticated using `median.firebaseAnalytics.event.setUser({'ID': 'your_user_id'})`, then apply properties with `setUserProperty`. Trigger a follow-up event after those calls so the updated identity and properties are attached to event data.

### E-commerce events are incomplete or rejected

Confirm your e-commerce payload includes valid `currency` (3-letter uppercase code), numeric `price`, and `quantity` where required. For `data`, include a valid ProductItem map and provide at least `item_id` or `item_name` to improve event quality and reporting reliability.

> [!NOTE]
>
> **Still having trouble?**
>
> For Firebase Analytics behavior outside Median’s bridge, refer to the [Google Firebase Analytics documentation](https://firebase.google.com/docs/analytics).


## Related topics

- [Analytics](https://docs.median.co/docs/analytics.md)
- [Detecting app usage](https://docs.median.co/docs/detecting-app-usage.md)
- [App marketing and growth](https://docs.median.co/docs/app-marketing-growth.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.