# Class AbstractAnalyticsProvider

java.lang.Object
com.codename1.analytics.AbstractAnalyticsProvider

All Implemented Interfaces:
  `AnalyticsProvider`

Direct Known Subclasses:
  `CodenameOneAnalyticsProvider, FirebaseAnalyticsProvider, GoogleAnalyticsProvider, LegacyAnalyticsProviderAdapter, LoggingAnalyticsProvider, MatomoAnalyticsProvider`

public abstract class AbstractAnalyticsProvider extends Object implements AnalyticsProvider
Convenience base class for `AnalyticsProvider` implementations. Every SPI method has an empty / no-op body so a concrete provider only overrides the calls it actually supports. The `AnalyticsContext` handed to `init(AnalyticsContext)` is retained and exposed via `getContext()`; `supports(AnalyticsCapability)` returns `false` for every capability and should be overridden.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractAnalyticsProvider()`

- ## Method Summary

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

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AbstractAnalyticsProvider

    public AbstractAnalyticsProvider()

- ## Method Details

  - ### getName

    public abstract String getName()
    Description copied from interface: `AnalyticsProvider`

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

    ###### Returns

    the provider name

    Specified by:
      `getName` in interface `AnalyticsProvider`

  - ### init

    public void init(AnalyticsContext context)
    Description copied from interface: `AnalyticsProvider`

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

    ###### Parameters

    - `context`: the analytics context
    Specified by:
      `init` in interface `AnalyticsProvider`

  - ### getContext

    protected AnalyticsContext getContext()

    The context supplied at `init(AnalyticsContext)` time.

    ###### Returns

    the context, or null if not yet initialised

  - ### trackScreen

    public void trackScreen(String name, String referrer)
    Description copied from interface: `AnalyticsProvider`

    Records a screen / page view.

    ###### Parameters

    - `name`: the screen name

    - `referrer`: the previous screen name, may be null

    Specified by:
      `trackScreen` in interface `AnalyticsProvider`

  - ### trackEvent

    public void trackEvent(AnalyticsEvent event)
    Description copied from interface: `AnalyticsProvider`

    Records a named event.

    ###### Parameters

    - `event`: the event
    Specified by:
      `trackEvent` in interface `AnalyticsProvider`

  - ### setUserId

    public void setUserId(String id)
    Description copied from interface: `AnalyticsProvider`

    Associates subsequent activity with a user identifier.

    ###### Parameters

    - `id`: the user id, or null to clear
    Specified by:
      `setUserId` in interface `AnalyticsProvider`

  - ### setUserProperty

    public void setUserProperty(String key, String value)
    Description copied from interface: `AnalyticsProvider`

    Sets a user-level property / custom dimension.

    ###### Parameters

    - `key`: the property name

    - `value`: the property value

    Specified by:
      `setUserProperty` in interface `AnalyticsProvider`

  - ### reportCrash

    public void reportCrash(AnalyticsCrashReport report)
    Description copied from interface: `AnalyticsProvider`

    Reports a crash or handled exception.

    ###### Parameters

    - `report`: the crash report
    Specified by:
      `reportCrash` in interface `AnalyticsProvider`

  - ### onConsentChanged

    public void onConsentChanged(AnalyticsConsent consent)
    Description copied from interface: `AnalyticsProvider`

    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
    Specified by:
      `onConsentChanged` in interface `AnalyticsProvider`

  - ### flush

    public void flush()
    Description copied from interface: `AnalyticsProvider`
    Flushes any buffered events to the backend.
    Specified by:
      `flush` in interface `AnalyticsProvider`

  - ### supports

    public boolean supports(AnalyticsCapability capability)
    Description copied from interface: `AnalyticsProvider`

    Indicates whether the provider supports a given capability.

    ###### Parameters

    - `capability`: the capability to query

    ###### Returns

    true if supported

    Specified by:
      `supports` in interface `AnalyticsProvider`