# Class CodenameOneAnalyticsProvider

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

All Implemented Interfaces:
  `AnalyticsProvider`

public class CodenameOneAnalyticsProvider extends AbstractAnalyticsProvider

The Codename One first-party analytics provider. It batches events and posts them as JSON to the Codename One cloud (`/api/v2/analytics/events`), where they are stored and aggregated for the reports shown in the developer console. The capabilities you actually get (screen views, custom events, retention window, raw export) are gated server-side by your subscription tier.

App identity is read from the build-injected `Display` properties (`build_key`, `package_name`, `AppName`, `AppVersion`, `OSVer`) -- the same mechanism the on-device crash client uses -- so no API key needs to be embedded in the app. Events are buffered in memory and flushed when the batch fills up or when `flush()` is called.

    Analytics.addProvider(new CodenameOneAnalyticsProvider());
    Analytics.setConsent(AnalyticsConsent.granted());

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CodenameOneAnalyticsProvider()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `flush()`
  Flushes any buffered events to the backend.
  `String`
  `getName()`
  A short, stable, human readable name for this provider (used in logs and diagnostics).
  `void`
  `reportCrash(AnalyticsCrashReport report)`
  Reports a crash or handled exception.
  `void`
  `setBatchSize(int size)`
  Sets the number of events buffered before an automatic flush.
  `void`
  `setEndpoint(String url)`
  Overrides the ingest endpoint URL.
  `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 AbstractAnalyticsProvider

  `getContext, init, onConsentChanged, setUserId`

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### CodenameOneAnalyticsProvider

    public CodenameOneAnalyticsProvider()

- ## Method Details

  - ### setEndpoint

    public void setEndpoint(String url)

    Overrides the ingest endpoint URL. By default the provider posts to the Codename One cloud (honouring the `cloudServerURL` display property).

    ###### Parameters

    - `url`: the full ingest URL

  - ### setBatchSize

    public void setBatchSize(int size)

    Sets the number of events buffered before an automatic flush.

    ###### Parameters

    - `size`: the batch size, values below 1 are clamped to 1

  - ### getName

    public 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`
    Specified by:
      `getName` in class `AbstractAnalyticsProvider`

  - ### 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`
    Overrides:
      `trackScreen` in class `AbstractAnalyticsProvider`

  - ### 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`
    Overrides:
      `trackEvent` in class `AbstractAnalyticsProvider`

  - ### 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`
    Overrides:
      `setUserProperty` in class `AbstractAnalyticsProvider`

  - ### 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`
    Overrides:
      `reportCrash` in class `AbstractAnalyticsProvider`

  - ### flush

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

  - ### 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`
    Overrides:
      `supports` in class `AbstractAnalyticsProvider`