Class TrackerConfiguration

java.lang.Object
org.vaadin.googleanalytics.tracking.TrackerConfiguration

public class TrackerConfiguration extends Object
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 Details

  • Method Details

    • getTrackingId

      public String getTrackingId()
      Gets the Google Analytics tracking ID to use.
      Returns:
      the tracking id, not null
    • setTrackingId

      public TrackerConfiguration setTrackingId(String trackingId)
      Sets the Google Analytics tracking ID to use.
      Parameters:
      trackingId - the tracking id to use, not null and not an empty string
      Returns:
      this configuration, for chaining
      See Also:
    • getCookieDomain

      @Deprecated public String 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 public TrackerConfiguration setCookieDomain(String cookieDomain)
      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, or null to restore the default value.
      Returns:
      this configuration, for chaining
      See Also:
    • setPageViewPrefix

      public TrackerConfiguration setPageViewPrefix(String pageViewPrefix)
      Sets a prefix that will be added to the location of all tracked page views.
      Parameters:
      pageViewPrefix - a page view prefix to use, not null
      Returns:
      this configuration, for chaining
    • getPageViewPrefix

      public String getPageViewPrefix()
      Gets the current page view prefix.
      Returns:
      the current page view prefix, not null
    • setScriptUrl

      public TrackerConfiguration setScriptUrl(String scriptUrl)
      Sets the URL from which to load the Google Analytics script.
      Parameters:
      scriptUrl - the script URL to use, not null
      Returns:
      this configuration, for chaining
    • getScriptUrl

      public String getScriptUrl()
      Gets the URL from which to load the Google Analytics script.
      Returns:
      scriptUrl
    • setCreateField

      public TrackerConfiguration setCreateField(String name, Serializable value)
      Sets a custom field value to use when creating the client-side tracker.
      Parameters:
      name - the name of the field to set, not null
      value - the field value
      Returns:
      this configuration, for chaining
      See Also:
    • removeCreateField

      public TrackerConfiguration removeCreateField(String name)
      Removes a create field value.
      Parameters:
      name - the name of the field, not null
      Returns:
      this configuration, for chaining
      See Also:
    • setInitialValue

      public TrackerConfiguration setInitialValue(String name, Serializable value)
      Sets a value that will be included in an initial set command.
      Parameters:
      name - the name of the value, not null
      value - the value to set
      Returns:
      this configuration, for chaining
    • removeInitialValue

      public TrackerConfiguration removeInitialValue(String name)
      Removes an initial value.
      Parameters:
      name - the name of the value, not null
      Returns:
      this configuration, for chaining
      See Also:
    • setGaDebug

      public TrackerConfiguration setGaDebug(String name, Serializable value)
      Adds an entry that should be assigned to the ga_debug variable when the client-side tracker is initialized.
      Parameters:
      name - the parameter name, not null
      value - the value
      Returns:
      this configuration, for chaining
    • removeGaDebug

      public TrackerConfiguration removeGaDebug(String name)
      Removes a debug parameter value.
      Parameters:
      name - the parameter name, not null
      Returns:
      this configuration, for chaining
      See Also:
    • getCreateFields

      public Map<String, Serializable> 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

      public Map<String, Serializable> 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

      public Map<String, Serializable> getGaDebug()
      Gets the ga_debug values 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, not null
      sendHits - 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 use
      productionMode - whether to configure for production mode
      Returns:
      a newly created tracker configuration, not null