All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.brsanthu.googleanalytics.DefaultRequest Maven / Gradle / Ivy

Go to download

This is Java API for Google Analytics (Measurement Protocol). More information about the protocol is available at https://developers.google.com/analytics/devguides/collection/protocol/v1/.

There is a newer version: 2.0.0
Show newest version
/*
 * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
ectextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
eatextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
eltextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
evintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
exdtextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
exfboolean1 * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
intextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
ipcurrency0 * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
iqinteger0 * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
ictextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
ivtextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
cutextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
sntextNone * 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'.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
satextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
sttextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
utctextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
utvtextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
uttintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
utltextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
pltintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
dnsintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
pdtintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
rrtintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
tcpintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
srtintegerNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
titextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
tatextNone * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
trcurrency0 * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
tscurrency0 * 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.

* * * * * * * * * * * * * * * * * *
ParameterValue TypeDefault ValueMax LengthSupported Hit Types
ttcurrency0 * 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); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy