Class GoogleAnalyticsProvider

java.lang.Object
com.codename1.analytics.AbstractAnalyticsProvider
com.codename1.analytics.GoogleAnalyticsProvider
All Implemented Interfaces:
AnalyticsProvider

public class GoogleAnalyticsProvider extends AbstractAnalyticsProvider

A provider for Google Analytics 4 using the Measurement Protocol (v2). This replaces the retired Universal Analytics / Measurement Protocol v1 endpoint that the legacy AnalyticsService targeted.

Create one with a GA4 measurement id (G-XXXXXXXX) and a Measurement Protocol API secret generated in the GA4 admin console:

Analytics.addProvider(new GoogleAnalyticsProvider("G-XXXXXXXX", "MY_API_SECRET"));

Screen views are sent as the GA4 screen_view event, custom events use the (sanitised) event name, and crashes are reported as app_exception. IP addresses are anonymised by GA4 by default. Consent is enforced upstream by Analytics, so this provider sends whatever it is handed.