public class AnalyticsService
- Object
- AnalyticsService
Analytics and an AnalyticsProviderThe 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()AnalyticsReturns
setFailSilently
public static void setFailSilently(boolean aFailSilently)AnalyticsParameters
aFailSilentlyboolean- the failSilently to set
isAppsMode
public static boolean isAppsMode()AnalyticsReturns
setAppsMode
public static void setAppsMode(boolean aAppsMode)AnalyticsParameters
aAppsModeboolean- the appsMode to set
setTimeout
public static void setTimeout(int ms)AnalyticsParameters
msint- Milliseconds timeout.
setReadTimeout
public static void setReadTimeout(int ms)AnalyticsParameters
msint- Milliseconds read timeout.
isEnabled
public static boolean isEnabled()AnalyticsReturns
init
public static void init(String agent, String domain)Analytics with a GoogleAnalyticsProvideragent is used as the GA4 measurement id.Parameters
agentString- the google analytics tracking agent / measurement id
domainString- 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)Analytics and a custom AnalyticsProvidervisitPage hook is invoked for page views.Parameters
iAnalyticsService- the analytics service implementation.
visit
public static void visit(String page, String referer)Analytics.screen(String, String)Parameters
pageString- the page viewed
refererString- the source page
sendCrashReport
public static void sendCrashReport(Throwable t, String message, boolean fatal)Analytics.crash(Throwable, String, boolean)Parameters
tThrowable- the exception
messageString- up to 150 character message,
fatalboolean- is the exception fatal
isAnalyticsEnabled
protected boolean isAnalyticsEnabled()Returns
decorateVisitPageRequest
protected void decorateVisitPageRequest(String page, String referer, ConnectionRequest request)AnalyticsProviderAnalytics.Parameters
pageString- The page visited
refererString- The page from which the user came.
requestConnectionRequest- The ConnectionRequest
visitPage
protected void visitPage(String page, String referer)Analytics facade.Parameters
pageString- the page visited
refererString- the page from which the user came