Summary: Protected Ctors | Methods | Protected Methods | Inherited Methods | [Expand All]
protected static class

# HitBuilders.HitBuilder

extends Object

java.lang.Object
↳ | com.google.android.gms.analytics.HitBuilders.HitBuilder<T extends com.google.android.gms.analytics.HitBuilders.HitBuilder>

Known Direct Subclasses HitBuilders.AppViewBuilder, HitBuilders.EventBuilder, HitBuilders.ExceptionBuilder, HitBuilders.ItemBuilder, HitBuilders.ScreenViewBuilder, HitBuilders.SocialBuilder, HitBuilders.TimingBuilder, HitBuilders.TransactionBuilder
HitBuilders.AppViewBuilder | This class is deprecated. This class has been deprecated in favor of the new ScreenViewBuilder class. The two classes are semantically similar but the latter is consistent across all the Google Analytics platforms.
HitBuilders.EventBuilder | A Builder object to build event hits.
HitBuilders.ExceptionBuilder | Exception builder allows you to measure the number and type of caught and uncaught crashes and exceptions that occur in your app.
HitBuilders.ItemBuilder | This class is deprecated. This class has been deprecated in favor of a richer set of APIs on all the HitBuilder classes. With the new approach, simply use addProduct, addImpression, addPromo and setAction to add ecommerce data to any of the hits.
HitBuilders.ScreenViewBuilder | Class to build a screen view hit.
HitBuilders.SocialBuilder | A Builder object to build social event hits.
HitBuilders.TimingBuilder | Hit builder used to collect timing related data.
HitBuilders.TransactionBuilder | This class is deprecated. This class has been deprecated in favor of a richer set of APIs on all the HitBuilder classes. With the new approach, simply use addProduct, addImpression, addPromo and setAction to add ecommerce data to any of the hits.

## Class Overview

Internal class to provide common builder class methods. The most important methods from this class are the setXYZ and build methods. These methods can be used to set individual properties on the hit and then build it so that it is ready to be passed into the tracker.

## Summary

Protected Constructors
| HitBuilders.HitBuilder()

Public Methods
T | addImpression(Product product, String impressionList) Adds a product impression to the hit.
T | addProduct(Product product) Adds product information to be sent with a given hit.
T | addPromotion(Promotion promotion) Adds promotion related information to the hit.
Map<String, String> | build() Builds a `Map` of parameters and values that can be set on the `Tracker` object.
final T | set(String paramName, String paramValue) Sets the value for the given parameter name.
final T | setAll(Map<String, String> params) Adds a set of key, value pairs to the hit builder.
T | setCampaignParamsFromUrl(String utmParams) Parses and translates utm campaign parameters to analytics campaign parameters and returns them as a map.
T | setCustomDimension(int index, String dimension) Adds a custom dimension to the current hit builder.
T | setCustomMetric(int index, float metric) Adds a custom metric to the current hit builder.
T | setNewSession()
T | setNonInteraction(boolean nonInteraction)
T | setProductAction(ProductAction action) Sets a product action for all the products included in this hit.
T | setPromotionAction(String action) Adds an action associated with the promotions in a given hit.

Protected Methods
String | get(String paramName)
T | setHitType(String hitType) Sets the type of the hit to be sent.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## Protected Constructors

#### protected HitBuilders.HitBuilder ()

## Public Methods

#### public T addImpression (Product product, String impressionList)

Adds a product impression to the hit. The product can be optionally associated with a named impression list.

#### public T addProduct (Product product)

Adds product information to be sent with a given hit. The action provided in `setProductAction(ProductAction)` affects how the products passed in through this method get processed.

#### public T addPromotion (Promotion promotion)

Adds promotion related information to the hit.

#### public Map<String, String> build ()

Builds a `Map` of parameters and values that can be set on the `Tracker` object.

##### Returns

- A map of string keys to string values that can be passed into the tracker for one or more hits.

#### public final T set (String paramName, String paramValue)

Sets the value for the given parameter name. These values will be added to the hit when it is built. This function should only be used for advanced cases where none of the explicit setters do not work. This function should usually be called after all the explicit setter have been called.

##### Parameters

paramName | The name of the parameter that should be sent over wire. This value should start with "&".
paramValue | The value to be sent over the wire for the given parameter.

##### Returns

- The builder object that you can use to chain calls.

#### public final T setAll (Map<String, String> params)

Adds a set of key, value pairs to the hit builder. These values will be added to the hit when it is built. This function should only be used for advanced cases where none of the explicit setters work. This function should usually be called after all the explicit setter have been called.

##### Parameters

params | A map of all the values to be added to the builder.

##### Returns

- The builder object that you can use to chain calls.

#### public T setCampaignParamsFromUrl (String utmParams)

Parses and translates utm campaign parameters to analytics campaign parameters and returns them as a map.

##### Parameters

utmParams | url containing utm campaign parameters.

##### Returns

- The builder object that you can use to chain calls. Valid campaign parameters are:
  - utm_id
  - utm_campaign
  - utm_content
  - utm_medium
  - utm_source
  - utm_term
  - dclid
  - gclid
  - gmob_t

  Example: http://my.site.com/index.html?utm_campaign=wow&utm_source=source utm_campaign=wow&utm_source=source.

  For more information on auto-tagging, see http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55590

  For more information on manual tagging, see http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55518 *

#### public T setCustomDimension (int index, String dimension)

Adds a custom dimension to the current hit builder. Calling this method with the same index will overwrite the previous dimension with the new one. Refer http://goo.gl/igziD2 for details on how to set the custom dimensions up.

##### Parameters

index | The index/slot in which the dimension will be set.
dimension | The value of the dimension for the given index.

##### Returns

- The builder object that you can use to chain calls.

#### public T setCustomMetric (int index, float metric)

Adds a custom metric to the current hit builder. Calling this method with the same index will overwrite the previous metric with the new one. Refer http://goo.gl/igziD2 for details on how to set the custom metrics up.

##### Parameters

index | The index/slot in which the metric will be set.
metric | The value of the metric for the given index.

##### Returns

- The builder object that you can use to chain calls.

#### public T setNewSession ()

#### public T setNonInteraction (boolean nonInteraction)

#### public T setProductAction (ProductAction action)

Sets a product action for all the products included in this hit. The action and its associated properties affect how the products added through `addProduct(Product)` are processed.

#### public T setPromotionAction (String action)

Adds an action associated with the promotions in a given hit. Valid values for an action are defined in `Promotion` class.

## Protected Methods

#### protected String get (String paramName)

#### protected T setHitType (String hitType)

Sets the type of the hit to be sent. This can be used to reuse the builder object for multiple hit types. See http://goo.gl/kMRwhS for possible hit values.

##### Parameters

hitType | The value of the Hit.