com.brsanthu.googleanalytics.request.GoogleAnalyticsRequest Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.brsanthu.googleanalytics.request;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.ADWORDS_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.ANONYMIZE_IP;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.APPLICATION_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.APPLICATION_INSTALLER_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.APPLICATION_NAME;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.APPLICATION_VERSION;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CACHE_BUSTER;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CAMPAIGN_CONTENT;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CAMPAIGN_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CAMPAIGN_KEYWORD;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CAMPAIGN_MEDIUM;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CAMPAIGN_NAME;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CAMPAIGN_SOURCE;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CLIENT_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.CONTENT_DESCRIPTION;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DATA_SOURCE;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DISPLAY_ADS_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DOCUMENT_ENCODING;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DOCUMENT_HOST_NAME;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DOCUMENT_PATH;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DOCUMENT_REFERRER;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DOCUMENT_TITLE;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.DOCUMENT_URL;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.EXPERIMENT_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.EXPERIMENT_VARIANT;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.FLASH_VERSION;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.HIT_TYPE;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.JAVA_ENABLED;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.NON_INTERACTION_HIT;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.PROTOCOL_VERSION;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.QUEUE_TIME;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.SCREEN_COLORS;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.SCREEN_RESOLUTION;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.SESSION_CONTROL;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.TRACKING_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.USER_ID;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.USER_LANGUAGE;
import static com.brsanthu.googleanalytics.request.GoogleAnalyticsParameter.VIEWPORT_SIZE;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.function.Supplier;
import com.brsanthu.googleanalytics.GoogleAnalyticsExecutor;
import com.brsanthu.googleanalytics.internal.Constants;
import com.brsanthu.googleanalytics.internal.GaUtils;
/**
* Base GA Tracking Request containing the standard and custom parameter values.
*
*
* It also provides type safe getter/setters for all parameters that are applicable for all hit types. Hit specific
* setters/getters are available in corresponding Hit specific request objects (like {@link EventHit} or
* {@link PageViewHit} etc)
*
* @author Santhosh Kumar
*/
@SuppressWarnings("unchecked")
public class GoogleAnalyticsRequest {
protected Map parms = new HashMap();
protected Map customDimensions = new HashMap();
protected Map customMetrics = new HashMap();
protected GoogleAnalyticsExecutor delegateExecutor = null;
public GoogleAnalyticsRequest() {
this(null, null, null, null);
}
public GoogleAnalyticsRequest(String hitType) {
this(hitType, null, null, null);
}
public GoogleAnalyticsRequest(String hitType, String trackingId, String appName, String appVersion) {
hitType(GaUtils.isBlank(hitType) ? Constants.HIT_PAGEVIEW : hitType);
trackingId(trackingId);
applicationName(appName);
applicationVersion(appVersion);
protocolVersion("1");
}
/**
* Sets the String value for specified parameter. If value is null, the parameter is removed from the parameters
* list.
*
* @param parameter
* @param value
* @return
*/
protected T setString(GoogleAnalyticsParameter parameter, String value) {
if (value == null) {
parms.remove(parameter);
} else {
String stringValue = value;
parms.put(parameter, stringValue);
}
return (T) this;
}
protected String getString(GoogleAnalyticsParameter parameter) {
return parms.get(parameter);
}
protected T setInteger(GoogleAnalyticsParameter parameter, Integer value) {
if (value == null) {
parms.remove(parameter);
} else {
String stringValue = fromInteger(value);
parms.put(parameter, stringValue);
}
return (T) this;
}
protected Double getDouble(GoogleAnalyticsParameter parameter) {
return toDouble(parms.get(parameter));
}
protected T setDouble(GoogleAnalyticsParameter parameter, Double value) {
if (value == null) {
parms.remove(parameter);
} else {
String stringValue = fromDouble(value);
parms.put(parameter, stringValue);
}
return (T) this;
}
protected Boolean getBoolean(GoogleAnalyticsParameter parameter) {
return toBoolean(parms.get(parameter));
}
protected T setBoolean(GoogleAnalyticsParameter parameter, Boolean value) {
if (value == null) {
parms.remove(parameter);
} else {
String stringValue = fromBoolean(value);
parms.put(parameter, stringValue);
}
return (T) this;
}
protected Integer getInteger(GoogleAnalyticsParameter parameter) {
return toInteger(parms.get(parameter));
}
protected String fromBoolean(Boolean booleanString) {
if (booleanString == null) {
return null;
}
return "" + booleanString;
}
protected Boolean toBoolean(String booleanString) {
if (GaUtils.isBlank(booleanString)) {
return null;
}
return new Boolean(booleanString).booleanValue();
}
protected String fromInteger(Integer intValue) {
if (intValue == null) {
return null;
}
return "" + intValue;
}
protected Integer toInteger(String intString) {
if (GaUtils.isBlank(intString)) {
return null;
}
return Integer.parseInt(intString);
}
protected String fromDouble(Double doubleValue) {
if (doubleValue == null) {
return null;
}
return "" + doubleValue;
}
protected Double toDouble(String doubleString) {
if (GaUtils.isBlank(doubleString)) {
return null;
}
return Double.parseDouble(doubleString);
}
protected T parameter(GoogleAnalyticsParameter parameter, String value) {
if (value == null) {
parms.remove(parameter);
} else {
parms.put(parameter, value);
}
return (T) this;
}
protected String parameter(GoogleAnalyticsParameter parameter) {
return parms.get(parameter);
}
public Map getParameters() {
return parms;
}
public String customDimension(int index) {
return customDimensions.get("cd" + index);
}
/**
*
*
* Optional.
*
*
* Each custom dimension has an associated index. There is a maximum of 20 custom dimensions (200 for Premium
* accounts). The name suffix must be a positive integer between 1 and 200, inclusive.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cd[1-9][0-9]*
* text
* None
* 150 Bytes
* all
*
*
*
* Example value: Sports
* Example usage: cd[1-9][0-9]*=Sports
*/
public T customDimension(int index, String value) {
customDimensions.put("cd" + index, value);
return (T) this;
}
/**
*
*
* Optional.
*
*
* Each custom metric has an associated index. There is a maximum of 20 custom metrics (200 for Premium accounts).
* The name suffix must be a positive integer between 1 and 200, inclusive.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cm[1-9][0-9]*
* integer
* None
* None
* all
*
*
*
* Example value: 47
* Example usage: cm[1-9][0-9]*=47
*/
public T customMetric(int index, String value) {
customMetrics.put("cm" + index, value);
return (T) this;
}
public String customMetric(int index) {
return customMetrics.get("cm" + index);
}
public Map customDimensions() {
return customDimensions;
}
public Map custommMetrics() {
return customMetrics;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Request [");
if (parms != null) {
builder.append("parms=");
builder.append(parms);
builder.append(", ");
}
if (customDimensions != null) {
builder.append("customDimensions=");
builder.append(customDimensions);
builder.append(", ");
}
if (customMetrics != null) {
builder.append("customMetrics=");
builder.append(customMetrics);
}
builder.append("]");
return builder.toString();
}
/**
*
*
* Required for all hit types.
*
*
* The Protocol version. The current value is '1'. This will only change when there are changes made that are not
* backwards compatible.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* v
* text
* None
* None
* all
*
*
*
* Example value: 1
* Example usage: v=1
*/
public T protocolVersion(String value) {
setString(PROTOCOL_VERSION, value);
return (T) this;
}
public String protocolVersion() {
return getString(PROTOCOL_VERSION);
}
/**
*
*
* Required for all hit types.
*
*
* The tracking ID / web property ID. The format is UA-XXXX-Y. All collected data is associated by this ID.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* tid
* text
* None
* None
* all
*
*
*
* Example value: UA-XXXX-Y
* Example usage: tid=UA-XXXX-Y
*/
public T trackingId(String value) {
setString(TRACKING_ID, value);
return (T) this;
}
public String trackingId() {
return getString(TRACKING_ID);
}
/**
*
*
* Optional.
*
*
* When present, the IP address of the sender will be anonymized. For example, the IP will be anonymized if any of
* the following parameters are present in the payload: &aip=, &aip=0, or &aip=1
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* aip
* boolean
* None
* None
* all
*
*
*
* Example value: 1
* Example usage: aip=1
*/
public T anonymizeIp(Boolean value) {
setBoolean(ANONYMIZE_IP, value);
return (T) this;
}
public Boolean anonymizeIp() {
return getBoolean(ANONYMIZE_IP);
}
/**
*
*
* Optional.
*
*
* Indicates the data source of the hit. Hits sent from analytics.js will have data source set to 'web'; hits sent
* from one of the mobile SDKs will have data source set to 'app'.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ds
* text
* None
* None
* all
*
*
*
* Example value: web
* Example usage: ds=web
*
* Example value: app
* Example usage: ds=app
*
* Example value: call center
* Example usage: ds=call%20center
*
* Example value: crm
* Example usage: ds=crm
*/
public T dataSource(String value) {
setString(DATA_SOURCE, value);
return (T) this;
}
public String dataSource() {
return getString(DATA_SOURCE);
}
/**
*
*
* Optional.
*
*
* Used to collect offline / latent hits. The value represents the time delta (in milliseconds) between when the hit
* being reported occurred and the time the hit was sent. The value must be greater than or equal to 0. Values
* greater than four hours may lead to hits not being processed.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* qt
* integer
* None
* None
* all
*
*
*
* Example value: 560
* Example usage: qt=560
*/
public T queueTime(Integer value) {
setInteger(QUEUE_TIME, value);
return (T) this;
}
public Integer queueTime() {
return getInteger(QUEUE_TIME);
}
/**
*
*
* Optional.
*
*
* Used to send a random number in GET requests to ensure browsers and proxies don't cache hits. It should be sent
* as the final parameter of the request since we've seen some 3rd party internet filtering software add additional
* parameters to HTTP requests incorrectly. This value is not used in reporting.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* z
* text
* None
* None
* all
*
*
*
* Example value: 289372387623
* Example usage: z=289372387623
*/
public T cacheBuster(String value) {
setString(CACHE_BUSTER, value);
return (T) this;
}
public String cacheBuster() {
return getString(CACHE_BUSTER);
}
/**
*
*
* Required for all hit types.
*
*
* This anonymously identifies a particular user, device, or browser instance. For the web, this is generally stored
* as a first-party cookie with a two-year expiration. For mobile apps, this is randomly generated for each
* particular instance of an application install. The value of this field should be a random UUID (version 4) as
* described in http://www.ietf.org/rfc/rfc4122.txt
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cid
* text
* None
* None
* all
*
*
*
* Example value: 35009a79-1a05-49d7-b876-2b884d0f825b
* Example usage: cid=35009a79-1a05-49d7-b876-2b884d0f825b
*/
public T clientId(String value) {
setString(CLIENT_ID, value);
return (T) this;
}
public String clientId() {
return getString(CLIENT_ID);
}
/**
* Optional.
*
* This is intended to be a known identifier for a user provided by the site owner/tracking library user. It may not
* itself be PII. The value should never be persisted in GA cookies or other Analytics provided storage.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* uid
* text
* None
* None
* all
*
*
*
*
*
* Example value: as8eknlll
* Example usage: uid=as8eknlll
*
*
*
*
* @param value
* @return
*/
public T userId(String value) {
setString(USER_ID, value);
return (T) this;
}
public String userId() {
return getString(USER_ID);
}
/**
*
*
* Optional.
*
*
* Used to control the session duration. A value of 'start' forces a new session to start with this hit and 'end'
* forces the current session to end with this hit. All other values are ignored.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* sc
* text
* None
* None
* all
*
*
*
* Example value: start
* Example usage: sc=start
* Example value: end
* Example usage: sc=end
*/
public T sessionControl(String value) {
setString(SESSION_CONTROL, value);
return (T) this;
}
public String sessionControl() {
return getString(SESSION_CONTROL);
}
/**
*
*
* Optional.
*
*
* Specifies which referral source brought traffic to a website. This value is also used to compute the traffic
* source. The format of this value is a URL.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* dr
* text
* None
* 2048 Bytes
* all
*
*
*
* Example value: http://example.com
* Example usage: dr=http%3A%2F%2Fexample.com
*/
public T documentReferrer(String value) {
setString(DOCUMENT_REFERRER, value);
return (T) this;
}
public String documentReferrer() {
return getString(DOCUMENT_REFERRER);
}
/**
*
*
* Optional.
*
*
* Specifies the campaign name.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cn
* text
* None
* 100 Bytes
* all
*
*
*
* Example value: (direct)
* Example usage: cn=%28direct%29
*/
public T campaignName(String value) {
setString(CAMPAIGN_NAME, value);
return (T) this;
}
public String campaignName() {
return getString(CAMPAIGN_NAME);
}
/**
*
*
* Optional.
*
*
* Specifies the campaign source.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cs
* text
* None
* 100 Bytes
* all
*
*
*
* Example value: (direct)
* Example usage: cs=%28direct%29
*/
public T campaignSource(String value) {
setString(CAMPAIGN_SOURCE, value);
return (T) this;
}
public String campaignSource() {
return getString(CAMPAIGN_SOURCE);
}
/**
*
*
* Optional.
*
*
* Specifies the campaign medium.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cm
* text
* None
* 50 Bytes
* all
*
*
*
* Example value: organic
* Example usage: cm=organic
*/
public T campaignMedium(String value) {
setString(CAMPAIGN_MEDIUM, value);
return (T) this;
}
public String campaignMedium() {
return getString(CAMPAIGN_MEDIUM);
}
/**
*
*
* Optional.
*
*
* Specifies the campaign keyword.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ck
* text
* None
* 500 Bytes
* all
*
*
*
* Example value: Blue Shoes
* Example usage: ck=Blue%20Shoes
*/
public T campaignKeyword(String value) {
setString(CAMPAIGN_KEYWORD, value);
return (T) this;
}
public String campaignKeyword() {
return getString(CAMPAIGN_KEYWORD);
}
/**
*
*
* Optional.
*
*
* Specifies the campaign content.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cc
* text
* None
* 500 Bytes
* all
*
*
*
* Example value: content
* Example usage: cc=content
*/
public T campaignContent(String value) {
setString(CAMPAIGN_CONTENT, value);
return (T) this;
}
public String campaignContent() {
return getString(CAMPAIGN_CONTENT);
}
/**
*
*
* Optional.
*
*
* Specifies the campaign ID.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ci
* text
* None
* 100 Bytes
* all
*
*
*
* Example value: ID
* Example usage: ci=ID
*/
public T campaignId(String value) {
setString(CAMPAIGN_ID, value);
return (T) this;
}
public String campaignId() {
return getString(CAMPAIGN_ID);
}
/**
*
*
* Optional.
*
*
* Specifies the Google AdWords Id.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* gclid
* text
* None
* None
* all
*
*
*
* Example value: CL6Q-OXyqKUCFcgK2goddQuoHg
* Example usage: gclid=CL6Q-OXyqKUCFcgK2goddQuoHg
*/
public T adwordsId(String value) {
setString(ADWORDS_ID, value);
return (T) this;
}
public String adwordsId() {
return getString(ADWORDS_ID);
}
/**
*
*
* Optional.
*
*
* Specifies the Google Display Ads Id.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* dclid
* text
* None
* None
* all
*
*
*
* Example value: d_click_id
* Example usage: dclid=d_click_id
*/
public T displayadId(String value) {
setString(DISPLAY_ADS_ID, value);
return (T) this;
}
public String displayadId() {
return getString(DISPLAY_ADS_ID);
}
/**
*
*
* Optional.
*
*
* Specifies the screen resolution.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* sr
* text
* None
* 20 Bytes
* all
*
*
*
* Example value: 800x600
* Example usage: sr=800x600
*/
public T screenResolution(String value) {
setString(SCREEN_RESOLUTION, value);
return (T) this;
}
public String screenResolution() {
return getString(SCREEN_RESOLUTION);
}
/**
*
*
* Optional.
*
*
* Specifies the viewable area of the browser / device.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* vp
* text
* None
* 20 Bytes
* all
*
*
*
* Example value: 123x456
* Example usage: vp=123x456
*/
public T viewportSize(String value) {
setString(VIEWPORT_SIZE, value);
return (T) this;
}
public String viewportSize() {
return getString(VIEWPORT_SIZE);
}
/**
*
*
* Optional.
*
*
* Specifies the character set used to encode the page / document.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* de
* text
* UTF-8
* 20 Bytes
* all
*
*
*
* Example value: UTF-8
* Example usage: de=UTF-8
*/
public T documentEncoding(String value) {
setString(DOCUMENT_ENCODING, value);
return (T) this;
}
public String documentEncoding() {
return getString(DOCUMENT_ENCODING);
}
/**
*
*
* Optional.
*
*
* Specifies the screen color depth.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* sd
* text
* None
* 20 Bytes
* all
*
*
*
* Example value: 24-bits
* Example usage: sd=24-bits
*/
public T screenColors(String value) {
setString(SCREEN_COLORS, value);
return (T) this;
}
public String screenColors() {
return getString(SCREEN_COLORS);
}
/**
*
*
* Optional.
*
*
* Specifies the language.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ul
* text
* None
* 20 Bytes
* all
*
*
*
* Example value: en-us
* Example usage: ul=en-us
*/
public T userLanguage(String value) {
setString(USER_LANGUAGE, value);
return (T) this;
}
public String userLanguage() {
return getString(USER_LANGUAGE);
}
/**
*
*
* Optional.
*
*
* Specifies whether Java was enabled.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* je
* boolean
* None
* None
* all
*
*
*
* Example value: 1
* Example usage: je=1
*/
public T javaEnabled(Boolean value) {
setBoolean(JAVA_ENABLED, value);
return (T) this;
}
public Boolean javaEnabled() {
return getBoolean(JAVA_ENABLED);
}
/**
*
*
* Optional.
*
*
* Specifies the flash version.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* fl
* text
* None
* 20 Bytes
* all
*
*
*
* Example value: 10 1 r103
* Example usage: fl=10%201%20r103
*/
public T flashVersion(String value) {
setString(FLASH_VERSION, value);
return (T) this;
}
public String flashVersion() {
return getString(FLASH_VERSION);
}
/**
*
*
* Required for all hit types.
*
*
* The type of hit. Must be one of 'pageview', 'appview', 'event', 'transaction', 'item', 'social', 'exception',
* 'timing'.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* t
* text
* None
* None
* all
*
*
*
* Example value: pageview
* Example usage: t=pageview
*/
public T hitType(String value) {
setString(HIT_TYPE, value);
return (T) this;
}
public String hitType() {
return getString(HIT_TYPE);
}
/**
*
*
* Optional.
*
*
* Specifies that a hit be considered non-interactive.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ni
* boolean
* None
* None
* all
*
*
*
* Example value: 1
* Example usage: ni=1
*/
public T nonInteractionHit(String value) {
setString(NON_INTERACTION_HIT, value);
return (T) this;
}
public String nonInteractionHit() {
return getString(NON_INTERACTION_HIT);
}
/**
*
*
* Optional.
*
*
* Use this parameter to send the full URL (document location) of the page on which content resides. You can use the
* &dh and &dp parameters to override the hostname and path + query portions of the document location,
* accordingly. The JavaScript clients determine this parameter using the concatenation of the
* document.location.origin + document.location.pathname + document.location.search browser parameters. Be sure to
* remove any user authentication or other private information from the URL if present.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* dl
* text
* None
* 2048 Bytes
* all
*
*
*
* Example value: http://foo.com/home?a=b
* Example usage: dl=http%3A%2F%2Ffoo.com%2Fhome%3Fa%3Db
*/
public T documentUrl(String value) {
setString(DOCUMENT_URL, value);
return (T) this;
}
public String documentUrl() {
return getString(DOCUMENT_URL);
}
/**
*
*
* Optional.
*
*
* Specifies the hostname from which content was hosted.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* dh
* text
* None
* 100 Bytes
* all
*
*
*
* Example value: foo.com
* Example usage: dh=foo.com
*/
public T documentHostName(String value) {
setString(DOCUMENT_HOST_NAME, value);
return (T) this;
}
public String documentHostName() {
return getString(DOCUMENT_HOST_NAME);
}
/**
*
*
* Optional.
*
*
* The path portion of the page URL. Should begin with '/'.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* dp
* text
* None
* 2048 Bytes
* all
*
*
*
* Example value: /foo
* Example usage: dp=%2Ffoo
*/
public T documentPath(String value) {
setString(DOCUMENT_PATH, value);
return (T) this;
}
public String documentPath() {
return getString(DOCUMENT_PATH);
}
/**
*
*
* Optional.
*
*
* The title of the page / document.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* dt
* text
* None
* 1500 Bytes
* all
*
*
*
* Example value: Settings
* Example usage: dt=Settings
*/
public T documentTitle(String value) {
setString(DOCUMENT_TITLE, value);
return (T) this;
}
public String documentTitle() {
return getString(DOCUMENT_TITLE);
}
/**
*
*
* Optional.
*
*
* If not specified, this will default to the unique URL of the page by either using the &dl parameter as-is or
* assembling it from &dh and &dp. App tracking makes use of this for the 'Screen Name' of the appview hit.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cd
* text
* None
* 2048 Bytes
* all
*
*
*
* Example value: High Scores
* Example usage: cd=High%20Scores
*/
public T contentDescription(String value) {
setString(CONTENT_DESCRIPTION, value);
return (T) this;
}
public String contentDescription() {
return getString(CONTENT_DESCRIPTION);
}
/**
*
*
* Optional.
*
*
* Specifies the application name. Only visible in app views (profiles).
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* an
* text
* None
* 100 Bytes
* all
*
*
*
* Example value: My App
* Example usage: an=My%20App
*/
public T applicationName(String value) {
setString(APPLICATION_NAME, value);
return (T) this;
}
public String applicationName() {
return getString(APPLICATION_NAME);
}
/**
*
*
* Optional.
*
*
* Specifies the application installer identifier Only visible in app views (profiles).
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* aiid
* text
* None
* 150 Bytes
* all
*
*
*
* Example value: com.platform.vending
* Example usage: aiid=com.platform.vending
*/
public T applicationInstallerId(String value) {
setString(APPLICATION_INSTALLER_ID, value);
return (T) this;
}
public String applicationInstallerId() {
return getString(APPLICATION_INSTALLER_ID);
}
/**
*
*
* Optional.
*
*
* Specifies the application version. Only visible in app views (profiles).
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* av
* text
* None
* 100 Bytes
* all
*
*
*
* Example value: 1.2
* Example usage: av=1.2
*/
public T applicationVersion(String value) {
setString(APPLICATION_VERSION, value);
return (T) this;
}
public String applicationVersion() {
return getString(APPLICATION_VERSION);
}
/**
*
*
* Optional.
*
*
* Specifies the application identifier. Only visible in app views (profiles).
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* aid
* text
* None
* 150 Bytes
* all
*
*
*
* Example value: com.company.app
* Example usage: aid=com.company.app
*/
public T applicationId(String value) {
setString(APPLICATION_ID, value);
return (T) this;
}
public String applicationId() {
return getString(APPLICATION_ID);
}
/**
*
*
* Optional.
*
*
*
* This parameter specifies that this visitor has been exposed to an experiment with the given ID. It should be sent
* in conjunction with the Experiment Variant parameter.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* xid
* text
* None
* 40 Bytes
* all
*
*
*
*
*
* Example value: Qp0gahJ3RAO3DJ18b0XoUQ
* Example usage: xid=Qp0gahJ3RAO3DJ18b0XoUQ
*/
public T experimentId(String value) {
setString(EXPERIMENT_ID, value);
return (T) this;
}
public String experimentId() {
return getString(EXPERIMENT_ID);
}
/**
*
*
* Optional.
*
*
*
* This parameter specifies that this visitor has been exposed to a particular variation of an experiment. It should
* be sent in conjunction with the Experiment ID parameter.
*
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* xvar
* text
* None
* None
* all
*
*
*
*
* Example value: 1
* Example usage: xvar=1
*/
public T experimentVariant(String value) {
setString(EXPERIMENT_VARIANT, value);
return (T) this;
}
public String experimentVariant() {
return getString(EXPERIMENT_VARIANT);
}
/**
* IP Override parameter: uip Should be a valid IP address. This will always be anonymized just as though &aip
* (anonymize IP) had been used. example: &uip=1.2.3.4
*/
public T userIp(String value) {
setString(GoogleAnalyticsParameter.USER_IP, value);
return (T) this;
}
public String userIp() {
return getString(GoogleAnalyticsParameter.USER_IP);
}
/**
* User Agent Override parameter: &ua Should be a User Agent reported by the browser. Note: We have libraries to
* identify real user agents. Hand crafting your own agent could break at any time. example:
* &ua=Opera%2F9.80%20(Windows%20NT%206.0)%20Presto%2F2.12.388%20Version%2F12.14
*/
public T userAgent(String value) {
setString(GoogleAnalyticsParameter.USER_AGENT, value);
return (T) this;
}
public String userAgent() {
return getString(GoogleAnalyticsParameter.USER_AGENT);
}
/**
* GeoId Override parameter: geoid The geographical ID should be a two letter country code or a criteria ID
* representing a city or region example: geoid=US
*/
public T geoid(String value) {
setString(GoogleAnalyticsParameter.GEOID, value);
return (T) this;
}
public String geoid() {
return getString(GoogleAnalyticsParameter.GEOID);
}
public GoogleAnalyticsResponse send() {
return execute(() -> delegateExecutor.post(this));
}
public Future sendAsync() {
return execute(() -> delegateExecutor.postAsync(this));
}
private E execute(Supplier call) {
if (delegateExecutor == null) {
throw new RuntimeException("GoogleAnalyticsExecutor is null");
}
return call.get();
}
public GoogleAnalyticsRequest setExecutor(GoogleAnalyticsExecutor delegateExecutor) {
this.delegateExecutor = delegateExecutor;
return this;
}
}