GAIDictionaryBuilder Class Reference

Overview

Helper class to build a dictionary of hit parameters and values.


Examples:

id<GAITracker> t = // get a tracker.
[t send:[[[GAIDictionaryBuilder createEventWithCategory:@"EventCategory"
                                                 action:@"EventAction"
                                                  label:nil
                                                  value:nil]
    set:"dimension1" forKey:[GAIFields customDimensionForIndex:1]] build]];

This will send an event hit type with the specified parameters and a custom dimension parameter.
If you want to send a parameter with all hits, set it on GAITracker directly.

[t set:kGAIScreenName value:@"Home"];
[t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
                                                action:@"PlusOne"
                                                target:@"SOME_URL"] build]];
[t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
                                                action:@"Share"
                                                target:@"SOME_POST"] build]];
[t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
                                                action:@"HangOut"
                                                target:@"SOME_CIRCLE"]
    build]];

You can override a value set on the tracker by adding it to the dictionary.

[t set:kGAIScreenName value:@"Home"];
[t send:...];
[t send[[[GAIDictionaryBuilder createEventWithCategory:@"click"
                                                action:@"popup"
                                                 label:nil
                                                 value:nil]
    set:@"popup title" forKey:kGAIScreenName] build]];

The values set via [GAIDictionaryBuilder set] or [GAIDictionaryBuilder setAll] will override any existing values in the GAIDictionaryBuilder object (i.e. initialized by [GAIDictionaryBuilder createXYZ]). e.g.

GAIDictionaryBuilder *m =
    GAIDictionaryBuilder createTimingWithCategory:@"category"
                                         interval:@0
                                             name:@"name"
                                            label:nil];
[t send:[m.set:@"10" forKey:kGAITimingVar] build];
[t send:[m.set:@"20" forKey:kGAITimingVar] build];

Inherits NSObject.

Instance Methods

(GAIDictionaryBuilder *) - setAll:
 Copies all the name-value pairs from params into this object, ignoring any keys that are not NSString and any values that are neither NSString or NSNull. More...
 
(NSString *) - get:
 Returns the value for the input parameter paramName, or nil if paramName is not present. More...
 
(NSMutableDictionary *) - build
 Return an NSMutableDictionary object with all the parameters set in this. More...
 
(GAIDictionaryBuilder *) - setCampaignParametersFromUrl:
 Parses and translates utm campaign parameters to analytics campaign param and returns them as a map. More...
 
(GAIDictionaryBuilder *) - setProductAction:
 Set the product action field for this hit. More...
 
(GAIDictionaryBuilder *) - addProduct:
 Adds a product to this hit. More...
 
(GAIDictionaryBuilder *) - addProductImpression:impressionList:impressionSource:
 Add a product impression to this hit. More...
 
(GAIDictionaryBuilder *) - addPromotion:
 Add a promotion to this hit. More...
 

Class Methods

("Use createScreenView instead.") + createAppView
 Returns a GAIDictionaryBuilder object with parameters specific to an appview hit. More...
 
(GAIDictionaryBuilder *) + createScreenView
 Returns a GAIDictionaryBuilder object with parameters specific to a screenview hit. More...
 
(GAIDictionaryBuilder *) + createEventWithCategory:action:label:value:
 Returns a GAIDictionaryBuilder object with parameters specific to an event hit. More...
 
(GAIDictionaryBuilder *) + createExceptionWithDescription:withFatal:
 Returns a GAIDictionaryBuilder object with parameters specific to an exception hit. More...
 
(GAIDictionaryBuilder *) + createItemWithTransactionId:name:sku:category:price:quantity:currencyCode:
 Returns a GAIDictionaryBuilder object with parameters specific to an item hit. More...
 
(GAIDictionaryBuilder *) + createSocialWithNetwork:action:target:
 Returns a GAIDictionaryBuilder object with parameters specific to a social hit. More...
 
(GAIDictionaryBuilder *) + createTimingWithCategory:interval:name:label:
 Returns a GAIDictionaryBuilder object with parameters specific to a timing hit. More...
 
