Class GoogleAnalytics4Provider
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,AnalyticsProvider
AnalyticsProvider interface for Google Analytics 4 collect API.
General outline:
Events are queued and ordered by date. Events that share the same date within a configured time resolution, client ID
and user ID are batched together. The time resolution can be configured via setResolutionMillis(long).
A task is run regularly to flush pending events regardless of the queue size and can be configured with
setPollingIntervalMillis(long).
If a full batch can be sent after sendEvent(String, Date, Map) is invoked and no manual flush is currently
in-progress, a manual flush is scheduled. This will only flush a single batch of events.
When the bean is destroyed, all pending events are flushed.
- Author:
- poirigui
-
Constructor Summary
ConstructorsConstructorDescriptionGoogleAnalytics4Provider(String measurementId, String apiSecret) GoogleAnalytics4Provider(org.springframework.web.client.RestTemplate restTemplate, String measurementId, String apiSecret) Create a new Google Analytics 4 provider. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddestroy()voidPublish an event.voidsetClientIdRetrievalStrategy(ClientIdRetrievalStrategy clientIdRetrievalStrategy) Set the strategy used to retrieve client IDs.voidsetDebug(boolean debug) Enable the debug mode.voidsetPollingIntervalMillis(long pollingIntervalMillis) Interval at which events are polled and flushed.voidsetResolutionMillis(long resolutionMillis) Time resolution for regrouping events in the same batch.voidsetUserIdRetrievalStrategy(UserIdRetrievalStrategy userIdRetrievalStrategy) Set the strategy used to retrieve user IDs.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ubic.gemma.rest.analytics.AnalyticsProvider
sendEvent, sendEvent
-
Constructor Details
-
GoogleAnalytics4Provider
public GoogleAnalytics4Provider(org.springframework.web.client.RestTemplate restTemplate, String measurementId, String apiSecret) Create a new Google Analytics 4 provider.- Parameters:
restTemplate- a REST template for performing requests with the collect APImeasurementId- a measurement ID which may be emptyapiSecret- an API secret, must be non-empty if measurementId is supplied
-
GoogleAnalytics4Provider
- See Also:
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
setClientIdRetrievalStrategy
Set the strategy used to retrieve client IDs. -
setUserIdRetrievalStrategy
Set the strategy used to retrieve user IDs. -
setDebug
public void setDebug(boolean debug) Enable the debug mode.When debug mode is enabled, a testing GA4 endpoint will be used and
sendEvent(String, Date, Map)may raise exception instead of simply warning. -
setResolutionMillis
public void setResolutionMillis(long resolutionMillis) Time resolution for regrouping events in the same batch.Events with the same client and user IDs are batched together if they are less than the resolution apart and reported at the time the first event in the batch occurred.
Setting this to zero effectively disable batching of events unless they occur at exactly the same time. This can be achieved by reusing the
Dateobject when sending multiple events. -
setPollingIntervalMillis
public void setPollingIntervalMillis(long pollingIntervalMillis) Interval at which events are polled and flushed. -
sendEvent
Description copied from interface:AnalyticsProviderPublish an event.- Specified by:
sendEventin interfaceAnalyticsProvider- Parameters:
eventName- a name for the eventdate- an exact moment when the event occurredparams- additional parameters for the event
-