com.brsanthu.googleanalytics.DefaultRequest Maven / Gradle / Ivy
Show all versions of google-analytics-java Show documentation
/*
* 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;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.CURRENCY_CODE;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.DNS_TIME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.EVENT_ACTION;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.EVENT_CATEGORY;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.EVENT_LABEL;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.EVENT_VALUE;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.EXCEPTION_DESCRIPTION;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.EXCEPTION_FATAL;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.ITEM_CATEGORY;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.ITEM_CODE;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.ITEM_NAME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.ITEM_PRICE;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.ITEM_QUANTITY;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.PAGE_DOWNLOAD_TIME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.PAGE_LOAD_TIME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.REDIRECT_RESPONSE_TIME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.SERVER_RESPONSE_TIME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.SOCIAL_ACTION;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.SOCIAL_ACTION_TARGET;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.SOCIAL_NETWORK;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.TCP_CONNECT_TIME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.TRANSACTION_AFFILIATION;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.TRANSACTION_ID;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.TRANSACTION_REVENUE;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.TRANSACTION_SHIPPING;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.TRANSACTION_TAX;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.USER_TIMING_CATEGORY;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.USER_TIMING_LABEL;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.USER_TIMING_TIME;
import static com.brsanthu.googleanalytics.GoogleAnalyticsParameter.USER_TIMING_VARIABLE_NAME;
import java.util.UUID;
/**
* Default request that captures default value for any of the parameters. Create an instance of
* this object and specify as constructor parameter to {@link GoogleAnalytics} or set one any time using
* {@link GoogleAnalytics#setDefaultRequest(DefaultRequest)} method.
*
* @author Santhosh Kumar
*/
public class DefaultRequest extends GoogleAnalyticsRequest{
private final static String DEFAULT_CLIENT_ID = UUID.randomUUID().toString();
public DefaultRequest() {
this(null, null, null, null);
}
public DefaultRequest(String hitType) {
this(hitType, null, null, null);
}
public DefaultRequest(String hitType, String trackingId, String appName, String appVersion) {
hitType(isEmpty(hitType)?"pageview":hitType);
trackingId(trackingId);
applicationName(appName);
applicationVersion(appVersion);
clientId(DEFAULT_CLIENT_ID);
}
/**
* Event Tracking
*
*
* Optional.
*
* Specifies the event category. Must not be empty.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ec
* text
* None
*
* 150 Bytes
*
* event
*
*
*
*
* Example value: Category
* Example usage: ec=Category
*
*
*/
public DefaultRequest eventCategory(String value) {
setString(EVENT_CATEGORY, value);
return this;
}
public String eventCategory() {
return getString(EVENT_CATEGORY);
}
/**
*
*
* Optional.
*
* Specifies the event action. Must not be empty.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ea
* text
* None
*
* 500 Bytes
*
* event
*
*
*
*
* Example value: Action
* Example usage: ea=Action
*
*
*/
public DefaultRequest eventAction(String value) {
setString(EVENT_ACTION, value);
return this;
}
public String eventAction() {
return getString(EVENT_ACTION);
}
/**
*
*
* Optional.
*
* Specifies the event label.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* el
* text
* None
*
* 500 Bytes
*
* event
*
*
*
*
* Example value: Label
* Example usage: el=Label
*
*
*/
public DefaultRequest eventLabel(String value) {
setString(EVENT_LABEL, value);
return this;
}
public String eventLabel() {
return getString(EVENT_LABEL);
}
/**
*
*
* Optional.
*
* Specifies the event value. Values must be non-negative.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ev
* integer
* None
*
* None
*
* event
*
*
*
*
* Example value: 55
* Example usage: ev=55
*
*
*/
public DefaultRequest eventValue(Integer value) {
setInteger(EVENT_VALUE, value);
return this;
}
public Integer eventValue() {
return getInteger(EVENT_VALUE);
}
/**
*
*
* Optional.
*
* Specifies the description of an exception.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* exd
* text
* None
*
* 150 Bytes
*
* exception
*
*
*
*
* Example value: DatabaseError
* Example usage: exd=DatabaseError
*
*
*/
public DefaultRequest exceptionDescription(String value) {
setString(EXCEPTION_DESCRIPTION, value);
return this;
}
public String exceptionDescription() {
return getString(EXCEPTION_DESCRIPTION);
}
/**
*
*
* Optional.
*
* Specifies whether the exception was fatal.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* exf
* boolean
* 1
*
* None
*
* exception
*
*
*
*
* Example value: 0
* Example usage: exf=0
*
*
*/
public DefaultRequest exceptionFatal(Boolean value) {
setBoolean(EXCEPTION_FATAL, value);
return this;
}
public Boolean exceptionFatal() {
return getBoolean(EXCEPTION_FATAL);
}
/**
*
*
* Required for item hit type.
*
* Specifies the item name.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* in
* text
* None
*
* 500 Bytes
*
* item
*
*
*
*
* Example value: Shoe
* Example usage: in=Shoe
*
*
*/
public DefaultRequest itemName(String value) {
setString(ITEM_NAME, value);
return this;
}
public String itemName() {
return getString(ITEM_NAME);
}
/**
*
*
* Optional.
*
* Specifies the price for a single item / unit.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ip
* currency
* 0
*
* None
*
* item
*
*
*
*
* Example value: 3.50
* Example usage: ip=3.50
*
*
*/
public DefaultRequest itemPrice(Double value) {
setDouble(ITEM_PRICE, value);
return this;
}
public Double itemPrice() {
return getDouble(ITEM_PRICE);
}
/**
*
*
* Optional.
*
* Specifies the number of items purchased.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* iq
* integer
* 0
*
* None
*
* item
*
*
*
*
* Example value: 4
* Example usage: iq=4
*
*
*/
public DefaultRequest itemQuantity(Integer value) {
setInteger(ITEM_QUANTITY, value);
return this;
}
public Integer itemQuantity() {
return getInteger(ITEM_QUANTITY);
}
/**
*
*
* Optional.
*
* Specifies the SKU or item code.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ic
* text
* None
*
* 500 Bytes
*
* item
*
*
*
*
* Example value: SKU47
* Example usage: ic=SKU47
*
*
*/
public DefaultRequest itemCode(String value) {
setString(ITEM_CODE, value);
return this;
}
public String itemCode() {
return getString(ITEM_CODE);
}
/**
*
*
* Optional.
*
* Specifies the category that the item belongs to.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* iv
* text
* None
*
* 500 Bytes
*
* item
*
*
*
*
* Example value: Blue
* Example usage: iv=Blue
*
*
*/
public DefaultRequest itemCategory(String value) {
setString(ITEM_CATEGORY, value);
return this;
}
public String itemCategory() {
return getString(ITEM_CATEGORY);
}
/**
*
*
* Optional.
*
* When present indicates the local currency for all transaction currency values. Value should be a valid ISO 4217 currency code.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* cu
* text
* None
*
* 10 Bytes
*
* transaction, item
*
*
*
*
* Example value: EUR
* Example usage: cu=EUR
*
*
*/
public DefaultRequest currencyCode(String value) {
setString(CURRENCY_CODE, value);
return this;
}
public String currencyCode() {
return getString(CURRENCY_CODE);
}
/**
*
*
* Required for social hit type.
*
* Specifies the social network, for example Facebook or Google Plus.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* sn
* text
* None
*
* 50 Bytes
*
* social
*
*
*
*
* Example value: facebook
* Example usage: sn=facebook
*
*
*/
public DefaultRequest socialNetwork(String value) {
setString(SOCIAL_NETWORK, value);
return this;
}
public String socialNetwork() {
return getString(SOCIAL_NETWORK);
}
/**
*
*
* Required for social hit type.
*
* Specifies the social interaction action. For example on Google Plus when a user clicks the +1 button, the social action is 'plus'.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* sa
* text
* None
*
* 50 Bytes
*
* social
*
*
*
*
* Example value: like
* Example usage: sa=like
*
*
*/
public DefaultRequest socialAction(String value) {
setString(SOCIAL_ACTION, value);
return this;
}
public String socialAction() {
return getString(SOCIAL_ACTION);
}
/**
*
*
* Required for social hit type.
*
* Specifies the target of a social interaction. This value is typically a URL but can be any text.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* st
* text
* None
*
* 2048 Bytes
*
* social
*
*
*
*
* Example value: http://foo.com
* Example usage: st=http%3A%2F%2Ffoo.com
*
*
*/
public DefaultRequest socialActionTarget(String value) {
setString(SOCIAL_ACTION_TARGET, value);
return this;
}
public String socialActionTarget() {
return getString(SOCIAL_ACTION_TARGET);
}
/**
*
*
* Optional.
*
* Specifies the user timing category.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* utc
* text
* None
*
* 150 Bytes
*
* timing
*
*
*
*
* Example value: category
* Example usage: utc=category
*
*
*/
public DefaultRequest userTimingCategory(String value) {
setString(USER_TIMING_CATEGORY, value);
return this;
}
public String userTimingCategory() {
return getString(USER_TIMING_CATEGORY);
}
/**
*
*
* Optional.
*
* Specifies the user timing variable.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* utv
* text
* None
*
* 500 Bytes
*
* timing
*
*
*
*
* Example value: lookup
* Example usage: utv=lookup
*
*
*/
public DefaultRequest userTimingVariableName(String value) {
setString(USER_TIMING_VARIABLE_NAME, value);
return this;
}
public String userTimingVariableName() {
return getString(USER_TIMING_VARIABLE_NAME);
}
/**
*
*
* Optional.
*
* Specifies the user timing value. The value is in milliseconds.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* utt
* integer
* None
*
* None
*
* timing
*
*
*
*
* Example value: 123
* Example usage: utt=123
*
*
*/
public DefaultRequest userTimingTime(Integer value) {
setInteger(USER_TIMING_TIME, value);
return this;
}
public Integer userTimingTime() {
return getInteger(USER_TIMING_TIME);
}
/**
*
*
* Optional.
*
* Specifies the user timing label.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* utl
* text
* None
*
* 500 Bytes
*
* timing
*
*
*
*
* Example value: label
* Example usage: utl=label
*
*
*/
public DefaultRequest userTimingLabel(String value) {
setString(USER_TIMING_LABEL, value);
return this;
}
public String userTimingLabel() {
return getString(USER_TIMING_LABEL);
}
/**
*
*
* Optional.
*
* Specifies the time it took for a page to load. The value is in milliseconds.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* plt
* integer
* None
*
* None
*
* timing
*
*
*
*
* Example value: 3554
* Example usage: plt=3554
*
*
*/
public DefaultRequest pageLoadTime(Integer value) {
setInteger(PAGE_LOAD_TIME, value);
return this;
}
public Integer pageLoadTime() {
return getInteger(PAGE_LOAD_TIME);
}
/**
*
*
* Optional.
*
* Specifies the time it took to do a DNS lookup.The value is in milliseconds.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* dns
* integer
* None
*
* None
*
* timing
*
*
*
*
* Example value: 43
* Example usage: dns=43
*
*
*/
public DefaultRequest dnsTime(Integer value) {
setInteger(DNS_TIME, value);
return this;
}
public Integer dnsTime() {
return getInteger(DNS_TIME);
}
/**
*
*
* Optional.
*
* Specifies the time it took for the page to be downloaded. The value is in milliseconds.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* pdt
* integer
* None
*
* None
*
* timing
*
*
*
*
* Example value: 500
* Example usage: pdt=500
*
*
*/
public DefaultRequest pageDownloadTime(Integer value) {
setInteger(PAGE_DOWNLOAD_TIME, value);
return this;
}
public Integer pageDownloadTime() {
return getInteger(PAGE_DOWNLOAD_TIME);
}
/**
*
*
* Optional.
*
* Specifies the time it took for any redirects to happen. The value is in milliseconds.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* rrt
* integer
* None
*
* None
*
* timing
*
*
*
*
* Example value: 500
* Example usage: rrt=500
*
*
*/
public DefaultRequest redirectResponseTime(Integer value) {
setInteger(REDIRECT_RESPONSE_TIME, value);
return this;
}
public Integer redirectResponseTime() {
return getInteger(REDIRECT_RESPONSE_TIME);
}
/**
*
*
* Optional.
*
* Specifies the time it took for a TCP connection to be made. The value is in milliseconds.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* tcp
* integer
* None
*
* None
*
* timing
*
*
*
*
* Example value: 500
* Example usage: tcp=500
*
*
*/
public DefaultRequest tcpConnectTime(Integer value) {
setInteger(TCP_CONNECT_TIME, value);
return this;
}
public Integer tcpConnectTime() {
return getInteger(TCP_CONNECT_TIME);
}
/**
*
*
* Optional.
*
* Specifies the time it took for the server to respond after the connect time. The value is in milliseconds.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* srt
* integer
* None
*
* None
*
* timing
*
*
*
*
* Example value: 500
* Example usage: srt=500
*
*
*/
public DefaultRequest serverResponseTime(Integer value) {
setInteger(SERVER_RESPONSE_TIME, value);
return this;
}
public Integer serverResponseTime() {
return getInteger(SERVER_RESPONSE_TIME);
}
/**
*
*
* Required for transaction hit type.
*
* Required for item hit type.
*
* A unique identifier for the transaction. This value should be the same for both the Transaction hit and Items hits associated to the particular transaction.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ti
* text
* None
*
* 500 Bytes
*
* transaction, item
*
*
*
*
* Example value: OD564
* Example usage: ti=OD564
*
*
*/
public DefaultRequest txId(String value) {
setString(TRANSACTION_ID, value);
return this;
}
public String txId() {
return getString(TRANSACTION_ID);
}
/**
*
*
* Optional.
*
* Specifies the affiliation or store name.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ta
* text
* None
*
* 500 Bytes
*
* transaction
*
*
*
*
* Example value: Member
* Example usage: ta=Member
*
*
*/
public DefaultRequest txAffiliation(String value) {
setString(TRANSACTION_AFFILIATION, value);
return this;
}
public String txAffiliation() {
return getString(TRANSACTION_AFFILIATION);
}
/**
*
*
* Optional.
*
* Specifies the total revenue associated with the transaction. This value should include any shipping or tax costs.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* tr
* currency
* 0
*
* None
*
* transaction
*
*
*
*
* Example value: 15.47
* Example usage: tr=15.47
*
*
*/
public DefaultRequest txRevenue(Double value) {
setDouble(TRANSACTION_REVENUE, value);
return this;
}
public Double txRevenue() {
return getDouble(TRANSACTION_REVENUE);
}
/**
*
*
* Optional.
*
* Specifies the total shipping cost of the transaction.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* ts
* currency
* 0
*
* None
*
* transaction
*
*
*
*
* Example value: 3.50
* Example usage: ts=3.50
*
*
*/
public DefaultRequest txShipping(Double value) {
setDouble(TRANSACTION_SHIPPING, value);
return this;
}
public Double txShipping() {
return getDouble(TRANSACTION_SHIPPING);
}
/**
*
*
* Optional.
*
* Specifies the total tax of the transaction.
*
*
*
* Parameter
* Value Type
* Default Value
* Max Length
* Supported Hit Types
*
*
* tt
* currency
* 0
*
* None
*
* transaction
*
*
*
*
* Example value: 11.20
* Example usage: tt=11.20
*
*
*/
public DefaultRequest txTax(Double value) {
setDouble(TRANSACTION_TAX, value);
return this;
}
public Double txTax() {
return getDouble(TRANSACTION_TAX);
}
}