com.brsanthu.googleanalytics
Class GoogleAnalyticsRequest<T>

java.lang.Object
  extended by com.brsanthu.googleanalytics.GoogleAnalyticsRequest<T>
Direct Known Subclasses:
AppViewHit, DefaultRequest, EventHit, ExceptionHit, ItemHit, PageViewHit, SocialHit, TimingHit, TransactionHit

public class GoogleAnalyticsRequest<T>
extends Object

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 EventHit or PageViewHit etc)

Author:
Santhosh Kumar

Field Summary
protected  Map<String,String> customDimentions
           
protected  Map<String,String> customMetrics
           
protected  Map<GoogleAnalyticsParameter,String> parms
           
 
Constructor Summary
GoogleAnalyticsRequest()
           
GoogleAnalyticsRequest(String hitType)
           
GoogleAnalyticsRequest(String hitType, String trackingId, String appName, String appVersion)
           
 
Method Summary
 String adwordsId()
           
 T adwordsId(String value)
          
 Boolean anonymizeIp()
           
 T anonymizeIp(Boolean value)
          
 String applicationName()
           
 T applicationName(String value)
          
 String applicationVersion()
           
 T applicationVersion(String value)
          
 String cacheBuster()
           
 T cacheBuster(String value)
          
 String campaignContent()
           
 T campaignContent(String value)
          
 String campaignId()
           
 T campaignId(String value)
          
 String campaignKeyword()
           
 T campaignKeyword(String value)
          
 String campaignMedium()
           
 T campaignMedium(String value)
          
 String campaignName()
           
 T campaignName(String value)
          
 String campaignSource()
           
 T campaignSource(String value)
          
 String clientId()
           
 T clientId(String value)
          
 String contentDescription()
           
 T contentDescription(String value)
          
 String customDimention(int index)
           
 T customDimention(int index, String value)
          
 Map<String,String> customDimentions()
           
 String customMetric(int index)
           
 T customMetric(int index, String value)
          
 Map<String,String> custommMetrics()
           
 String displayadId()
           
 T displayadId(String value)
          
 String documentEncoding()
           
 T documentEncoding(String value)
          
 String documentHostName()
           
 T documentHostName(String value)
          
 String documentPath()
           
 T documentPath(String value)
          
 String documentReferrer()
           
 T documentReferrer(String value)
          
 String documentTitle()
           
 T documentTitle(String value)
          
 String documentUrl()
           
 T documentUrl(String value)
          
 String expirementId()
           
 T expirementId(String value)
          
 String expirementVariant()
           
 T expirementVariant(String value)
          
 String flashVersion()
           
 T flashVersion(String value)
          
protected  String fromBoolean(Boolean booleanString)
           
protected  String fromDouble(Double doubleValue)
           
protected  String fromInteger(Integer intValue)
           
protected  Boolean getBoolean(GoogleAnalyticsParameter parameter)
           
protected  Double getDouble(GoogleAnalyticsParameter parameter)
           
protected  Integer getInteger(GoogleAnalyticsParameter parameter)
           
 Map<GoogleAnalyticsParameter,String> getParameters()
           
protected  String getString(GoogleAnalyticsParameter parameter)
           
 String hitType()
           
 T hitType(String value)
          
protected  boolean isEmpty(String string)
           
 Boolean javaEnabled()
           
 T javaEnabled(Boolean value)
          
 String nonInteractionHit()
           
 T nonInteractionHit(String value)
          
protected  String parameter(GoogleAnalyticsParameter parameter)
           
protected  T parameter(GoogleAnalyticsParameter parameter, String value)
           
 String protocolVersion()
           
 T protocolVersion(String value)
          
 Integer queueTime()
           
 T queueTime(Integer value)
          
 String screenColors()
           
 T screenColors(String value)
          
 String screenResolution()
           
 T screenResolution(String value)
          
 String sessionControl()
           
 T sessionControl(String value)
          
protected  T setBoolean(GoogleAnalyticsParameter parameter, Boolean value)
           
protected  T setDouble(GoogleAnalyticsParameter parameter, Double value)
           
protected  T setInteger(GoogleAnalyticsParameter parameter, Integer value)
           
protected  T setString(GoogleAnalyticsParameter parameter, String value)
          Sets the String value for specified parameter.
protected  Boolean toBoolean(String booleanString)
           
protected  Double toDouble(String doubleString)
           
protected  Integer toInteger(String intString)
           
 String toString()
           
 String trackingId()
           
 T trackingId(String value)
          
 String userLanguage()
           
 T userLanguage(String value)
          
 String viewportSize()
           
 T viewportSize(String value)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parms

protected Map<GoogleAnalyticsParameter,String> parms

customDimentions

protected Map<String,String> customDimentions

customMetrics

protected Map<String,String> customMetrics
Constructor Detail

GoogleAnalyticsRequest

public GoogleAnalyticsRequest()

GoogleAnalyticsRequest

public GoogleAnalyticsRequest(String hitType)

GoogleAnalyticsRequest

public GoogleAnalyticsRequest(String hitType,
                              String trackingId,
                              String appName,
                              String appVersion)
Method Detail

setString

protected T setString(GoogleAnalyticsParameter parameter,
                      String value)
Sets the String value for specified parameter. If value is null, the parameter is removed from the parameters list.

Parameters:
parameter -
value -
Returns:

getString

protected String getString(GoogleAnalyticsParameter parameter)

setInteger

protected T setInteger(GoogleAnalyticsParameter parameter,
                       Integer value)

getDouble

protected Double getDouble(GoogleAnalyticsParameter parameter)

setDouble

protected T setDouble(GoogleAnalyticsParameter parameter,
                      Double value)

getBoolean

protected Boolean getBoolean(GoogleAnalyticsParameter parameter)

setBoolean

protected T setBoolean(GoogleAnalyticsParameter parameter,
                       Boolean value)

getInteger

protected Integer getInteger(GoogleAnalyticsParameter parameter)

fromBoolean

protected String fromBoolean(Boolean booleanString)

toBoolean

protected Boolean toBoolean(String booleanString)

fromInteger

protected String fromInteger(Integer intValue)

toInteger

protected Integer toInteger(String intString)

fromDouble

protected String fromDouble(Double doubleValue)

toDouble

protected Double toDouble(String doubleString)

parameter

protected T parameter(GoogleAnalyticsParameter parameter,
                      String value)

parameter

protected String parameter(GoogleAnalyticsParameter parameter)

getParameters

public Map<GoogleAnalyticsParameter,String> getParameters()

customDimention

public String customDimention(int index)

customDimention

public T customDimention(int index,
                         String value)

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


customMetric

public T customMetric(int index,
                      String value)

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


customMetric

public String customMetric(int index)

customDimentions

public Map<String,String> customDimentions()

custommMetrics

public Map<String,String> custommMetrics()

toString

public String toString()
Overrides:
toString in class Object

protocolVersion

public T protocolVersion(String value)

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


protocolVersion

public String protocolVersion()

trackingId

public T trackingId(String value)

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


trackingId

public String trackingId()

anonymizeIp

public T anonymizeIp(Boolean value)

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


anonymizeIp

public Boolean anonymizeIp()

queueTime

public T queueTime(Integer value)

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


queueTime

public Integer queueTime()

cacheBuster

public T cacheBuster(String value)

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


cacheBuster

public String cacheBuster()

clientId

public T clientId(String value)

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


clientId

public String clientId()

sessionControl

public T sessionControl(String value)

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


sessionControl

public String sessionControl()

documentReferrer

public T documentReferrer(String value)

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


documentReferrer

public String documentReferrer()

campaignName

public T campaignName(String value)

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


campaignName

public String campaignName()

campaignSource

public T campaignSource(String value)

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


campaignSource

public String campaignSource()

campaignMedium

public T campaignMedium(String value)

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


campaignMedium

public String campaignMedium()

campaignKeyword

public T campaignKeyword(String value)

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


campaignKeyword

public String campaignKeyword()

campaignContent

public T campaignContent(String value)

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


campaignContent

public String campaignContent()

campaignId

public T campaignId(String value)

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


campaignId

public String campaignId()

adwordsId

public T adwordsId(String value)

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


adwordsId

public String adwordsId()

displayadId

public T displayadId(String value)

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


displayadId

public String displayadId()

screenResolution

public T screenResolution(String value)

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


screenResolution

public String screenResolution()

viewportSize

public T viewportSize(String value)

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


viewportSize

public String viewportSize()

documentEncoding

public T documentEncoding(String value)

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


documentEncoding

public String documentEncoding()

screenColors

public T screenColors(String value)

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


screenColors

public String screenColors()

userLanguage

public T userLanguage(String value)

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


userLanguage

public String userLanguage()

javaEnabled

public T javaEnabled(Boolean value)

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


javaEnabled

public Boolean javaEnabled()

flashVersion

public T flashVersion(String value)

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


flashVersion

public String flashVersion()

hitType

public T hitType(String value)

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


hitType

public String hitType()

nonInteractionHit

public T nonInteractionHit(String value)

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


nonInteractionHit

public String nonInteractionHit()

documentUrl

public T documentUrl(String value)

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


documentUrl

public String documentUrl()

documentHostName

public T documentHostName(String value)

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


documentHostName

public String documentHostName()

documentPath

public T documentPath(String value)

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


documentPath

public String documentPath()

documentTitle

public T documentTitle(String value)

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


documentTitle

public String documentTitle()

contentDescription

public T contentDescription(String value)

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


contentDescription

public String contentDescription()

applicationName

public T applicationName(String value)

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


applicationName

public String applicationName()

applicationVersion

public T applicationVersion(String value)

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


applicationVersion

public String applicationVersion()

expirementId

public T expirementId(String value)

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


expirementId

public String expirementId()

expirementVariant

public T expirementVariant(String value)

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


expirementVariant

public String expirementVariant()

isEmpty

protected boolean isEmpty(String string)


Copyright © Sep 2013–2013 brsanthu Inc. All rights reserved.