Class FirebaseAnalyticsProvider
- All Implemented Interfaces:
AnalyticsProvider
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/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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe platform's connection to the native Firebase SDK. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetName()A short, stable, human readable name for this provider (used in logs and diagnostics).voidinit(AnalyticsContext context) Called once when the provider is registered with the facade, supplying ambient application context.static voidRegisters the platform bridge.voidreportCrash(AnalyticsCrashReport report) Reports a crash or handled exception.voidAssociates subsequent activity with a user identifier.voidsetUserProperty(String key, String value) Sets a user-level property / custom dimension.booleansupports(AnalyticsCapability capability) Indicates whether the provider supports a given capability.voidtrackEvent(AnalyticsEvent event) Records a named event.voidtrackScreen(String name, String referrer) Records a screen / page view.Methods inherited from class AbstractAnalyticsProvider
flush, getContext, onConsentChanged
-
Constructor Details
-
FirebaseAnalyticsProvider
public FirebaseAnalyticsProvider()
-
-
Method Details
-
registerBridge
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
Description copied from interface:AnalyticsProviderA short, stable, human readable name for this provider (used in logs and diagnostics).
Returns
the provider name
- Specified by:
getNamein interfaceAnalyticsProvider- Specified by:
getNamein classAbstractAnalyticsProvider
-
init
Description copied from interface:AnalyticsProviderCalled once when the provider is registered with the facade, supplying ambient application context.
Parameters
context: the analytics context
- Specified by:
initin interfaceAnalyticsProvider- Overrides:
initin classAbstractAnalyticsProvider
-
trackScreen
Description copied from interface:AnalyticsProviderRecords a screen / page view.
Parameters
-
name: the screen name -
referrer: the previous screen name, may be null
- Specified by:
trackScreenin interfaceAnalyticsProvider- Overrides:
trackScreenin classAbstractAnalyticsProvider
-
-
trackEvent
Description copied from interface:AnalyticsProviderRecords a named event.
Parameters
event: the event
- Specified by:
trackEventin interfaceAnalyticsProvider- Overrides:
trackEventin classAbstractAnalyticsProvider
-
setUserId
Description copied from interface:AnalyticsProviderAssociates subsequent activity with a user identifier.
Parameters
id: the user id, or null to clear
- Specified by:
setUserIdin interfaceAnalyticsProvider- Overrides:
setUserIdin classAbstractAnalyticsProvider
-
setUserProperty
Description copied from interface:AnalyticsProviderSets a user-level property / custom dimension.
Parameters
-
key: the property name -
value: the property value
- Specified by:
setUserPropertyin interfaceAnalyticsProvider- Overrides:
setUserPropertyin classAbstractAnalyticsProvider
-
-
reportCrash
Description copied from interface:AnalyticsProviderReports a crash or handled exception.
Parameters
report: the crash report
- Specified by:
reportCrashin interfaceAnalyticsProvider- Overrides:
reportCrashin classAbstractAnalyticsProvider
-
supports
Description copied from interface:AnalyticsProviderIndicates whether the provider supports a given capability.
Parameters
capability: the capability to query
Returns
true if supported
- Specified by:
supportsin interfaceAnalyticsProvider- Overrides:
supportsin classAbstractAnalyticsProvider
-