public class AnalyticsService

  1. Object
  2. AnalyticsService
Deprecated. use Analytics and an AnalyticsProvider

The legacy analytics entry point, retained for backward compatibility. New code should use the Analytics facade together with one or more AnalyticsProvider implementations, which adds a generic provider SPI, GDPR/CCPA consent handling and modern backends (GA4, Matomo, Firebase and the first-party Codename One service).

This class now delegates to Analytics: init(String, String) registers a GoogleAnalyticsProvider (Google Analytics 4, replacing the retired Measurement Protocol v1 that this class used to target) and visit(String, String) / sendCrashReport(Throwable, String, boolean) route through the facade.

To preserve the historical “always on” behaviour of this deprecated API – which predates the consent model – init(String, String) and init(AnalyticsService) switch the facade to ConsentMode.OPT_OUT. Applications that need opt-in / GDPR behaviour should migrate to the Analytics API and call Analytics.setConsent(AnalyticsConsent).

Constructors

public AnalyticsService()

Methods

public static boolean isFailSilently()Deprecated Indicates whether analytics server failures should brodcast an error event
public static void setFailSilently(boolean aFailSilently)Deprecated Indicates whether analytics server failures should brodcast an error event
public static boolean isAppsMode()Deprecated Apps mode allows improved analytics using the newer google analytics API designed for apps
public static void setAppsMode(boolean aAppsMode)Deprecated Apps mode allows improved analytics using the newer google analytics API designed for apps.
public static void setTimeout(int ms)Deprecated Retained for source compatibility; no longer affects behaviour.
public static void setReadTimeout(int ms)Deprecated Retained for source compatibility; no longer affects behaviour.
public static boolean isEnabled()Deprecated Indicates whether analytics is enabled for this application
public static void init(String agent, String domain)Deprecated Initializes analytics for this application using the modern Google Analytics 4 protocol.
public static void init(AnalyticsService i)Deprecated Allows installing an analytics service other than the default.
public static void visit(String page, String referer)Deprecated Sends an asynchronous notice to the server regarding a page in the application being viewed, notice that you don’t need to append the URL prefix to the page string.
public static void sendCrashReport(Throwable t, String message, boolean fatal)Deprecated Reports information about an exception to the analytics server.
protected boolean isAnalyticsEnabled()Indicates if the analytics is enabled, subclasses must override this method to process their information
protected void decorateVisitPageRequest(String page, String referer, ConnectionRequest request)Deprecated Retained for source compatibility with subclasses written against the previous Google Analytics v1 implementation.
protected void visitPage(String page, String referer)Subclasses may override this method to track page visits.

Inherited methods

Constructor details

AnalyticsService

public AnalyticsService()

Method details

isFailSilently

public static boolean isFailSilently()
Deprecated. use Analytics
Indicates whether analytics server failures should brodcast an error event

Returns

the failSilently

setFailSilently

public static void setFailSilently(boolean aFailSilently)
Deprecated. use Analytics
Indicates whether analytics server failures should brodcast an error event

Parameters

aFailSilently boolean
the failSilently to set

isAppsMode

public static boolean isAppsMode()
Deprecated. use Analytics
Apps mode allows improved analytics using the newer google analytics API designed for apps

Returns

the appsMode

setAppsMode

public static void setAppsMode(boolean aAppsMode)
Deprecated. use Analytics
Apps mode allows improved analytics using the newer google analytics API designed for apps. This setting is retained for source compatibility but no longer affects behaviour; the modern GA4 protocol is always used.

Parameters

aAppsMode boolean
the appsMode to set

setTimeout

public static void setTimeout(int ms)
Deprecated. use Analytics
Retained for source compatibility; no longer affects behaviour.

Parameters

ms int
Milliseconds timeout.

setReadTimeout

public static void setReadTimeout(int ms)
Deprecated. use Analytics
Retained for source compatibility; no longer affects behaviour.

Parameters

ms int
Milliseconds read timeout.

isEnabled

public static boolean isEnabled()
Deprecated. use Analytics
Indicates whether analytics is enabled for this application

Returns

true if analytics is enabled

init

public static void init(String agent, String domain)
Deprecated. use Analytics with a GoogleAnalyticsProvider
Initializes analytics for this application using the modern Google Analytics 4 protocol. The agent is used as the GA4 measurement id.

Parameters

agent String
the google analytics tracking agent / measurement id
domain String
a domain to represent your application, commonly your package name as a URL (e.g. com.mycompany.myapp should become: myapp.mycompany.com)

init

public static void init(AnalyticsService i)
Deprecated. use Analytics and a custom AnalyticsProvider
Allows installing an analytics service other than the default. The custom implementation’s visitPage hook is invoked for page views.

Parameters

i AnalyticsService
the analytics service implementation.

visit

public static void visit(String page, String referer)
Sends an asynchronous notice to the server regarding a page in the application being viewed, notice that you don’t need to append the URL prefix to the page string.

Parameters

page String
the page viewed
referer String
the source page

sendCrashReport

public static void sendCrashReport(Throwable t, String message, boolean fatal)
Reports information about an exception to the analytics server.

Parameters

t Throwable
the exception
message String
up to 150 character message,
fatal boolean
is the exception fatal

isAnalyticsEnabled

protected boolean isAnalyticsEnabled()
Indicates if the analytics is enabled, subclasses must override this method to process their information

Returns

true if analytics is enabled

decorateVisitPageRequest

protected void decorateVisitPageRequest(String page, String referer, ConnectionRequest request)
Deprecated. decorate the request inside a custom AnalyticsProvider
Retained for source compatibility with subclasses written against the previous Google Analytics v1 implementation. It is no longer invoked by the default page-view path, which now delegates to Analytics.

Parameters

page String
The page visited
referer String
The page from which the user came.
request ConnectionRequest
The ConnectionRequest

visitPage

protected void visitPage(String page, String referer)
Subclasses may override this method to track page visits. The default implementation routes the visit to the Analytics facade.

Parameters

page String
the page visited
referer String
the page from which the user came