public class GoogleAnalyticsTracker extends Object
get(UI)
) or for the
current UI instance (getCurrent()
).
Page view commands will automatically be sent for any Flow 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.
Modifier and Type | Method and Description |
---|---|
void |
ga(String command,
Map<String,? extends Serializable> fieldsObject,
Serializable... fields)
Sends a generic command to Google Analytics.
|
static GoogleAnalyticsTracker |
get(com.vaadin.flow.component.UI ui)
Gets or creates a tracker for the given UI.
|
static GoogleAnalyticsTracker |
getCurrent()
Gets or creates a tracker for the current UI.
|
boolean |
isInitialized()
Checks whether this tracker has been initialized.
|
void |
sendEvent(String category,
String action)
Sends an event command with the given category and action.
|
void |
sendEvent(String category,
String action,
Map<String,Serializable> fieldsObject)
Sends an event command with the given category, action and arbitrary
additional fields.
|
void |
sendEvent(String category,
String action,
String label)
Sends an event command with the given category, action and label.
|
void |
sendEvent(String category,
String action,
String label,
int value)
Sends an event command with the given category, action, label and value.
|
void |
sendPageView(String location)
Sends a page view command to Google Analytics.
|
void |
sendPageView(String location,
Map<String,Serializable> fieldsObject)
Sends a page view command with arbitrary additional fields to Google
Analytics.
|
public static GoogleAnalyticsTracker getCurrent()
null
if there is
no current UIUI.getCurrent()
public static GoogleAnalyticsTracker get(com.vaadin.flow.component.UI ui)
ui
- the UI for which to get at tracker, not null
public void ga(String command, Map<String,? extends Serializable> fieldsObject, Serializable... fields)
ga
function except that fieldsObject
is not the last parameter because of the way varargs work in Java.command
- the name of the command to send, not null
fieldsObject
- a map of additional fields, or null
to to not
send any additional fieldsfields
- a list of field values to sendpublic void sendPageView(String location)
location
- the location of the viewed page, not null
public void sendPageView(String location, Map<String,Serializable> fieldsObject)
location
- the location of the viewed page, not null
fieldsObject
- map of additional fields to include in the send
commandpublic void sendEvent(String category, String action)
category
- the category name, not null
action
- the action name, not null
public void sendEvent(String category, String action, String label)
category
- the category name, not null
action
- the action name, not null
label
- the event label, not null
public void sendEvent(String category, String action, String label, int value)
category
- the category name, not null
action
- the action name, not null
label
- the event label, not null
value
- the event valuepublic void sendEvent(String category, String action, Map<String,Serializable> fieldsObject)
category
- the category name, not null
action
- the action name, not null
fieldsObject
- field objectpublic boolean isInitialized()
true
if this tracker is initialized, otherwise
false
Copyright © 2023 Sami Ekblad. All rights reserved.