public interface AnalyticsProvider

Known subtypesAbstractAnalyticsProvider, 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.

Methods

public abstract String getName()A short, stable, human readable name for this provider (used in logs and diagnostics).
public abstract void init(AnalyticsContext context)Called once when the provider is registered with the facade, supplying ambient application context.
public abstract void trackScreen(String name, String referrer)Records a screen / page view.
public abstract void trackEvent(AnalyticsEvent event)Records a named event.
public abstract void setUserId(String id)Associates subsequent activity with a user identifier.
public abstract void setUserProperty(String key, String value)Sets a user-level property / custom dimension.
public abstract void reportCrash(AnalyticsCrashReport report)Reports a crash or handled exception.
public abstract void onConsentChanged(AnalyticsConsent consent)Notifies the provider that the user’s consent has changed so it can enable, disable or reconfigure collection accordingly.
public abstract void flush()Flushes any buffered events to the backend.
public abstract boolean supports(AnalyticsCapability capability)Indicates whether the provider supports a given capability.

Method details

getName

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

Returns

the provider name

init

public abstract 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 abstract 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 abstract void trackEvent(AnalyticsEvent event)
Records a named event.

Parameters

event AnalyticsEvent
the event

setUserId

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

Parameters

id String
the user id, or null to clear

setUserProperty

public abstract 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 abstract void reportCrash(AnalyticsCrashReport report)
Reports a crash or handled exception.

Parameters

report AnalyticsCrashReport
the crash report

onConsentChanged

public abstract void onConsentChanged(AnalyticsConsent consent)
Notifies the provider that the user’s consent has changed so it can enable, disable or reconfigure collection accordingly.

Parameters

consent AnalyticsConsent
the new consent state

flush

public abstract void flush()
Flushes any buffered events to the backend.

supports

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

Parameters

capability AnalyticsCapability
the capability to query

Returns

true if supported