Class TrackerConfiguration
java.lang.Object
org.vaadin.googleanalytics.tracking.TrackerConfiguration
Configuration for a Google Analytics tracker. By default, the configuration
is created based on an @
EnableGoogleAnalytics annotation on the
application's outermost router layout class. The layout class can also
implement TrackerConfigurator to declaratively update the
configuration.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic TrackerConfigurationcreate(EnableGoogleAnalytics.LogLevel logLevel, boolean sendHits) Creates a tracker configuration with default settings based on a log level and whether to actually enable sending commands to Google Analytics.static TrackerConfigurationfromAnnotation(EnableGoogleAnalytics annotation, boolean productionMode) Creates a tracker configuration based on annotation values.Deprecated.In GA4 it is recommended to configure cookie domains through admin interface.Gets all the custom fields to pass when creating the client-side tracker.Gets thega_debugvalues to use when creating a clients-side tracker.Gets the initial value to set after creating a client-side tracker.Gets the current page view prefix.Gets the URL from which to load the Google Analytics script.Gets the Google Analytics tracking ID to use.removeCreateField(String name) Removes a create field value.removeGaDebug(String name) Removes a debug parameter value.removeInitialValue(String name) Removes an initial value.setCookieDomain(String cookieDomain) Deprecated.In GA4 it is recommended to configure cookie domains through admin interface.setCreateField(String name, Serializable value) Sets a custom field value to use when creating the client-side tracker.setGaDebug(String name, Serializable value) Adds an entry that should be assigned to thega_debugvariable when the client-side tracker is initialized.setInitialValue(String name, Serializable value) Sets a value that will be included in an initialsetcommand.setPageViewPrefix(String pageViewPrefix) Sets a prefix that will be added to the location of all tracked page views.setScriptUrl(String scriptUrl) Sets the URL from which to load the Google Analytics script.setTrackingId(String trackingId) Sets the Google Analytics tracking ID to use.
-
Field Details
-
DEFAULT_COOKIE_DOMAIN
-
-
Method Details
-
getTrackingId
Gets the Google Analytics tracking ID to use.- Returns:
- the tracking id, not
null
-
setTrackingId
Sets the Google Analytics tracking ID to use.- Parameters:
trackingId- the tracking id to use, notnulland not an empty string- Returns:
- this configuration, for chaining
- See Also:
-
getCookieDomain
Deprecated.In GA4 it is recommended to configure cookie domains through admin interface.Gets the cookie domain setting.- Returns:
- the cookie domain setting, not
null
-
setCookieDomain
Deprecated.In GA4 it is recommended to configure cookie domains through admin interface.Sets the cookie domain value to use.- Parameters:
cookieDomain- the cookie domain value to set, ornullto restore the default value.- Returns:
- this configuration, for chaining
- See Also:
-
setPageViewPrefix
Sets a prefix that will be added to the location of all tracked page views.- Parameters:
pageViewPrefix- a page view prefix to use, notnull- Returns:
- this configuration, for chaining
-
getPageViewPrefix
Gets the current page view prefix.- Returns:
- the current page view prefix, not
null
-
setScriptUrl
Sets the URL from which to load the Google Analytics script.- Parameters:
scriptUrl- the script URL to use, notnull- Returns:
- this configuration, for chaining
-
getScriptUrl
Gets the URL from which to load the Google Analytics script.- Returns:
- scriptUrl
-
setCreateField
Sets a custom field value to use when creating the client-side tracker.- Parameters:
name- the name of the field to set, notnullvalue- the field value- Returns:
- this configuration, for chaining
- See Also:
-
removeCreateField
Removes a create field value.- Parameters:
name- the name of the field, notnull- Returns:
- this configuration, for chaining
- See Also:
-
setInitialValue
Sets a value that will be included in an initialsetcommand.- Parameters:
name- the name of the value, notnullvalue- the value to set- Returns:
- this configuration, for chaining
-
removeInitialValue
Removes an initial value.- Parameters:
name- the name of the value, notnull- Returns:
- this configuration, for chaining
- See Also:
-
setGaDebug
Adds an entry that should be assigned to thega_debugvariable when the client-side tracker is initialized.- Parameters:
name- the parameter name, notnullvalue- the value- Returns:
- this configuration, for chaining
-
removeGaDebug
Removes a debug parameter value.- Parameters:
name- the parameter name, notnull- Returns:
- this configuration, for chaining
- See Also:
-
getCreateFields
Gets all the custom fields to pass when creating the client-side tracker.- Returns:
- an unmodifiable map of parameter values, not
null - See Also:
-
getInitialValues
Gets the initial value to set after creating a client-side tracker.- Returns:
- an unmodifiable map of initial values, not
null - See Also:
-
getGaDebug
Gets thega_debugvalues to use when creating a clients-side tracker.- Returns:
- an unmodifiable map of debug settings, not
null - See Also:
-
create
public static TrackerConfiguration create(EnableGoogleAnalytics.LogLevel logLevel, boolean sendHits) Creates a tracker configuration with default settings based on a log level and whether to actually enable sending commands to Google Analytics.- Parameters:
logLevel- the log level to use, notnullsendHits- whether to send commands to Google Analytics- Returns:
- a newly created tracker configuration, not
null
-
fromAnnotation
public static TrackerConfiguration fromAnnotation(EnableGoogleAnalytics annotation, boolean productionMode) Creates a tracker configuration based on annotation values.- Parameters:
annotation- the configuration annotation to useproductionMode- whether to configure for production mode- Returns:
- a newly created tracker configuration, not
null
-