public class FirebaseAnalyticsProvider

  1. Object
  2. AbstractAnalyticsProvider
  3. FirebaseAnalyticsProvider

ImplementsAnalyticsProvider

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 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 types

interface FirebaseAnalyticsProvider.BridgeThe platform’s connection to the native Firebase SDK.

Constructors

public FirebaseAnalyticsProvider()

Methods

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

Inherited methods

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 FirebaseAnalyticsProvider.Bridge
the platform bridge, or null

getName

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

Returns

the provider name

init

public void init(AnalyticsContext context)
Called once when the provider is registered with the facade, supplying ambient application context.

Parameters

context AnalyticsContext
the analytics context

trackScreen

public void trackScreen(String name, String referrer)
Records a screen / page view.

Parameters

name String
the screen name
referrer String
the previous screen name, may be null

trackEvent

public void trackEvent(AnalyticsEvent event)
Records a named event.

Parameters

event AnalyticsEvent
the event

setUserId

public void setUserId(String id)
Associates subsequent activity with a user identifier.

Parameters

id String
the user id, or null to clear

setUserProperty

public void setUserProperty(String key, String value)
Sets a user-level property / custom dimension.

Parameters

key String
the property name
value String
the property value

reportCrash

public void reportCrash(AnalyticsCrashReport report)
Reports a crash or handled exception.

Parameters

report AnalyticsCrashReport
the crash report

supports

public boolean supports(AnalyticsCapability capability)
Indicates whether the provider supports a given capability.

Parameters

capability AnalyticsCapability
the capability to query

Returns

true if supported