public class FirebaseAnalyticsProvider
- Object
- AbstractAnalyticsProvider
- 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/setUserPropertydirectly. Requiresgoogle-services.jsonand the Firebase Gradle plugin in the build. - iOS: a bridge whose methods are declared
nativeand implemented in Objective-C (FIRAnalytics). RequiresGoogleService-Info.plistand 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.Bridge | The 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)Parameters
bridgeFirebaseAnalyticsProvider.Bridge- the platform bridge, or null
getName
public String getName()Returns
init
public void init(AnalyticsContext context)Parameters
contextAnalyticsContext- the analytics context
trackScreen
public void trackScreen(String name, String referrer)Parameters
nameString- the screen name
referrerString- the previous screen name, may be null
trackEvent
public void trackEvent(AnalyticsEvent event)Parameters
eventAnalyticsEvent- the event
setUserId
public void setUserId(String id)Parameters
idString- the user id, or null to clear
setUserProperty
public void setUserProperty(String key, String value)Parameters
keyString- the property name
valueString- the property value
reportCrash
public void reportCrash(AnalyticsCrashReport report)Parameters
reportAnalyticsCrashReport- the crash report
supports
public boolean supports(AnalyticsCapability capability)Parameters
capabilityAnalyticsCapability- the capability to query