Interface AnalyticsProvider
- All Known Implementing Classes:
AbstractAnalyticsProvider, CodenameOneAnalyticsProvider, FirebaseAnalyticsProvider, GoogleAnalyticsProvider, LegacyAnalyticsProviderAdapter, LoggingAnalyticsProvider, MatomoAnalyticsProvider
The analytics service provider interface (SPI). Implement this to plug an
analytics backend into the Analytics facade. Several providers can
be registered at once; the facade fans every call out to all of them after
the relevant consent has been satisfied.
Providers are registered by explicit instantiation
(Analytics.addProvider(new MyProvider())) -- no reflection or service
lookup is used, which keeps the mechanism safe under the obfuscation applied
to shipped builds. Most implementations should extend
AbstractAnalyticsProvider and override only the calls they support.
-
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Flushes any buffered events to the backend.getName()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.voidonConsentChanged(AnalyticsConsent consent) Notifies the provider that the user's consent has changed so it can enable, disable or reconfigure collection accordingly.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.
-
Method Details
-
getName
String getName()A short, stable, human readable name for this provider (used in logs and diagnostics).
Returns
the provider name
-
init
Called once when the provider is registered with the facade, supplying ambient application context.
Parameters
context: the analytics context
-
trackScreen
-
trackEvent
Records a named event.
Parameters
event: the event
-
setUserId
Associates subsequent activity with a user identifier.
Parameters
id: the user id, or null to clear
-
setUserProperty
-
reportCrash
Reports a crash or handled exception.
Parameters
report: the crash report
-
onConsentChanged
Notifies the provider that the user's consent has changed so it can enable, disable or reconfigure collection accordingly.
Parameters
consent: the new consent state
-
flush
void flush()Flushes any buffered events to the backend. -
supports
Indicates whether the provider supports a given capability.
Parameters
capability: the capability to query
Returns
true if supported
-