# Class FirebaseAnalyticsProvider

java.lang.Object
com.codename1.analytics.AbstractAnalyticsProvider
com.codename1.analytics.FirebaseAnalyticsProvider

All Implemented Interfaces:
  `AnalyticsProvider`

public class FirebaseAnalyticsProvider extends AbstractAnalyticsProvider

A provider that forwards analytics to the native Firebase Analytics SDK. On Android and iOS, with Firebase configured in the build, events flow to the Firebase console. Where no native implementation is wired (the simulator, the desktop build, or a build without Firebase set up) the provider degrades silently to a no-op, so it is always safe to register:

    Analytics.addProvider(new FirebaseAnalyticsProvider());

#### How the native call is wired

Unlike a `NativeInterface` (which exists for the build server to generate per-app native peers), this provider talks to the platform through a small `FirebaseAnalyticsProvider.Bridge`. The Codename One build supplies the concrete bridge for the target and registers it via `registerBridge(Bridge)` before the app starts:

- Android: a bridge that calls `FirebaseAnalytics.getInstance(context).logEvent(...)` / `setUserId` / `setUserProperty` directly. Requires `google-services.json` and the Firebase Gradle plugin in the build.
- iOS: a bridge whose methods are declared `native` and implemented in Objective-C (`FIRAnalytics`). Requires `GoogleService-Info.plist` and the Firebase pods.
- Everything else (simulator, desktop): no bridge is registered, so the provider is a no-op.

Firebase is enabled with the `codename1.arg.android.firebaseAnalytics` / `codename1.arg.ios.firebaseAnalytics` build hints, which is what makes the build register the bridge.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `FirebaseAnalyticsProvider.Bridge`
  The platform's connection to the native Firebase SDK.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FirebaseAnalyticsProvider()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getName()`
  A short, stable, human readable name for this provider (used in logs and diagnostics).
  `void`
  `init(AnalyticsContext context)`
  Called once when the provider is registered with the facade, supplying ambient application context.
  `static void`
  `registerBridge(FirebaseAnalyticsProvider.Bridge bridge)`
  Registers the platform bridge.
  `void`
  `reportCrash(AnalyticsCrashReport report)`
  Reports a crash or handled exception.
  `void`
  `setUserId(String id)`
  Associates subsequent activity with a user identifier.
  `void`
  `setUserProperty(String key, String value)`
  Sets a user-level property / custom dimension.
  `boolean`
  `supports(AnalyticsCapability capability)`
  Indicates whether the provider supports a given capability.
  `void`
  `trackEvent(AnalyticsEvent event)`
  Records a named event.
  `void`
  `trackScreen(String name, String referrer)`
  Records a screen / page view.

  ### Methods inherited from class AbstractAnalyticsProvider

  `flush, getContext, onConsentChanged`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### FirebaseAnalyticsProvider

    public FirebaseAnalyticsProvider()

- ## Method Details

  - ### registerBridge

    public static void registerBridge(FirebaseAnalyticsProvider.Bridge bridge)

    Registers the platform bridge. Called by the Codename One build for a Firebase-enabled Android / iOS target; never called by application code. Passing null clears the registration (the provider becomes a no-op).

    ###### Parameters

    - `bridge`: the platform bridge, or null

  - ### getName

    public String getName()
    Description copied from interface: `AnalyticsProvider`

    A short, stable, human readable name for this provider (used in logs and diagnostics).

    ###### Returns

    the provider name

    Specified by:
      `getName` in interface `AnalyticsProvider`
    Specified by:
      `getName` in class `AbstractAnalyticsProvider`

  - ### init

    public void init(AnalyticsContext context)
    Description copied from interface: `AnalyticsProvider`

    Called once when the provider is registered with the facade, supplying ambient application context.

    ###### Parameters

    - `context`: the analytics context
    Specified by:
      `init` in interface `AnalyticsProvider`
    Overrides:
      `init` in class `AbstractAnalyticsProvider`

  - ### trackScreen

    public void trackScreen(String name, String referrer)
    Description copied from interface: `AnalyticsProvider`

    Records a screen / page view.

    ###### Parameters

    - `name`: the screen name

    - `referrer`: the previous screen name, may be null

    Specified by:
      `trackScreen` in interface `AnalyticsProvider`
    Overrides:
      `trackScreen` in class `AbstractAnalyticsProvider`

  - ### trackEvent

    public void trackEvent(AnalyticsEvent event)
    Description copied from interface: `AnalyticsProvider`

    Records a named event.

    ###### Parameters

    - `event`: the event
    Specified by:
      `trackEvent` in interface `AnalyticsProvider`
    Overrides:
      `trackEvent` in class `AbstractAnalyticsProvider`

  - ### setUserId

    public void setUserId(String id)
    Description copied from interface: `AnalyticsProvider`

    Associates subsequent activity with a user identifier.

    ###### Parameters

    - `id`: the user id, or null to clear
    Specified by:
      `setUserId` in interface `AnalyticsProvider`
    Overrides:
      `setUserId` in class `AbstractAnalyticsProvider`

  - ### setUserProperty

    public void setUserProperty(String key, String value)
    Description copied from interface: `AnalyticsProvider`

    Sets a user-level property / custom dimension.

    ###### Parameters

    - `key`: the property name

    - `value`: the property value

    Specified by:
      `setUserProperty` in interface `AnalyticsProvider`
    Overrides:
      `setUserProperty` in class `AbstractAnalyticsProvider`

  - ### reportCrash

    public void reportCrash(AnalyticsCrashReport report)
    Description copied from interface: `AnalyticsProvider`

    Reports a crash or handled exception.

    ###### Parameters

    - `report`: the crash report
    Specified by:
      `reportCrash` in interface `AnalyticsProvider`
    Overrides:
      `reportCrash` in class `AbstractAnalyticsProvider`

  - ### supports

    public boolean supports(AnalyticsCapability capability)
    Description copied from interface: `AnalyticsProvider`

    Indicates whether the provider supports a given capability.

    ###### Parameters

    - `capability`: the capability to query

    ###### Returns

    true if supported

    Specified by:
      `supports` in interface `AnalyticsProvider`
    Overrides:
      `supports` in class `AbstractAnalyticsProvider`