Class GoogleAnalyticsTracker
java.lang.Object
org.vaadin.googleanalytics.tracking.GoogleAnalyticsTracker
- All Implemented Interfaces:
Serializable
Sends commands to Google Analytics in the browser. An instance of the tracker
can be retrieved from a given UI instance (
get(UI)) or for the
current UI instance (getCurrent()).
Page view commands will automatically be sent for any navigation if the tracker can be configured.
The first time any command is sent, the tracker will configure itself based
on the top-level router layout in the corresponding UI. The layout should be
annotated with @EnableGoogleAnalytics or implement
TrackerConfigurator for the configuration to succeed.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidga(String command, Map<String, Serializable> fieldsObject, Serializable... fields) Sends a generic command to Google Analytics.static GoogleAnalyticsTrackerget(com.vaadin.flow.component.UI ui) Gets or creates a tracker for the given UI.static GoogleAnalyticsTrackerGets or creates a tracker for the current UI.booleanChecks whether this tracker has been initialized.voidSends an event command with the given category and action.voidSends an event command with the given category, action and label.voidSends an event command with the given category, action, label and value.voidSends an event command with the given category, action and arbitrary additional fields.voidsendPageView(String location) Sends a page view command to Google Analytics.voidsendPageView(String location, Map<String, Serializable> fieldsObject) Sends a page view command with arbitrary additional fields to Google Analytics.
-
Method Details
-
getCurrent
Gets or creates a tracker for the current UI.- Returns:
- the tracker for the current UI, or
nullif there is no current UI - See Also:
-
get
Gets or creates a tracker for the given UI.- Parameters:
ui- the UI for which to get at tracker, notnull- Returns:
- the tracker for the given ui
-
ga
Sends a generic command to Google Analytics. This corresponds to a client-side call to thegafunction except that fieldsObject is not the last parameter because of the way varargs work in Java.- Parameters:
command- the name of the command to send, notnullfieldsObject- a map of additional fields, ornullto to not send any additional fieldsfields- a list of field values to send
-
sendPageView
Sends a page view command to Google Analytics.- Parameters:
location- the location of the viewed page, notnull
-
sendPageView
Sends a page view command with arbitrary additional fields to Google Analytics. See the reference documentation for more information about supported additional fields.- Parameters:
location- the location of the viewed page, notnullfieldsObject- map of additional fields to include in thesendcommand
-
sendEvent
Sends an event command with the given category and action. See the reference documentation for information about the semantics of the parameters.- Parameters:
groupId- the category name, notnulleventName- the action name, notnull
-
sendEvent
Sends an event command with the given category, action and label. See the reference documentation for information about the semantics of the parameters.- Parameters:
category- the category name, notnullaction- the action name, notnulllabel- the event label, notnull
-
sendEvent
Sends an event command with the given category, action, label and value. See the reference documentation for information about the semantics of the parameters.- Parameters:
category- the category name, notnullaction- the action name, notnulllabel- the event label, notnullvalue- the event value
-
sendEvent
Sends an event command with the given category, action and arbitrary additional fields. See the reference documentation for information about the semantics of the parameters.- Parameters:
category- the category name, notnullaction- the action name, notnullfieldsObject- field object
-
isInitialized
public boolean isInitialized()Checks whether this tracker has been initialized.- Returns:
trueif this tracker is initialized, otherwisefalse
-