Interface AnalyticsProvider

All Known Implementing Classes:
AbstractAnalyticsProvider, CodenameOneAnalyticsProvider, FirebaseAnalyticsProvider, GoogleAnalyticsProvider, LegacyAnalyticsProviderAdapter, LoggingAnalyticsProvider, MatomoAnalyticsProvider

public interface AnalyticsProvider

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 Details

    • getName

      String getName()

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

      Returns

      the provider name

    • init

      void init(AnalyticsContext context)

      Called once when the provider is registered with the facade, supplying ambient application context.

      Parameters
      • context: the analytics context
    • trackScreen

      void trackScreen(String name, String referrer)

      Records a screen / page view.

      Parameters
      • name: the screen name

      • referrer: the previous screen name, may be null

    • trackEvent

      void trackEvent(AnalyticsEvent event)

      Records a named event.

      Parameters
      • event: the event
    • setUserId

      void setUserId(String id)

      Associates subsequent activity with a user identifier.

      Parameters
      • id: the user id, or null to clear
    • setUserProperty

      void setUserProperty(String key, String value)

      Sets a user-level property / custom dimension.

      Parameters
      • key: the property name

      • value: the property value

    • reportCrash

      void reportCrash(AnalyticsCrashReport report)

      Reports a crash or handled exception.

      Parameters
      • report: the crash report
    • onConsentChanged

      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: the new consent state
    • flush

      void flush()
      Flushes any buffered events to the backend.
    • supports

      boolean supports(AnalyticsCapability capability)

      Indicates whether the provider supports a given capability.

      Parameters
      • capability: the capability to query
      Returns

      true if supported