GAIDictionaryBuilder.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*!
  2. @header GAIDictionaryBuilder.h
  3. @abstract Google Analytics iOS SDK Hit Format Header
  4. @copyright Copyright 2013 Google Inc. All rights reserved.
  5. */
  6. #import <Foundation/Foundation.h>
  7. #import "GAIEcommerceProduct.h"
  8. #import "GAIEcommerceProductAction.h"
  9. #import "GAIEcommercePromotion.h"
  10. /*!
  11. * Helper class to build a dictionary of hit parameters and values.
  12. * <br>
  13. * Examples:
  14. * <code>
  15. * id<GAITracker> t = // get a tracker.
  16. * [t send:[[[GAIDictionaryBuilder createEventWithCategory:@"EventCategory"
  17. * action:@"EventAction"
  18. * label:nil
  19. * value:nil]
  20. * set:@"dimension1" forKey:[GAIFields customDimensionForIndex:1]] build]];
  21. * </code>
  22. * This will send an event hit type with the specified parameters
  23. * and a custom dimension parameter.
  24. * <br>
  25. * If you want to send a parameter with all hits, set it on GAITracker directly.
  26. * <code>
  27. * [t set:kGAIScreenName value:@"Home"];
  28. * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
  29. * action:@"PlusOne"
  30. * target:@"SOME_URL"] build]];
  31. * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
  32. * action:@"Share"
  33. * target:@"SOME_POST"] build]];
  34. * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
  35. * action:@"HangOut"
  36. * target:@"SOME_CIRCLE"]
  37. * build]];
  38. * </code>
  39. * You can override a value set on the tracker by adding it to the dictionary.
  40. * <code>
  41. * [t set:kGAIScreenName value:@"Home"];
  42. * [t send:...];
  43. * [t send[[[GAIDictionaryBuilder createEventWithCategory:@"click"
  44. * action:@"popup"
  45. * label:nil
  46. * value:nil]
  47. * set:@"popup title" forKey:kGAIScreenName] build]];
  48. * </code>
  49. * The values set via [GAIDictionaryBuilder set] or
  50. * [GAIDictionaryBuilder setAll] will override any existing values in the
  51. * GAIDictionaryBuilder object (i.e. initialized by
  52. * [GAIDictionaryBuilder createXYZ]). e.g.
  53. * <code>
  54. * GAIDictionaryBuilder *m =
  55. * GAIDictionaryBuilder createTimingWithCategory:@"category"
  56. * interval:@0
  57. * name:@"name"
  58. * label:nil];
  59. * [t send:[m.set:@"10" forKey:kGAITimingVar] build];
  60. * [t send:[m.set:@"20" forKey:kGAITimingVar] build];
  61. * </code>
  62. */
  63. @interface GAIDictionaryBuilder : NSObject
  64. - (GAIDictionaryBuilder *)set:(NSString *)value
  65. forKey:(NSString *)key;
  66. /*!
  67. * Copies all the name-value pairs from params into this object, ignoring any
  68. * keys that are not NSString and any values that are neither NSString or
  69. * NSNull.
  70. */
  71. - (GAIDictionaryBuilder *)setAll:(NSDictionary *)params;
  72. /*!
  73. * Returns the value for the input parameter paramName, or nil if paramName
  74. * is not present.
  75. */
  76. - (NSString *)get:(NSString *)paramName;
  77. /*!
  78. * Return an NSMutableDictionary object with all the parameters set in this
  79. */
  80. - (NSMutableDictionary *)build;
  81. /*!
  82. * Parses and translates utm campaign parameters to analytics campaign param
  83. * and returns them as a map.
  84. *
  85. * @param params url containing utm campaign parameters.
  86. *
  87. * Valid campaign parameters are:
  88. * <ul>
  89. * <li>utm_id</li>
  90. * <li>utm_campaign</li>
  91. * <li>utm_content</li>
  92. * <li>utm_medium</li>
  93. * <li>utm_source</li>
  94. * <li>utm_term</li>
  95. * <li>dclid</li>
  96. * <li>gclid</li>
  97. * <li>gmob_t</li>
  98. * <li>aclid</li>
  99. * <li>anid</li>
  100. * </ul>
  101. * <p>
  102. * Example:
  103. * http://my.site.com/index.html?utm_campaign=wow&utm_source=source
  104. * utm_campaign=wow&utm_source=source.
  105. * <p>
  106. * For more information on auto-tagging, see
  107. * http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55590
  108. * <p>
  109. * For more information on manual tagging, see
  110. * http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55518
  111. */
  112. - (GAIDictionaryBuilder *)setCampaignParametersFromUrl:(NSString *)urlString;
  113. /*!
  114. Returns a GAIDictionaryBuilder object with parameters specific to an appview
  115. hit.
  116. Note that using this method will not set the screen name for followon hits. To
  117. do that you need to call set:kGAIDescription value:<screenName> on the
  118. GAITracker instance.
  119. This method is deprecated. Use createScreenView instead.
  120. */
  121. + (GAIDictionaryBuilder *)createAppView DEPRECATED_MSG_ATTRIBUTE("Use createScreenView instead.");
  122. /*!
  123. Returns a GAIDictionaryBuilder object with parameters specific to a screenview
  124. hit.
  125. Note that using this method will not set the screen name for followon hits. To
  126. do that you need to call set:kGAIDescription value:<screenName> on the
  127. GAITracker instance.
  128. */
  129. + (GAIDictionaryBuilder *)createScreenView;
  130. /*!
  131. Returns a GAIDictionaryBuilder object with parameters specific to an event hit.
  132. */
  133. + (GAIDictionaryBuilder *)createEventWithCategory:(NSString *)category
  134. action:(NSString *)action
  135. label:(NSString *)label
  136. value:(NSNumber *)value;
  137. /*!
  138. Returns a GAIDictionaryBuilder object with parameters specific to an exception
  139. hit.
  140. */
  141. + (GAIDictionaryBuilder *)createExceptionWithDescription:(NSString *)description
  142. withFatal:(NSNumber *)fatal;
  143. /*!
  144. Returns a GAIDictionaryBuilder object with parameters specific to an item hit.
  145. */
  146. + (GAIDictionaryBuilder *)createItemWithTransactionId:(NSString *)transactionId
  147. name:(NSString *)name
  148. sku:(NSString *)sku
  149. category:(NSString *)category
  150. price:(NSNumber *)price
  151. quantity:(NSNumber *)quantity
  152. currencyCode:(NSString *)currencyCode;
  153. /*!
  154. Returns a GAIDictionaryBuilder object with parameters specific to a social hit.
  155. */
  156. + (GAIDictionaryBuilder *)createSocialWithNetwork:(NSString *)network
  157. action:(NSString *)action
  158. target:(NSString *)target;
  159. /*!
  160. Returns a GAIDictionaryBuilder object with parameters specific to a timing hit.
  161. */
  162. + (GAIDictionaryBuilder *)createTimingWithCategory:(NSString *)category
  163. interval:(NSNumber *)intervalMillis
  164. name:(NSString *)name
  165. label:(NSString *)label;
  166. /*!
  167. Returns a GAIDictionaryBuilder object with parameters specific to a transaction
  168. hit.
  169. */
  170. + (GAIDictionaryBuilder *)createTransactionWithId:(NSString *)transactionId
  171. affiliation:(NSString *)affiliation
  172. revenue:(NSNumber *)revenue
  173. tax:(NSNumber *)tax
  174. shipping:(NSNumber *)shipping
  175. currencyCode:(NSString *)currencyCode;
  176. /*!
  177. Set the product action field for this hit.
  178. */
  179. - (GAIDictionaryBuilder *)setProductAction:(GAIEcommerceProductAction *)productAction;
  180. /*!
  181. Adds a product to this hit.
  182. */
  183. - (GAIDictionaryBuilder *)addProduct:(GAIEcommerceProduct *)product;
  184. /*!
  185. Add a product impression to this hit.
  186. */
  187. - (GAIDictionaryBuilder *)addProductImpression:(GAIEcommerceProduct *)product
  188. impressionList:(NSString *)name
  189. impressionSource:(NSString *)source;
  190. /*!
  191. Add a promotion to this hit.
  192. */
  193. - (GAIDictionaryBuilder *)addPromotion:(GAIEcommercePromotion *)promotion;
  194. @end