(GAIDictionaryBuilder *) + createTransactionWithId:affiliation:revenue:tax:shipping:currencyCode:
 Returns a GAIDictionaryBuilder object with parameters specific to a transaction hit. More...
 

Method Documentation

- (GAIDictionaryBuilder *) setAll: (NSDictionary *)  params

Copies all the name-value pairs from params into this object, ignoring any keys that are not NSString and any values that are neither NSString or NSNull.

- (NSString *) get: (NSString *)  paramName

Returns the value for the input parameter paramName, or nil if paramName is not present.

- (NSMutableDictionary *) build

Return an NSMutableDictionary object with all the parameters set in this.

- (GAIDictionaryBuilder *) setCampaignParametersFromUrl: (NSString *)  urlString

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

Parameters
paramsurl containing utm campaign parameters.

Valid campaign parameters are:

  • utm_id
  • utm_campaign
  • utm_content
  • utm_medium
  • utm_source
  • utm_term
  • dclid
  • gclid
  • gmob_t
  • aclid
  • anid

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 and manual tagging, see Benefits of auto-tagging.

+ (GAIDictionaryBuilder *) createAppView

Returns a GAIDictionaryBuilder object with parameters specific to an appview hit.

Note that using this method will not set the screen name for followon hits. To do that you need to call set:kGAIDescription value:<screenName> on the GAITracker instance.

This method is deprecated. Use createScreenView instead.

+ (GAIDictionaryBuilder *) createScreenView

Returns a GAIDictionaryBuilder object with parameters specific to a screenview hit.

Note that using this method will not set the screen name for followon hits. To do that you need to call set:kGAIDescription value:<screenName> on the GAITracker instance.

+ (GAIDictionaryBuilder *) createEventWithCategory: (NSString *)  category
action: (NSString *)  action
label: (NSString *)  label
value: (NSNumber *)  value 

Returns a GAIDictionaryBuilder object with parameters specific to an event hit.

+ (GAIDictionaryBuilder *) createExceptionWithDescription: (NSString *)  description
withFatal: (NSNumber *)  fatal 

Returns a GAIDictionaryBuilder object with parameters specific to an exception hit.

+ (GAIDictionaryBuilder *) createItemWithTransactionId: (NSString *)  transactionId
name: (NSString *)  name
sku: (NSString *)  sku
category: (NSString *)  category
price: (NSNumber *)  price
quantity: (NSNumber *)  quantity
currencyCode: (NSString *)  currencyCode 

Returns a GAIDictionaryBuilder object with parameters specific to an item hit.

+ (GAIDictionaryBuilder *) createSocialWithNetwork: (NSString *)  network
action: (NSString *)  action
target: (NSString *)  target 

Returns a GAIDictionaryBuilder object with parameters specific to a social hit.

+ (GAIDictionaryBuilder *) createTimingWithCategory: (NSString *)  category
interval: (NSNumber *)  intervalMillis
name: (NSString *)  name
label: (NSString *)  label 

Returns a GAIDictionaryBuilder object with parameters specific to a timing hit.

+ (GAIDictionaryBuilder *) createTransactionWithId: (NSString *)  transactionId
affiliation: (NSString *)  affiliation
revenue: (NSNumber *)  revenue
tax: (NSNumber *)  tax
shipping: (NSNumber *)  shipping
currencyCode: (NSString *)  currencyCode 

Returns a GAIDictionaryBuilder object with parameters specific to a transaction hit.

- (GAIDictionaryBuilder *) setProductAction: (GAIEcommerceProductAction *)  productAction

Set the product action field for this hit.

- (GAIDictionaryBuilder *) addProduct: (GAIEcommerceProduct *)  product

Adds a product to this hit.

- (GAIDictionaryBuilder *) addProductImpression: (GAIEcommerceProduct *)  product
impressionList: (NSString *)  name
impressionSource: (NSString *)  source 

Add a product impression to this hit.

- (GAIDictionaryBuilder *) addPromotion: (GAIEcommercePromotion *)  promotion

Add a promotion to this hit.