8 |
9 | #import "GAIEcommerceProduct.h"
10 | #import "GAIEcommerceProductAction.h"
11 | #import "GAIEcommercePromotion.h"
12 |
13 | /*!
14 | * Helper class to build a dictionary of hit parameters and values.
15 | *
16 | * Examples:
17 | *
18 | * id t = // get a tracker.
19 | * [t send:[[[GAIDictionaryBuilder createEventWithCategory:@"EventCategory"
20 | * action:@"EventAction"
21 | * label:nil
22 | * value:nil]
23 | * set:@"dimension1" forKey:[GAIFields customDimensionForIndex:1]] build]];
24 | *
25 | * This will send an event hit type with the specified parameters
26 | * and a custom dimension parameter.
27 | *
28 | * If you want to send a parameter with all hits, set it on GAITracker directly.
29 | *
30 | * [t set:kGAIScreenName value:@"Home"];
31 | * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
32 | * action:@"PlusOne"
33 | * target:@"SOME_URL"] build]];
34 | * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
35 | * action:@"Share"
36 | * target:@"SOME_POST"] build]];
37 | * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+"
38 | * action:@"HangOut"
39 | * target:@"SOME_CIRCLE"]
40 | * build]];
41 | *
42 | * You can override a value set on the tracker by adding it to the dictionary.
43 | *
44 | * [t set:kGAIScreenName value:@"Home"];
45 | * [t send:...];
46 | * [t send[[[GAIDictionaryBuilder createEventWithCategory:@"click"
47 | * action:@"popup"
48 | * label:nil
49 | * value:nil]
50 | * set:@"popup title" forKey:kGAIScreenName] build]];
51 | *
52 | * The values set via [GAIDictionaryBuilder set] or
53 | * [GAIDictionaryBuilder setAll] will override any existing values in the
54 | * GAIDictionaryBuilder object (i.e. initialized by
55 | * [GAIDictionaryBuilder createXYZ]). e.g.
56 | *
57 | * GAIDictionaryBuilder *m =
58 | * GAIDictionaryBuilder createTimingWithCategory:@"category"
59 | * interval:@0
60 | * name:@"name"
61 | * label:nil];
62 | * [t send:[m.set:@"10" forKey:kGAITimingVar] build];
63 | * [t send:[m.set:@"20" forKey:kGAITimingVar] build];
64 | *
65 | */
66 | @interface GAIDictionaryBuilder : NSObject
67 |
68 | - (GAIDictionaryBuilder *)set:(NSString *)value
69 | forKey:(NSString *)key;
70 |
71 | /*!
72 | * Copies all the name-value pairs from params into this object, ignoring any
73 | * keys that are not NSString and any values that are neither NSString or
74 | * NSNull.
75 | */
76 | - (GAIDictionaryBuilder *)setAll:(NSDictionary *)params;
77 |
78 | /*!
79 | * Returns the value for the input parameter paramName, or nil if paramName
80 | * is not present.
81 | */
82 | - (NSString *)get:(NSString *)paramName;
83 |
84 | /*!
85 | * Return an NSMutableDictionary object with all the parameters set in this
86 | */
87 | - (NSMutableDictionary *)build;
88 |
89 | /*!
90 | * Parses and translates utm campaign parameters to analytics campaign param
91 | * and returns them as a map.
92 | *
93 | * @param params url containing utm campaign parameters.
94 | *
95 | * Valid campaign parameters are:
96 | *
97 | * - utm_id
98 | * - utm_campaign
99 | * - utm_content
100 | * - utm_medium
101 | * - utm_source
102 | * - utm_term
103 | * - dclid
104 | * - gclid
105 | * - gmob_t
106 | * - aclid
107 | * - anid
108 | *
109 | *
110 | * Example:
111 | * http://my.site.com/index.html?utm_campaign=wow&utm_source=source
112 | * utm_campaign=wow&utm_source=source.
113 | *
114 | * For more information on manual and auto-tagging, see
115 | * https://support.google.com/analytics/answer/1733663?hl=en
116 | */
117 | - (GAIDictionaryBuilder *)setCampaignParametersFromUrl:(NSString *)urlString;
118 |
119 | /*!
120 | Returns a GAIDictionaryBuilder object with parameters specific to an appview
121 | hit.
122 |
123 | Note that using this method will not set the screen name for followon hits. To
124 | do that you need to call set:kGAIDescription value: on the
125 | GAITracker instance.
126 |
127 | This method is deprecated. Use createScreenView instead.
128 | */
129 | + (GAIDictionaryBuilder *)createAppView DEPRECATED_MSG_ATTRIBUTE("Use createScreenView instead.");
130 |
131 | /*!
132 | Returns a GAIDictionaryBuilder object with parameters specific to a screenview
133 | hit.
134 |
135 | Note that using this method will not set the screen name for followon hits. To
136 | do that you need to call set:kGAIDescription value: on the
137 | GAITracker instance.
138 | */
139 | + (GAIDictionaryBuilder *)createScreenView;
140 |
141 | /*!
142 | Returns a GAIDictionaryBuilder object with parameters specific to an event hit.
143 | */
144 | + (GAIDictionaryBuilder *)createEventWithCategory:(NSString *)category
145 | action:(NSString *)action
146 | label:(NSString *)label
147 | value:(NSNumber *)value;
148 |
149 | /*!
150 | Returns a GAIDictionaryBuilder object with parameters specific to an exception
151 | hit.
152 | */
153 | + (GAIDictionaryBuilder *)createExceptionWithDescription:(NSString *)description
154 | withFatal:(NSNumber *)fatal;
155 |
156 | /*!
157 | Returns a GAIDictionaryBuilder object with parameters specific to an item hit.
158 | */
159 | + (GAIDictionaryBuilder *)createItemWithTransactionId:(NSString *)transactionId
160 | name:(NSString *)name
161 | sku:(NSString *)sku
162 | category:(NSString *)category
163 | price:(NSNumber *)price
164 | quantity:(NSNumber *)quantity
165 | currencyCode:(NSString *)currencyCode;
166 |
167 | /*!
168 | Returns a GAIDictionaryBuilder object with parameters specific to a social hit.
169 | */
170 | + (GAIDictionaryBuilder *)createSocialWithNetwork:(NSString *)network
171 | action:(NSString *)action
172 | target:(NSString *)target;
173 |
174 | /*!
175 | Returns a GAIDictionaryBuilder object with parameters specific to a timing hit.
176 | */
177 | + (GAIDictionaryBuilder *)createTimingWithCategory:(NSString *)category
178 | interval:(NSNumber *)intervalMillis
179 | name:(NSString *)name
180 | label:(NSString *)label;
181 |
182 | /*!
183 | Returns a GAIDictionaryBuilder object with parameters specific to a transaction
184 | hit.
185 | */
186 | + (GAIDictionaryBuilder *)createTransactionWithId:(NSString *)transactionId
187 | affiliation:(NSString *)affiliation
188 | revenue:(NSNumber *)revenue
189 | tax:(NSNumber *)tax
190 | shipping:(NSNumber *)shipping
191 | currencyCode:(NSString *)currencyCode;
192 |
193 | /*!
194 | Set the product action field for this hit.
195 | */
196 | - (GAIDictionaryBuilder *)setProductAction:(GAIEcommerceProductAction *)productAction;
197 |
198 | /*!
199 | Adds a product to this hit.
200 | */
201 | - (GAIDictionaryBuilder *)addProduct:(GAIEcommerceProduct *)product;
202 |
203 | /*!
204 | Add a product impression to this hit.
205 | */
206 | - (GAIDictionaryBuilder *)addProductImpression:(GAIEcommerceProduct *)product
207 | impressionList:(NSString *)name
208 | impressionSource:(NSString *)source;
209 |
210 | /*!
211 | Add a promotion to this hit.
212 | */
213 | - (GAIDictionaryBuilder *)addPromotion:(GAIEcommercePromotion *)promotion;
214 | @end
215 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAIEcommerceFields.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAIEcommerceFields.h
3 | @abstract Google Analytics iOS SDK Ecommerce Hit Format Header
4 | @copyright Copyright 2014 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 |
9 | /*!
10 | This class provides several fields and methods useful as wire format parameters for
11 | Enhanced Ecommerce. See the online developer guides for Enhanced Ecommerce for details
12 | on how to use the Enhanced Ecommerce features.
13 | */
14 |
15 | // Enhanced Ecommerce Product fields
16 | extern NSString *const kGAIProductId;
17 | extern NSString *const kGAIProductName;
18 | extern NSString *const kGAIProductBrand;
19 | extern NSString *const kGAIProductCategory;
20 | extern NSString *const kGAIProductVariant;
21 | extern NSString *const kGAIProductPrice;
22 | extern NSString *const kGAIProductQuantity;
23 | extern NSString *const kGAIProductCouponCode;
24 | extern NSString *const kGAIProductPosition;
25 |
26 | extern NSString *const kGAIProductAction;
27 |
28 | // product action values
29 | extern NSString *const kGAIPADetail;
30 | extern NSString *const kGAIPAClick;
31 | extern NSString *const kGAIPAAdd;
32 | extern NSString *const kGAIPARemove;
33 | extern NSString *const kGAIPACheckout;
34 | extern NSString *const kGAIPACheckoutOption;
35 | extern NSString *const kGAIPAPurchase;
36 | extern NSString *const kGAIPARefund;
37 |
38 | // product action fields
39 | // used for 'purchase' and 'refund' actions
40 | extern NSString *const kGAIPATransactionId;
41 | extern NSString *const kGAIPAAffiliation;
42 | extern NSString *const kGAIPARevenue;
43 | extern NSString *const kGAIPATax;
44 | extern NSString *const kGAIPAShipping;
45 | extern NSString *const kGAIPACouponCode;
46 | // used for 'checkout' action
47 | extern NSString *const kGAICheckoutStep;
48 | extern NSString *const kGAICheckoutOption;
49 | // used for 'detail' and 'click' actions
50 | extern NSString *const kGAIProductActionList;
51 | extern NSString *const kGAIProductListSource;
52 |
53 | // Enhanced Ecommerce Impressions fields
54 | extern NSString *const kGAIImpressionName;
55 | extern NSString *const kGAIImpressionListSource;
56 | extern NSString *const kGAIImpressionProduct;
57 | extern NSString *const kGAIImpressionProductId;
58 | extern NSString *const kGAIImpressionProductName;
59 | extern NSString *const kGAIImpressionProductBrand;
60 | extern NSString *const kGAIImpressionProductCategory;
61 | extern NSString *const kGAIImpressionProductVariant;
62 | extern NSString *const kGAIImpressionProductPosition;
63 | extern NSString *const kGAIImpressionProductPrice;
64 |
65 | // Enhanced Ecommerce Promotions fields
66 | extern NSString *const kGAIPromotionId;
67 | extern NSString *const kGAIPromotionName;
68 | extern NSString *const kGAIPromotionCreative;
69 | extern NSString *const kGAIPromotionPosition;
70 |
71 | // Promotion actions
72 | extern NSString *const kGAIPromotionAction;
73 | extern NSString *const kGAIPromotionView;
74 | extern NSString *const kGAIPromotionClick;
75 |
76 | @interface GAIEcommerceFields : NSObject
77 |
78 | /*!
79 | Generates an enhanced ecommerce product field. Note that field names generated by
80 | customDimensionForIndex and customMetricForIndex can be used as suffixes.
81 |
82 | @param index the index of the product
83 | @param suffix the product field suffix (such as kGAIProductPrice).
84 |
85 | @return an NSString representing the product field parameter
86 | */
87 | + (NSString *)productFieldForIndex:(NSUInteger)index suffix:(NSString *)suffix;
88 |
89 | /*!
90 | Genrates an enhanced ecommerce impression list field name with an index. The return value of
91 | this method should also be used as input to the productImpressionForList method below.
92 |
93 | @param index the index of the impression list
94 |
95 | @return an NSString representing the impression list parameter
96 | */
97 | + (NSString *)impressionListForIndex:(NSUInteger)index;
98 |
99 | /*!
100 | Generates an enhanced ecommerce product impression field with the impression list, product index
101 | and product suffix as parameters. The output of the method impressionListForIndex above should be
102 | used as the input list for this method. The output of customDimensionForIndex and
103 | customMetricForIndex can be used as suffixes.
104 |
105 | @param list the impression list for this product impression
106 | @param index the index of this product in the impression list
107 | @param suffix the product impression suffix for this field
108 |
109 | @return an NSString representing this product impression field parameter
110 | */
111 | + (NSString *)productImpressionForList:(NSString *)list
112 | index:(NSUInteger)index
113 | suffix:(NSString *)Suffix;
114 |
115 | /*!
116 | Generates an enhanced ecommerce promotion field with an index and suffix.
117 |
118 | @param index the index of the promotion
119 | @param suffix the promotion suffix (such as kGAIPromotionId)
120 |
121 | @return an NSString representing this promotion field paramter
122 | */
123 | + (NSString *)promotionForIndex:(NSUInteger)index suffix:(NSString *)suffix;
124 | @end
125 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAIEcommerceProduct.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAIEcommerceProduct.h
3 | @abstract Google Analytics iOS SDK Hit Format Header
4 | @copyright Copyright 2014 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 |
9 | /*!
10 | * Class to construct product related information for a Google Analytics beacon. Use this class to
11 | * report information about products sold by merchants or impressions of products seen by users.
12 | * Instances of this class can be associated with both Product Actions and Product
13 | * Impression Lists.
14 | *
15 | * Typical usage:
16 | *
17 | * [tracker set:kGAIScreenName value:@"MyScreen"];
18 | * GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createScreenView];
19 | * GAIEcommerceProduct *product = [[GAIEcommerceProduct alloc] init];
20 | * [product setId:@""PID-1234""];
21 | * [product setName:@"Space Monkeys!"];
22 | * [product setPrice:@100];
23 | * [product setQuantity:@2];
24 | * [builder addProductImpression:product impressionList:@"listName"];
25 | * [tracker send:[builder build]];
26 | *
27 | */
28 | @interface GAIEcommerceProduct : NSObject
29 |
30 | /*!
31 | Sets the id that is used to identify a product in GA reports.
32 | */
33 | - (GAIEcommerceProduct *)setId:(NSString *)productId;
34 |
35 | /*!
36 | Sets the name that is used to indentify the product in GA reports.
37 | */
38 | - (GAIEcommerceProduct *)setName:(NSString *)productName;
39 |
40 | /*!
41 | Sets the brand associated with the product in GA reports.
42 | */
43 | - (GAIEcommerceProduct *)setBrand:(NSString *)productBrand;
44 |
45 | /*!
46 | Sets the category associated with the product in GA reports.
47 | */
48 | - (GAIEcommerceProduct *)setCategory:(NSString *)productCategory;
49 |
50 | /*!
51 | Sets the variant of the product.
52 | */
53 | - (GAIEcommerceProduct *)setVariant:(NSString *)productVariant;
54 |
55 | /*!
56 | Sets the price of the product.
57 | */
58 | - (GAIEcommerceProduct *)setPrice:(NSNumber *)productPrice;
59 |
60 | /*!
61 | Sets the quantity of the product. This field is usually not used with product impressions.
62 | */
63 | - (GAIEcommerceProduct *)setQuantity:(NSNumber *)productQuantity;
64 |
65 | /*!
66 | Sets the coupon code associated with the product. This field is usually not used with product
67 | impressions.
68 | */
69 | - (GAIEcommerceProduct *)setCouponCode:(NSString *)productCouponCode;
70 |
71 | /*!
72 | Sets the position of the product on the screen/product impression list, etc.
73 | */
74 | - (GAIEcommerceProduct *)setPosition:(NSNumber *)productPosition;
75 |
76 | /*!
77 | Sets the custom dimension associated with this product.
78 | */
79 | - (GAIEcommerceProduct *)setCustomDimension:(NSUInteger)index value:(NSString *)value;
80 |
81 | /*!
82 | Sets the custom metric associated with this product.
83 | */
84 | - (GAIEcommerceProduct *)setCustomMetric:(NSUInteger)index value:(NSNumber *)value;
85 |
86 | /*!
87 | Builds an NSDictionary of fields stored in this instance suitable for a product action. The
88 | index parameter is the index of this product in the product action list.
89 |
90 | Normally, users will have no need to call this method.
91 | */
92 | - (NSDictionary *)buildWithIndex:(NSUInteger)index;
93 |
94 | /*!
95 | Builds an NSDictionary of fields stored in this instance suitable for an impression list. The
96 | lIndex parameter is the index of the product impression list while the index parameter is the
97 | index of this product in that impression list.
98 |
99 | Normally, users will have no need to call this method.
100 | */
101 | - (NSDictionary *)buildWithListIndex:(NSUInteger)lIndex index:(NSUInteger)index;
102 | @end
103 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAIEcommerceProductAction.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAIProductAction.h
3 | @abstract Google Analytics iOS SDK Hit Format Header
4 | @copyright Copyright 2014 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 |
9 | /*!
10 | * Class to construct transaction/checkout or other product interaction related information for a
11 | * Google Analytics hit. Use this class to report information about products sold, viewed or
12 | * refunded. This class is intended to be used with GAIDictionaryBuilder.
13 | *
14 | * Typical usage:
15 | *
16 | * [tracker set:kGAIScreenName value:@"MyScreen"];
17 | * GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createScreenView];
18 | * GAIEcommerceProductAction *action = [[GAIEcommerceProductAction alloc] init];
19 | * [action setAction:kGAIPAPurchase];
20 | * [action setTransactionId:@"TT-1234"];
21 | * [action setRevenue:@3.14];
22 | * [action setCouponCode:@"EXTRA100"];
23 | * [builder setProductAction:action];
24 | * GAIEcommerceProduct *product = [[GAIEcommerceProduct alloc] init];
25 | * [product setId:@""PID-1234""];
26 | * [product setName:@"Space Monkeys!"];
27 | * [product setPrice:@100];
28 | * [product setQuantity:@2];
29 | * [builder addProduct:product];
30 | * [tracker send:[builder build]];
31 | *
32 | */
33 | @interface GAIEcommerceProductAction : NSObject
34 |
35 | /*!
36 | Sets the product action field for this product action. Valid values can be found in
37 | GAIEcommerceFields.h under "product action values".
38 | */
39 | - (GAIEcommerceProductAction *)setAction:(NSString *)productAction;
40 |
41 | /*!
42 | The unique id associated with the transaction. This value is used for kGAIPAPurchase and
43 | kGAIPARefund product actions.
44 | */
45 | - (GAIEcommerceProductAction *)setTransactionId:(NSString *)transactionId;
46 |
47 | /*!
48 | Sets the transaction's affiliation value. This value is used for kGAIPAPurchase and
49 | kGAIPARefund product actions.
50 | */
51 | - (GAIEcommerceProductAction *)setAffiliation:(NSString *)affiliation;
52 |
53 | /*!
54 | Sets the transaction's total revenue. This value is used for kGAIPAPurchase and kGAIPARefund
55 | product actions.
56 | */
57 | - (GAIEcommerceProductAction *)setRevenue:(NSNumber *)revenue;
58 |
59 | /*!
60 | Sets the transaction's total tax. This value is used for kGAIPAPurchase and kGAIPARefund
61 | product actions.
62 | */
63 | - (GAIEcommerceProductAction *)setTax:(NSNumber *)tax;
64 |
65 | /*!
66 | Sets the transaction's total shipping costs. This value is used for kGAIPAPurchase and
67 | kGAIPARefund product actions.
68 | */
69 | - (GAIEcommerceProductAction *)setShipping:(NSNumber *)shipping;
70 |
71 | /*!
72 | Sets the coupon code used in this transaction. This value is used for kGAIPAPurchase and
73 | kGAIPARefund product actions.
74 | */
75 | - (GAIEcommerceProductAction *)setCouponCode:(NSString *)couponCode;
76 |
77 | /*!
78 | Sets the checkout process's progress. This value is used for kGAICheckout and
79 | kGAICheckoutOptions product actions.
80 | */
81 | - (GAIEcommerceProductAction *)setCheckoutStep:(NSNumber *)checkoutStep;
82 |
83 | /*!
84 | Sets the option associated with the checkout. This value is used for kGAICheckout and
85 | kGAICheckoutOptions product actions.
86 | */
87 | - (GAIEcommerceProductAction *)setCheckoutOption:(NSString *)checkoutOption;
88 |
89 | /*!
90 | Sets the list name associated with the products in Google Analytics beacons. This value is
91 | used in kGAIPADetail and kGAIPAClick product actions.
92 | */
93 | - (GAIEcommerceProductAction *)setProductActionList:(NSString *)productActionList;
94 |
95 | /*!
96 | Sets the list source name associated with the products in Google Analytics beacons. This value
97 | is used in kGAIPADetail and kGAIPAClick product actions.
98 | */
99 | - (GAIEcommerceProductAction *)setProductListSource:(NSString *)productListSource;
100 |
101 | /*!
102 | Builds an NSDictionary of fields stored in this instance representing this product action.
103 |
104 | Normally, users will have no need to call this method.
105 | */
106 | - (NSDictionary *)build;
107 | @end
108 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAIEcommercePromotion.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAIEcommercePromotion.h
3 | @abstract Google Analytics iOS SDK Hit Format Header
4 | @copyright Copyright 2014 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 |
9 | /*!
10 | * Class to construct promotion related fields for Google Analytics hits. The fields from this class
11 | * can be used to represent internal promotions that run within an app, such as banners, banner ads
12 | * etc.
13 | *
14 | * Typical usage:
15 | *
16 | * GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createScreenView];
17 | * GAIEcommercePromotion *promotion = [[GAIEcommercePromotion alloc] init];
18 | * [promotion setId:@"PROMO-ID1234"];
19 | * [promotion setName:@"Home screen banner"];
20 | * [builder set:kGAIPromotionClick forKey:kGAIPromotionAction];
21 | * [builder addPromotion:promotion];
22 | * [tracker send:builder.build]];
23 | *
24 | */
25 | @interface GAIEcommercePromotion : NSObject
26 |
27 | /*!
28 | Sets the id that is used to identify a promotion in GA reports.
29 | */
30 | - (GAIEcommercePromotion *)setId:(NSString *)pid;
31 |
32 | /*!
33 | Sets the name that is used to identify a promotion in GA reports.
34 | */
35 | - (GAIEcommercePromotion *)setName:(NSString *)name;
36 |
37 | /*!
38 | Sets the name of the creative associated with the promotion.
39 | */
40 | - (GAIEcommercePromotion *)setCreative:(NSString *)creative;
41 |
42 | /*!
43 | Sets the position of the promotion.
44 | */
45 | - (GAIEcommercePromotion *)setPosition:(NSString *)position;
46 |
47 | /*!
48 | Builds an NSDictionary of fields stored in this instance. The index parameter is the
49 | index of this promotion in that promotion list.
50 |
51 | Normally, users will have no need to call this method.
52 | */
53 | - (NSDictionary *)buildWithIndex:(NSUInteger)index;
54 | @end
55 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAIFields.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAIFields.h
3 | @abstract Google Analytics iOS SDK Hit Format Header
4 | @copyright Copyright 2013 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 |
9 | /*!
10 | These fields can be used for the wire format parameter names required by
11 | the |GAITracker| get, set and send methods as well as the set methods in the
12 | |GAIDictionaryBuilder| class.
13 | */
14 | extern NSString *const kGAIUseSecure;
15 |
16 | extern NSString *const kGAIHitType;
17 | extern NSString *const kGAITrackingId;
18 | extern NSString *const kGAIClientId;
19 | extern NSString *const kGAIDataSource;
20 | extern NSString *const kGAIAnonymizeIp;
21 | extern NSString *const kGAISessionControl;
22 | extern NSString *const kGAIDeviceModelVersion;
23 | extern NSString *const kGAIScreenResolution;
24 | extern NSString *const kGAIViewportSize;
25 | extern NSString *const kGAIEncoding;
26 | extern NSString *const kGAIScreenColors;
27 | extern NSString *const kGAILanguage;
28 | extern NSString *const kGAIJavaEnabled;
29 | extern NSString *const kGAIFlashVersion;
30 | extern NSString *const kGAINonInteraction;
31 | extern NSString *const kGAIReferrer;
32 | extern NSString *const kGAILocation;
33 | extern NSString *const kGAIHostname;
34 | extern NSString *const kGAIPage;
35 | extern NSString *const kGAIDescription; // synonym for kGAIScreenName
36 | extern NSString *const kGAIScreenName; // synonym for kGAIDescription
37 | extern NSString *const kGAITitle;
38 | extern NSString *const kGAIAdMobHitId;
39 | extern NSString *const kGAIAppName;
40 | extern NSString *const kGAIAppVersion;
41 | extern NSString *const kGAIAppId;
42 | extern NSString *const kGAIAppInstallerId;
43 | extern NSString *const kGAIUserId;
44 |
45 | extern NSString *const kGAIEventCategory;
46 | extern NSString *const kGAIEventAction;
47 | extern NSString *const kGAIEventLabel;
48 | extern NSString *const kGAIEventValue;
49 |
50 | extern NSString *const kGAISocialNetwork;
51 | extern NSString *const kGAISocialAction;
52 | extern NSString *const kGAISocialTarget;
53 |
54 | extern NSString *const kGAITransactionId;
55 | extern NSString *const kGAITransactionAffiliation;
56 | extern NSString *const kGAITransactionRevenue;
57 | extern NSString *const kGAITransactionShipping;
58 | extern NSString *const kGAITransactionTax;
59 | extern NSString *const kGAICurrencyCode;
60 |
61 | extern NSString *const kGAIItemPrice;
62 | extern NSString *const kGAIItemQuantity;
63 | extern NSString *const kGAIItemSku;
64 | extern NSString *const kGAIItemName;
65 | extern NSString *const kGAIItemCategory;
66 |
67 | extern NSString *const kGAICampaignSource;
68 | extern NSString *const kGAICampaignMedium;
69 | extern NSString *const kGAICampaignName;
70 | extern NSString *const kGAICampaignKeyword;
71 | extern NSString *const kGAICampaignContent;
72 | extern NSString *const kGAICampaignId;
73 | extern NSString *const kGAICampaignAdNetworkClickId;
74 | extern NSString *const kGAICampaignAdNetworkId;
75 |
76 | extern NSString *const kGAITimingCategory;
77 | extern NSString *const kGAITimingVar;
78 | extern NSString *const kGAITimingValue;
79 | extern NSString *const kGAITimingLabel;
80 |
81 | extern NSString *const kGAIExDescription;
82 | extern NSString *const kGAIExFatal;
83 |
84 | extern NSString *const kGAISampleRate;
85 |
86 | extern NSString *const kGAIIdfa;
87 | extern NSString *const kGAIAdTargetingEnabled;
88 |
89 | // hit types
90 | extern NSString *const kGAIAppView DEPRECATED_MSG_ATTRIBUTE("Use kGAIScreenView instead.");
91 | extern NSString *const kGAIScreenView;
92 | extern NSString *const kGAIEvent;
93 | extern NSString *const kGAISocial;
94 | extern NSString *const kGAITransaction;
95 | extern NSString *const kGAIItem;
96 | extern NSString *const kGAIException;
97 | extern NSString *const kGAITiming;
98 |
99 | /*!
100 | This class provides several fields and methods useful as wire format parameter
101 | names. The methods are used for wire format parameter names that are indexed.
102 | */
103 |
104 | @interface GAIFields : NSObject
105 |
106 | /*!
107 | Generates the correct parameter name for a content group with an index.
108 |
109 | @param index the index of the content group.
110 |
111 | @return an NSString representing the content group parameter for the index.
112 | */
113 | + (NSString *)contentGroupForIndex:(NSUInteger)index;
114 |
115 | /*!
116 | Generates the correct parameter name for a custon dimension with an index.
117 |
118 | @param index the index of the custom dimension.
119 |
120 | @return an NSString representing the custom dimension parameter for the index.
121 | */
122 | + (NSString *)customDimensionForIndex:(NSUInteger)index;
123 |
124 | /*!
125 | Generates the correct parameter name for a custom metric with an index.
126 |
127 | @param index the index of the custom metric.
128 |
129 | @return an NSString representing the custom metric parameter for the index.
130 | */
131 | + (NSString *)customMetricForIndex:(NSUInteger)index;
132 |
133 | @end
134 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAILogger.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAILogger.h
3 | @abstract Google Analytics iOS SDK Source
4 | @copyright Copyright 2011 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 |
9 | typedef NS_ENUM(NSUInteger, GAILogLevel) {
10 | kGAILogLevelNone = 0,
11 | kGAILogLevelError = 1,
12 | kGAILogLevelWarning = 2,
13 | kGAILogLevelInfo = 3,
14 | kGAILogLevelVerbose = 4
15 | };
16 |
17 | /*!
18 | Protocol to be used for logging debug and informational messages from the SDK.
19 | Implementations of this protocol can be provided to the |GAI| class,
20 | to be used as the logger by the SDK. See the |logger| property in GAI.h.
21 | */
22 | @protocol GAILogger
23 | @required
24 |
25 | /*!
26 | Only messages of |logLevel| and below are logged.
27 | */
28 | @property (nonatomic, assign) GAILogLevel logLevel;
29 |
30 | /*!
31 | Logs message with log level |kGAILogLevelVerbose|.
32 | */
33 | - (void)verbose:(NSString *)message;
34 |
35 | /*!
36 | Logs message with log level |kGAILogLevelInfo|.
37 | */
38 | - (void)info:(NSString *)message;
39 |
40 | /*!
41 | Logs message with log level |kGAILogLevelWarning|.
42 | */
43 | - (void)warning:(NSString *)message;
44 |
45 | /*!
46 | Logs message with log level |kGAILogLevelError|.
47 | */
48 | - (void)error:(NSString *)message;
49 | @end
50 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAITrackedViewController.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAITrackedViewController.h
3 | @abstract Google Analytics for iOS Tracked View Controller Header
4 | @copyright Copyright 2012 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 | #import
9 |
10 | @protocol GAITracker;
11 |
12 | /*!
13 | Extends UIViewController to generate Google Analytics screenview calls
14 | whenever the view appears; this is done by overriding the `viewDidAppear:`
15 | method. The screen name must be set for any tracking calls to be made.
16 |
17 | By default, this will use [GAI defaultTracker] for tracking calls, but one can
18 | override this by setting the tracker property.
19 | */
20 | @interface GAITrackedViewController : UIViewController
21 |
22 | /*!
23 | The tracker on which view tracking calls are be made, or `nil`, in which case
24 | [GAI defaultTracker] will be used.
25 | */
26 | @property(nonatomic, assign) id tracker;
27 | /*!
28 | The screen name, for purposes of Google Analytics tracking. If this is `nil`,
29 | no tracking calls will be made.
30 | */
31 | @property(nonatomic, copy) NSString *screenName;
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/GAITracker.h:
--------------------------------------------------------------------------------
1 | /*!
2 | @header GAITracker.h
3 | @abstract Google Analytics iOS SDK Tracker Header
4 | @copyright Copyright 2013 Google Inc. All rights reserved.
5 | */
6 |
7 | #import
8 |
9 | /*!
10 | Google Analytics tracking interface. Obtain instances of this interface from
11 | [GAI trackerWithTrackingId:] to track screens, events, transactions, timing,
12 | and exceptions. The implementation of this interface is thread-safe, and no
13 | calls are expected to block or take a long time. All network and disk activity
14 | will take place in the background.
15 | */
16 | @protocol GAITracker
17 |
18 | /*!
19 | Name of this tracker.
20 | */
21 | @property(nonatomic, readonly) NSString *name;
22 |
23 | /*!
24 | Allow collection of IDFA and related fields if set to true. Default is false.
25 | */
26 | @property(nonatomic) BOOL allowIDFACollection;
27 |
28 | /*!
29 | Set a tracking parameter.
30 |
31 | @param parameterName The parameter name.
32 |
33 | @param value The value to set for the parameter. If this is nil, the
34 | value for the parameter will be cleared.
35 | */
36 | - (void)set:(NSString *)parameterName
37 | value:(NSString *)value;
38 |
39 | /*!
40 | Get a tracking parameter.
41 |
42 | @param parameterName The parameter name.
43 |
44 | @returns The parameter value, or nil if no value for the given parameter is
45 | set.
46 | */
47 | - (NSString *)get:(NSString *)parameterName;
48 |
49 | /*!
50 | Queue tracking information with the given parameter values.
51 |
52 | @param parameters A map from parameter names to parameter values which will be
53 | set just for this piece of tracking information, or nil for none.
54 | */
55 | - (void)send:(NSDictionary *)parameters;
56 |
57 | @end
58 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/TAGContainer.h:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All rights reserved.
2 | /** @file */
3 |
4 | #import
5 |
6 | @class TAGContainer;
7 |
8 | /**
9 | * Refresh types for container callback.
10 | */
11 | typedef enum {
12 | /** Refresh from a saved container. */
13 | kTAGContainerCallbackRefreshTypeSaved,
14 |
15 | /** Refresh from the network. */
16 | kTAGContainerCallbackRefreshTypeNetwork,
17 | } TAGContainerCallbackRefreshType;
18 |
19 | /**
20 | * Ways in which a refresh can fail.
21 | */
22 | typedef enum {
23 | /** There is no saved container. */
24 | kTAGContainerCallbackRefreshFailureNoSavedContainer,
25 |
26 | /** An I/O error prevented refreshing the container. */
27 | kTAGContainerCallbackRefreshFailureIoError,
28 |
29 | /** No network is available. */
30 | kTAGContainerCallbackRefreshFailureNoNetwork,
31 |
32 | /** A network error has occurred. */
33 | kTAGContainerCallbackRefreshFailureNetworkError,
34 |
35 | /** An error on the server. */
36 | kTAGContainerCallbackRefreshFailureServerError,
37 |
38 | /** An error that cannot be categorized. */
39 | kTAGContainerCallbackRefreshFailureUnknownError
40 | } TAGContainerCallbackRefreshFailure;
41 |
42 | /**
43 | * A protocol implemented by the application to execute a custom tag.
44 | */
45 | @protocol TAGFunctionCallTagHandler
46 | /**
47 | * Handler is given the tag name and a dictionary of named parameters.
48 | *
49 | * @param tagName The same name by which the handler was registered. It
50 | * is provided as a convenience to allow a single handler to be registered
51 | * for multiple function call tags.
52 | * @param parameters The named parameters for the function call. The
53 | * dictionary may contain NSString
, NSNumber
54 | * (double, int, or boolean), NSDictionary
, or
55 | * NSArray
.
56 | * @return The evaluated result, which can be an NSString
or
57 | * NSNumber
.
58 | */
59 | - (void)execute:(NSString *)tagName parameters:(NSDictionary *)parameters;
60 |
61 | @end
62 |
63 | /**
64 | * A protocol implemented by the application to calculate the value of a
65 | * function call macro.
66 | */
67 | @protocol TAGFunctionCallMacroHandler
68 | /**
69 | * Returns an object which is the calculated value of the macro.
70 | * Handler is given the macro name and a dictionary of named parameters.
71 | *
72 | * @param macroName The same name by which the handler was registered. It
73 | * is provided as a convenience to allow a single handler to be registered
74 | * for multiple function call macros.
75 | * @param parameters The named parameters for the function call. The
76 | * dictionary may contain NSString
, NSNumber
77 | * (double, int, or boolean), NSDictionary
, or
78 | * NSArray
.
79 | * @return The evaluated result, which can be an NSString
or
80 | * NSNumber
.
81 | */
82 | - (id)valueForMacro:(NSString *)macroName parameters:(NSDictionary *)parameters;
83 |
84 | @end
85 |
86 | /**
87 | * A protocol that a client may implement to receive
88 | * information when the contents of the container has been successfully
89 | * loaded or failed to load.
90 | *
91 | * You may rely on the fact that
92 | * TAGContainerCallback::containerRefreshBegin:refreshType:
93 | * will be called for a given @ref TAGContainerCallbackRefreshType before its
94 | * associated TAGContainerCallback::containerRefreshSuccess:refreshType: or
95 | * TAGContainerCallback::containerRefreshFailure:failure:refreshType:, but
96 | * shouldn't make any other assumptions about ordering. In particular, there
97 | * may be two refreshes outstanding at once
98 | * (both @ref kTAGContainerCallbackRefreshTypeSaved and
99 | * @ref kTAGContainerCallbackRefreshTypeNetwork), or a
100 | * @ref kTAGContainerCallbackRefreshTypeSaved refresh
101 | * may occur before a @ref kTAGContainerCallbackRefreshTypeNetwork refresh.
102 | */
103 | @protocol TAGContainerCallback
104 |
105 | /**
106 | * Called before the refresh is about to begin.
107 | *
108 | * @param container The container being refreshed.
109 | * @param refreshType The type of refresh which is starting.
110 | */
111 | - (void)containerRefreshBegin:(TAGContainer *)container
112 | refreshType:(TAGContainerCallbackRefreshType)refreshType;
113 |
114 | /**
115 | * Called when a refresh has successfully completed for the given refresh type.
116 | *
117 | * @param container The container being refreshed.
118 | * @param refreshType The type of refresh which completed successfully.
119 | */
120 | - (void)containerRefreshSuccess:(TAGContainer *)container
121 | refreshType:(TAGContainerCallbackRefreshType)refreshType;
122 |
123 | /**
124 | * Called when a refresh has failed to complete for the given refresh type.
125 | *
126 | * @param container The container being refreshed.
127 | * @param failure The reason for the refresh failure.
128 | * @param refreshType The type of refresh which failed.
129 | */
130 | - (void)containerRefreshFailure:(TAGContainer *)container
131 | failure:(TAGContainerCallbackRefreshFailure)failure
132 | refreshType:(TAGContainerCallbackRefreshType)refreshType;
133 |
134 | @end
135 |
136 | /**
137 | * A class that provides access to container values.
138 | * Container objects must be created via @ref TAGManager.
139 | * Once a container is created, it can be queried for key values which
140 | * may depend on rules established for the container.
141 | * A container is automatically refreshed periodically (every 12 hours), but
142 | * can also be manually refreshed with TAGContainer::refresh.
143 | */
144 | @interface TAGContainer : NSObject
145 |
146 | /**
147 | * The ID for this container.
148 | */
149 | @property(readonly, nonatomic, copy) NSString *containerId;
150 |
151 | /**
152 | * The last time (in milliseconds since midnight Jan 1, 1970 UTC) that this
153 | * container was refreshed from the network.
154 | */
155 | @property(atomic, readonly) double lastRefreshTime;
156 |
157 | // @cond
158 | /**
159 | * Containers should be instantiated through TAGManager or TAGContainerOpener.
160 | */
161 | - (id)init __attribute__((unavailable));
162 | // @endcond
163 |
164 | /**
165 | * Returns a BOOL
representing the configuration value for the
166 | * given key. If the container has no value for this key, NO will be returned.
167 | *
168 | * @param key The key to lookup for the configuration value.
169 | */
170 | - (BOOL)booleanForKey:(NSString *)key;
171 |
172 | /**
173 | * Returns a double
representing the configuration value for the
174 | * given key. If the container has no value for this key, 0.0 will be returned.
175 | *
176 | * @param key The key to lookup for the configuration value.
177 | */
178 | - (double)doubleForKey:(NSString *)key;
179 |
180 | /**
181 | * Returns an int64_t
representing the configuration value for the
182 | * given key. If the container has no value for this key, 0 will be returned.
183 | *
184 | * @param key The key to lookup for the configuration value.
185 | */
186 | - (int64_t)int64ForKey:(NSString *)key;
187 |
188 | /**
189 | * Returns an NSString
to represent the configuration value for the
190 | * given key. If the container has no value for this key, an empty string
191 | * will be returned.
192 | *
193 | * @param key The key to lookup for the configuration value.
194 | */
195 | - (NSString *)stringForKey:(NSString *)key;
196 |
197 | /**
198 | * Requests that this container be refreshed from the network.
199 | * This call is asynchronous, so the refresh may take place on another thread.
200 | */
201 | - (void)refresh;
202 |
203 | /**
204 | * Closes this container so that it will no longer be refreshed.
205 | * After closing, don't make any other calls to the container.
206 | */
207 | - (void)close;
208 |
209 | /**
210 | * Returns whether this is a default container, or one refreshed from the
211 | * server.
212 | */
213 | - (BOOL)isDefault;
214 |
215 | /**
216 | * Registers the given macro handler to handle a given function call macro.
217 | *
218 | * @param handler The handler for the macro. If the parameter is
219 | * nil, the method unregisters any existing handler for that macro.
220 | * @param macroName The name of the macro which is being registered.
221 | */
222 | - (void)registerFunctionCallMacroHandler:(id)handler
223 | forMacro:(NSString *)macroName;
224 |
225 | /**
226 | * Given the name of a function call macro, returns the handler registered for
227 | * the macro.
228 | *
229 | * @return The handler registered for the macro.
230 | */
231 | - (id)
232 | functionCallMacroHandlerForMacro:(NSString *)functionCallMacroName;
233 |
234 | /**
235 | * Registers the given tag handler to handle a given function call tag.
236 | *
237 | * @param handler The handler for the tag. If the parameter is
238 | * nil, the method unregisters any existing handler for that tag.
239 | * @param tagName The name of the tag which is being registered.
240 | */
241 | - (void)registerFunctionCallTagHandler:(id)handler
242 | forTag:(NSString *)tagName;
243 |
244 | /**
245 | * Given the name of a function call tag, returns the handler registered for
246 | * the tag.
247 | *
248 | * @return The handler registered for the tag.
249 | */
250 | - (id)functionCallTagHandlerForTag:(NSString *)functionCallTagName;
251 |
252 | @end
253 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/TAGDataLayer.h:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | /**
4 | * Represents an object missing in an NSArray. If the data layer currently
5 | * contains:
6 |
7 | * {
8 | * myArray: [1, 2, 3]
9 | * }
10 |
11 | * and you want to update the third element to 5, while leaving other elements
12 | * alone, you'd use kTAGDataLayerNotPresent
as the 1st and 2nd
13 | * elements (if you were to use a NSNull
object,
14 | * the 1st and 2nd elements would be replaced).
15 | *
16 | * So, after executing:
17 |
18 | * [dataLayer push:@{@"myArray",
19 | * @[kTAGDataLayerObjectNotPresent, kTAGDataLayerObjectNotPresent, @5}];
20 |
21 | * then, the data layer will contain:
22 |
23 | * {
24 | * myArray: [1, 2, 5]
25 | * }
26 |
27 | */
28 | extern id kTAGDataLayerObjectNotPresent;
29 |
30 | /**
31 | * The data layer is a dictionary holding generic information about the
32 | * application. It uses a standard set of keys so it can be read by any party
33 | * that understands the specification. The data layer state is updated
34 | * through its API. For example, an app might start with the following
35 | * dataLayer:
36 |
37 | * {
38 | * title: "Original screen title"
39 | * }
40 |
41 | *
42 | * As the state/data of an app can change, the app can update the dataLayer with a call such as:
43 |
44 | * [dataLayer push:@{@"title": @"New screen title"}];
45 |
46 | * Now the data layer contains:
47 |
48 | * {
49 | * title: "New screen title"
50 | * }
51 |
52 | * After another push happens:
53 |
54 | * [dataLayer push:@{@"xyz": @3}];
55 |
56 | * The dataLayer contains:
57 |
58 | * {
59 | * "title": "New screen title",
60 | * "xyz": 3
61 | * }
62 |
63 | * The following example demonstrates how array and map merging works. If the
64 | * original dataLayer contains:
65 |
66 | * {
67 | * "items": @[@"item1", [NSNull null], @"item2", @{@"a": @"aValue", @"b": @"bValue"}]
68 | * }
69 |
70 | * After this push happens:
71 |
72 | * [dataLayer push:@{@"items":
73 | * @[[NSNull null], @"item6", kTAGDataLayerObjectNotPresent, @{@"a": [NSNull null]}]}
74 |
75 | * The dataLayer contains:
76 |
77 | * {
78 | * "items": @[[NSNull null], @"item6", @"item2", @{@"a": [NSNull null], @"b": @"bValue"}]}
79 | * }
80 |
81 | * Pushes happen synchronously; after the push, changes have been reflected
82 | * in the model.
83 | *
When an event
key is pushed to the data layer, rules for tags
84 | * are evaluated and any tags matching this event will fire.
85 | * For example, given a container with a tag whose firing rules is that "event"
86 | * is equal to "openScreen", after this push:
87 |
88 | * [dataLayer push:@{@"event", @"openScreen"}];
89 |
90 | * that tag will fire.
91 | */
92 | @interface TAGDataLayer : NSObject
93 |
94 | @property(readonly, nonatomic) NSDictionary *dataLayer;
95 |
96 | /**
97 | * Pushes a key/value pair to the data layer. This is just a convenience
98 | * method that calls push:@{key: value}
.
99 | */
100 | - (void)pushValue:(id)value forKey:(id)key;
101 |
102 | /**
103 | * Merges the given update
object into the existing data model,
104 | * calling any listeners with the update (after the merge occurs).
105 | *
106 | * It's valid for values in the dictionary (or embedded Arrays) to be
107 | * of type NSNull
.
108 | * If you want to represent a missing value (like an empty index in a List),
109 | * use the kTAGDataLayerObjectNotPresent
object.
110 | *
111 | *
This is normally a synchronous call.
112 | * However, if, while the thread is executing the push, another push happens
113 | * from the same thread, then that second push is asynchronous (the second push
114 | * will return before changes have been made to the data layer). This second
115 | * push from the same thread can occur, for example, if a data layer push is
116 | * made in response to a tag firing. However, all updates will be processed
117 | * before the outermost push returns.
118 | *
If the update
contains the key event
, rules
119 | * will be evaluated and matching tags will fire.
120 | *
121 | * @param update The update object to process
122 | */
123 | - (void)push:(NSDictionary*)update;
124 |
125 | /**
126 | * Returns the object in the model associated with the given key.
127 | * If key isn't present, returns nil
. If
128 | * key
is present, but NSNull
, returns
129 | * NSNull
.
130 | *
131 | *
The key can can have embedded periods. For example:
132 | * a key of "a.b.c"
returns the value of the "c" key in
133 | * the dictionary with key "b" in the dictionary with key "a" in the model.
134 | */
135 | - (id)get:(NSString*)key;
136 |
137 | @end
138 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/TAGLogger.h:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All rights reserved.
2 | /** @file */
3 |
4 | #import
5 |
6 | /**
7 | * Log Level setting.
8 | */
9 | typedef enum {
10 | /** Log level of Verbose. */
11 | kTAGLoggerLogLevelVerbose,
12 |
13 | /** Log level of Debug. */
14 | kTAGLoggerLogLevelDebug,
15 |
16 | /** Log level of Info. */
17 | kTAGLoggerLogLevelInfo,
18 |
19 | /** Log level of Warning. */
20 | kTAGLoggerLogLevelWarning,
21 |
22 | /** Log level of Error. */
23 | kTAGLoggerLogLevelError,
24 |
25 | /** Log level of None. */
26 | kTAGLoggerLogLevelNone
27 | } TAGLoggerLogLevelType;
28 |
29 | /**
30 | * A protocol for error/warning/info/debug/verbose logging.
31 | *
32 | * By default, Google Tag Manager logs error/warning messages and
33 | * ignores info/debug/verbose messages. You can install your own logger
34 | * by setting the TAGManager::logger property.
35 | */
36 | @protocol TAGLogger
37 |
38 | /**
39 | * Logs an error message.
40 | *
41 | * @param message The error message to be logged.
42 | */
43 | - (void)error:(NSString *)message;
44 |
45 | /**
46 | * Logs a warning message.
47 | *
48 | * @param message The warning message to be logged.
49 | */
50 | - (void)warning:(NSString *)message;
51 |
52 | /**
53 | * Logs an info message.
54 | *
55 | * @param message The info message to be logged.
56 | */
57 | - (void)info:(NSString *)message;
58 |
59 | /**
60 | * Logs a debug message.
61 | *
62 | * @param message The debug message to be logged.
63 | */
64 | - (void)debug:(NSString *)message;
65 |
66 | /**
67 | * Logs a verbose message.
68 | *
69 | * @param message The verbose message to be logged.
70 | */
71 | - (void)verbose:(NSString *)message;
72 |
73 | /**
74 | * Sets the log level. It is up to the implementation how the log level is used,
75 | * but log messages outside the log level should not be output.
76 | */
77 | - (void)setLogLevel:(TAGLoggerLogLevelType)logLevel;
78 |
79 | /**
80 | * Returns the current log level.
81 | */
82 | - (TAGLoggerLogLevelType)logLevel;
83 |
84 | @end
85 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/TAGManager.h:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All rights reserved.
2 | /** @file */
3 |
4 | #import
5 |
6 | #import "TAGContainer.h"
7 | #import "TAGLogger.h"
8 |
9 | @class TAGDataLayer;
10 |
11 | /**
12 | * Mode for refreshing the container.
13 | */
14 | typedef enum {
15 | /**
16 | * In this mode, containers are automatically refreshed from network every 12
17 | * hours. Developers can also call TAGContainer::refresh to manually
18 | * refresh containers.
19 | *
20 | * This is the default mode.
21 | */
22 | kTAGRefreshModeStandard,
23 | /**
24 | * In this mode, the default container is always used (the container will not load a version
25 | * from network, or from disk).
26 | *
27 | * This mode allows developers to add new key/value pairs locally and
28 | * then to use the Plist or JSON default container to test them quickly
29 | * without having to add those key/value pairs to the container using
30 | * the GTM UI.
31 | *
32 | * This mode is intended for development only and not for shipping code.
33 | */
34 | kTAGRefreshModeDefaultContainer,
35 | } TAGRefreshMode;
36 |
37 |
38 | typedef NS_ENUM(NSUInteger, TAGDispatchResult) {
39 | kTAGDispatchNoData,
40 | kTAGDispatchGood,
41 | kTAGDispatchError
42 | };
43 |
44 | /**
45 | * A class that is the mobile implementation of Google Tag Manager (GTM).
46 | *
47 | * Sample usage:
48 |
49 | * TAGContainer *container =
50 | * [[TAGManager instance] openContainerById:myContainerId];
51 | * NSString *value = [container stringForKey:@"myKey"];
52 | *
53 | * TAGDataLayer *dataLayer =
54 | * [[TAGManager instance] dataLayer];
55 | * [dataLayer push:@{@"event": @"openScreen",
56 | * @"screenName": @"Main Page"}];
57 |
58 | *
59 | * A container is a collection of macros, rules, and tags. It is created within
60 | * the GTM application (http://www.google.com/tagmanager), and is assigned
61 | * a container ID. This container ID is the one used within this API.
62 | *
63 | * The TAGContainer class provides methods for retrieving
64 | * macro values given the macro name. The routines
65 | * TAGContainer::booleanForKey:, TAGContainer::doubleForKey:,
66 | * TAGContainer::int64ForKey:, TAGContainer::stringForKey: return the current
67 | * value for the value collection macro name, depending on the rules associated with that macro
68 | * in the container.
69 | *
70 | * As an example, if your container has a value collection macro with a key "speed" whose
71 | * value is 32, and the enabling rule is Language is "en"; and another value collection macro
72 | * with a key "speed" whose value is 45, and the enabling rule is Language is not "en",
73 | * then making the following call:
74 | *
75 |
76 | * [container longForKey:\@"speed"]
77 |
78 | *
79 | * will return either 32 if the current language of the device is English, or
80 | * 45 otherwise.
81 |
82 | * The data layer is a map holding generic information about the application.
83 | * The TAGDataLayer class provides methods to push and retrieve data from
84 | * the data layer. Pushing an event
key to the data layer will
85 | * cause tags that match this event to fire.
86 | *
87 | * An initial version of the container is bundled with the application. It
88 | * should be placed as a resource in the bundle with name
89 | * containerId
where containerId
is the same container
90 | * ID you will use within this API. When you call
91 | * TAGManager::openContainerById:callback:, the container will be
92 | * returned with those bundled rules/tags/macros. You will create the container
93 | * in the UI and use the Download button to download it.
94 | *
95 | * You can modify the container in the UI and publish a new version. In that
96 | * case, the next time the mobile app refreshes the container from the network
97 | * (currently every 12 hours),
98 | * it will get that new version. When you call one of the get... routines, the
99 | * value will be computed using the most recent rules.
100 | *
101 | * The downloaded container is saved locally. When you call
102 | * TAGManager::openContainerById:callback:, it will first load the default
103 | * container, and will then asynchronously load any saved container. If none is
104 | * found or if it is older than 12 hours, it will try to retrieve a newer version
105 | * from the network. You can find the status of those asynchronous loads by
106 | * passing a TAGContainerCallback to TAGManager::openContainerById:callback:.
107 | *
108 | * Sometimes you may want to block until either a non-default container is
109 | * available, or until a recent fresh container is available. You can do that
110 | * by using the callbacks in TAGManager::openContainerById:callback: or use
111 | * TAGContainerOpener.
112 | *
113 | * When you are finished with a container, call TAGContainer::close.
114 | */
115 | @interface TAGManager : NSObject
116 |
117 | /**
118 | * The logger to use for Google Tag Manager SDK. By default, Google Tag Manager
119 | * logs error/warning messages and ignores info/debug/verbose messages.
120 | * You can use your own customized logger by setting this property.
121 | */
122 | @property(nonatomic, strong) id logger;
123 |
124 | /**
125 | * The refresh mode used for Google Tag Manager SDK. Setting this to
126 | * @ref kTAGRefreshModeDefaultContainer allows the refresh
127 | * method to use only the default container for development purposes. Default is
128 | * @ref kTAGRefreshModeStandard.
129 | */
130 | @property(nonatomic) TAGRefreshMode refreshMode;
131 |
132 | /**
133 | * Call TAGDataLayer::push: method to push events and other data.
134 | */
135 | @property(nonatomic, readonly, strong) TAGDataLayer *dataLayer;
136 |
137 | /**
138 | * Returns a container.
139 | * Usually the returned container will be empty, but the loading will happen
140 | * asynchronously, so the returned container may be refreshed before it
141 | * is returned, after it is returned, or may never be refreshed if, for example,
142 | * there is no network connection during the lifetime of the container.
143 | *
144 | * Callback will be called as various things happen for
145 | * the container. At a minimum, TAGManager::openContainerById:callback: will
146 | * attempt to load a saved version of the container. If there is no saved
147 | * version, or if the saved version is out of date, attempt will be made to
148 | * load from the network.
149 | *
150 | * If TAGManager::openContainerById:callback: is called a second time for a
151 | * given containerId
, nil
will be returned unless
152 | * the previous opened container has already been closed.
153 | *
154 | * @param containerId The ID of the container to open.
155 | * @param callback An object whose various methods will be called during the
156 | * loading process. Note that the methods may be called from different
157 | * threads. In addition, they may be called before
158 | * TAGManager::openContainerById:callback: returns.
159 | * @return The opened container.
160 | */
161 | - (TAGContainer *)openContainerById:(NSString *)containerId
162 | callback:(id )callback;
163 |
164 | /**
165 | * Returns the container associated with the given containerId
;
166 | * returns nil
if the container is not already open.
167 | */
168 | - (TAGContainer *)getContainerById:(NSString *)containerId;
169 |
170 | /**
171 | * Previews the app with the input url.
172 | *
173 | * The valid url must start with the following:
174 |
175 | * tagmanager.c.\://preview/p?id=
176 |
177 | * where <app_name> is the application name.
178 | *
179 | * @param url The preview url.
180 | * @return YES if the url is a valid tagmanager preview url.
181 | */
182 | - (BOOL)previewWithUrl:(NSURL *)url;
183 |
184 | /**
185 | * Gets the singleton instance of the TAGManager class, creating it if
186 | * necessary.
187 | *
188 | * @return The singleton instance of TAGManager.
189 | */
190 | + (TAGManager *)instance;
191 |
192 |
193 | /**
194 | * Dispatches any pending network traffic generated by tags (arbitrary pixels, analytics beacons,
195 | * etc).
196 | */
197 | - (void)dispatch;
198 |
199 | /**
200 | * If this value is positive, tracking information will be automatically
201 | * dispatched every dispatchInterval seconds.
202 | * Otherwise, tracking information must be sent manually by
203 | * calling dispatch.
204 | *
205 | * By default, this is set to `120`, which indicates tracking information will
206 | * be dispatched automatically every 120 seconds.
207 | */
208 | @property(nonatomic, assign) NSTimeInterval dispatchInterval;
209 |
210 | /**
211 | * Dispatches the next pending network traffic in the queue, calling completionHandler when
212 | * the request has either been sent (returning kTAGDispatchGood) or an error has resulted
213 | * (returning kTAGDispatchError). If there is no network connection or there is no data to send,
214 | * kTAGDispatchNoData is returned.
215 | *
216 | * Calling this method with a nil completionHandler is the same as calling dispatch.
217 | *
218 | * This method can be used for background data fetching in iOS 7.0 or later.
219 | *
220 | * It would be wise to call this when the application is exiting to initiate the submission of any
221 | * unsubmitted tracking information.
222 | */
223 | - (void)dispatchWithCompletionHandler:(void (^)(TAGDispatchResult))completionHandler;
224 |
225 | @end
226 |
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/libAdIdAccess.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/idehub/react-native-google-analytics-bridge/e6623b18a54cd7bb9166cd41a0b370efd7e0687b/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/libAdIdAccess.a
--------------------------------------------------------------------------------
/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/libGoogleAnalyticsServices.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/idehub/react-native-google-analytics-bridge/e6623b18a54cd7bb9166cd41a0b370efd7e0687b/ios/RCTGoogleAnalyticsBridge/google-analytics-lib/libGoogleAnalyticsServices.a
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-google-analytics-bridge",
3 | "version": "7.1.0",
4 | "description": "React Native bridge for using native Google Analytics libraries on iOS and Android",
5 | "main": "./dist/index.js",
6 | "types": "./dist/index.d.ts",
7 | "scripts": {
8 | "prepublishOnly": "yarn run build-all",
9 | "test": "echo \"Error: no test yet!\" && exit 0",
10 | "build": "tsc",
11 | "build-watch": "tsc --watch",
12 | "docs": "documentation readme dist/** --section=\"JavaScript API\"",
13 | "build-all": "rm -rf dist && yarn run build && yarn run docs",
14 | "precommit": "yarn run build"
15 | },
16 | "repository": {
17 | "type": "git",
18 | "url": "git+https://github.com/idehub/react-native-google-analytics-bridge.git"
19 | },
20 | "author": "Idéhub AS",
21 | "license": "MIT",
22 | "bugs": {
23 | "url": "https://github.com/idehub/react-native-google-analytics-bridge/issues"
24 | },
25 | "homepage": "https://github.com/idehub/react-native-google-analytics-bridge#readme",
26 | "keywords": [
27 | "react",
28 | "native",
29 | "google",
30 | "analytics",
31 | "tracking",
32 | "native",
33 | "bridge",
34 | "events",
35 | "screen",
36 | "hits",
37 | "react-native",
38 | "ios",
39 | "android"
40 | ],
41 | "rnpm": {
42 | "ios": {
43 | "sharedLibraries": [
44 | "CoreData.framework",
45 | "SystemConfiguration.framework",
46 | "libz.tbd",
47 | "libsqlite3.0.tbd"
48 | ]
49 | }
50 | },
51 | "devDependencies": {
52 | "@types/react": "16.3.1",
53 | "@types/react-native": "0.55.4",
54 | "documentation": "^8.0.0",
55 | "husky": "^0.14.3",
56 | "prettier": "^1.6.1",
57 | "typescript": "^2.5.2"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/react-native-google-analytics-bridge.podspec:
--------------------------------------------------------------------------------
1 | require "json"
2 |
3 | package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4 | ios_root = 'ios/RCTGoogleAnalyticsBridge'
5 | galib_root = ios_root+'/google-analytics-lib'
6 |
7 | Pod::Spec.new do |s|
8 | s.name = "react-native-google-analytics-bridge"
9 | s.version = package["version"]
10 | s.summary = package["description"]
11 | s.author = "Idéhub AS"
12 |
13 | s.homepage = package["homepage"]
14 |
15 | s.license = package["license"]
16 | s.platform = :ios, "7.0"
17 |
18 | s.source = { :git => "https://github.com/idehub/react-native-google-analytics-bridge", :tag => "v#{s.version}" }
19 | s.default_subspec = 'Core'
20 |
21 | s.subspec 'Core' do |ss|
22 | ss.dependency 'React'
23 | ss.frameworks = 'CoreData', 'SystemConfiguration'
24 | ss.libraries = 'z', 'sqlite3.0','GoogleAnalyticsServices'
25 |
26 | ss.vendored_libraries =
27 | galib_root+'/libGoogleAnalyticsServices.a'
28 |
29 | ss.source_files =
30 | galib_root+'/*.{h}',
31 | ios_root+'/RCTGoogleAnalyticsBridge/*.{h,m}'
32 | end
33 |
34 | s.subspec 'adSupport' do |ss|
35 | ss.dependency 'react-native-google-analytics-bridge/Core'
36 | ss.frameworks = 'AdSupport'
37 | ss.libraries = 'AdIdAccess'
38 | ss.vendored_libraries =
39 | galib_root+'/libAdIdAccess.a'
40 | end
41 |
42 | end
43 |
--------------------------------------------------------------------------------
/src/GoogleAnalyticsSettings.ts:
--------------------------------------------------------------------------------
1 | import { AnalyticsSettings } from "./NativeBridges";
2 |
3 | /**
4 | * Settings which are applied across all trackers.
5 | * @name GoogleAnalyticsSettings
6 | */
7 | class GoogleAnalyticsSettings {
8 | /**
9 | * Sets if OptOut is active and disables Google Analytics. This is disabled by default. Note: This has to be set each time the App starts.
10 | * @example GoogleAnalyticsSettings.setOptOut(true);
11 | * @param {boolean} enabled
12 | */
13 | static setOptOut(enabled: boolean): void {
14 | AnalyticsSettings.setOptOut(enabled);
15 | }
16 |
17 | /**
18 | * Sets the trackers dispatch interval.
19 | * Events, screen views, etc, are sent in batches to your tracker. This function allows you to configure how often (in seconds) the batches are sent to your tracker. Recommended to keep this around 20-120 seconds to preserve battery and network traffic. This is set to 20 seconds by default.
20 | * @example GoogleAnalyticsSettings.setDispatchInterval(30);
21 | * @param {number} intervalInSeconds
22 | */
23 | static setDispatchInterval(intervalInSeconds: number): void {
24 | AnalyticsSettings.setDispatchInterval(intervalInSeconds);
25 | }
26 |
27 | /**
28 | * When enabled the native library prevents any data from being sent to Google Analytics. This allows you to test or debug the implementation, without your test data appearing in your Google Analytics reports.
29 | * @example GoogleAnalyticsSettings.setDryRun(true);
30 | * @param {boolean} enabled
31 | */
32 | static setDryRun(enabled: boolean): void {
33 | AnalyticsSettings.setDryRun(enabled);
34 | }
35 | }
36 |
37 | export default GoogleAnalyticsSettings;
38 |
--------------------------------------------------------------------------------
/src/GoogleTagManager.ts:
--------------------------------------------------------------------------------
1 | import DataLayerEvent from "./models/DataLayerEvent";
2 | import { TagManagerBridge } from "./NativeBridges";
3 | import FunctionCallTagHandler from "./Helpers/FunctionCallTagHandler";
4 |
5 | /**
6 | * Can only be used with one container. All functions returns a Promise.
7 | *
8 | * @name GoogleTagManager
9 | * @example
10 | * import { GoogleTagManager } from "react-native-google-analytics-bridge";
11 | * GoogleTagManager.openContainerWithId("GT-NZT48")
12 | * .then(() => GoogleTagManager.stringForKey("pack"))
13 | * .then(str => console.log("Pack: ", str));
14 | */
15 | class GoogleTagManager {
16 | /**
17 | * Call once to open the container for all subsequent static calls.
18 | * @example
19 | * GoogleTagManager.openContainerWithId('GT-NZT48').then((..) => ..)
20 | * @param {string} containerId
21 | * @returns {Promise}
22 | */
23 | static openContainerWithId(containerId: string): Promise {
24 | return TagManagerBridge.openContainerWithId(containerId);
25 | }
26 |
27 | /**
28 | * Refreshes the GTM container.
29 | * According to Tag Manager documentations for Android can be called once every 15 minutes.
30 | * No such limitations has been mentioned for iOS containers, though.
31 | * @example
32 | * GoogleTagManager.refreshContainer().then((..) => ..)
33 | * @returns {Promise}
34 | */
35 | static refreshContainer(): Promise {
36 | return TagManagerBridge.refreshContainer();
37 | }
38 |
39 | /**
40 | * Retrieves a boolean value with the given key from the opened container.
41 | * @example GoogleTagManager.boolForKey("key").then(val => console.log(val));
42 | * @param {string} key
43 | * @returns {Promise}
44 | */
45 | static boolForKey(key: string): Promise {
46 | return TagManagerBridge.booleanForKey(key);
47 | }
48 |
49 | /**
50 | * Retrieves a string with the given key from the opened container.
51 | * @example GoogleTagManager.stringForKey("key").then(val => console.log(val));
52 | * @param {string} key
53 | * @returns {Promise}
54 | */
55 | static stringForKey(key: string): Promise {
56 | return TagManagerBridge.stringForKey(key);
57 | }
58 |
59 | /**
60 | * Retrieves a number with the given key from the opened container.
61 | * @example GoogleTagManager.doubleForKey("key").then(val => console.log(val));
62 | * @param {string} key
63 | * @returns {Promise}
64 | */
65 | static doubleForKey(key): Promise {
66 | return TagManagerBridge.doubleForKey(key);
67 | }
68 |
69 | /**
70 | * Push a datalayer event for Google Analytics through Google Tag Manager. The event must have at least one key "event" with event name.
71 | * @example
72 | * GoogleTagManager.pushDataLayerEvent({
73 | * event: "eventName",
74 | * pageId: "/home"
75 | * }).then(success => console.log(success));
76 | * @param {DataLayerEvent} event An Map containing key and value pairs. It must have at least one key "event" with event name
77 | * @returns {Promise}
78 | */
79 | static pushDataLayerEvent(event: DataLayerEvent): Promise {
80 | return TagManagerBridge.pushDataLayerEvent(event);
81 | }
82 |
83 | /**
84 | * Register Function Call tag handler
85 | * @param {String} functionName
86 | * @param {Function} handler
87 | */
88 | static registerFunctionCallTagHandler(functionName, handler) {
89 | return FunctionCallTagHandler(functionName, handler);
90 | }
91 |
92 | /**
93 | * Sets logger to verbose, default is warning
94 | * @param {boolean} enabled
95 | */
96 | static setVerboseLoggingEnabled(enabled: boolean): Promise {
97 | return TagManagerBridge.setVerboseLoggingEnabled(enabled);
98 | }
99 | }
100 |
101 | export default GoogleTagManager;
102 |
--------------------------------------------------------------------------------
/src/Helpers/FunctionCallTagHandler/FunctionCallTagHandlerAndroid.ts:
--------------------------------------------------------------------------------
1 | import { DeviceEventEmitter } from "react-native";
2 | import { TagManagerBridge } from "../../NativeBridges";
3 | import { Handler } from "./models";
4 |
5 | /*
6 | * FunctionTagHandler module for Android adds an event listener per each Function Call registration.
7 | * To prevent possible messaging collision between native and JS realms, events are prefixed in
8 | * both environments before being registered.
9 | * For example, if a handler is being registered to handle tags with function name of "some_func", the corresponding
10 | * event would be GTM_FUNCTION_CALL_TAG_some_func. This is an implementation detail and does not affect high-level
11 | * APIs of the module.
12 | */
13 |
14 | const TAG_EVENT_PREFIX = "GTM_FUNCTION_CALL_TAG_";
15 |
16 | export default (functionName: string, handler: Handler): Promise => {
17 | const event = TAG_EVENT_PREFIX + functionName;
18 |
19 | return TagManagerBridge.registerFunctionCallTagHandler(functionName).then(
20 | () => {
21 | DeviceEventEmitter.addListener(event, payload => {
22 | try {
23 | handler(functionName, payload);
24 | } catch (e) {
25 | console.error(
26 | `Unhandled exception in FunctionCallTag handler: ${e.stack}`,
27 | `\nFunction Name: ${functionName}`,
28 | `\nPayload: ${JSON.stringify(payload)}`
29 | );
30 | }
31 | });
32 | return true;
33 | }
34 | );
35 | };
36 |
--------------------------------------------------------------------------------
/src/Helpers/FunctionCallTagHandler/FunctionCallTagHandlerIOS.ts:
--------------------------------------------------------------------------------
1 | import { NativeEventEmitter } from "react-native";
2 | import { TagManagerBridge } from "../../NativeBridges";
3 | import { Handler } from "./models";
4 |
5 | /*
6 | * FunctionTagHandler module for iOS lazily adds the global event listner the first time a function tag
7 | * needs to be registered. Due to some limitations in native enviroment all Function Call tag events
8 | * from native realm are sent over as GTM_FUNCTION_CALL_TAG event. The event objects
9 | * include _fn (function name) and payload attributes which are passed down to registered
10 | * handlers respectively
11 | */
12 |
13 | const GTM_FUNCTION_CALL_TAG_EVENT = "GTM_FUNCTION_CALL_TAG";
14 |
15 | interface Listener {
16 | functionName: string;
17 | handler: Handler;
18 | }
19 |
20 | // Downstream events from native realm
21 | const functionCallTagEventEmitter = new NativeEventEmitter(TagManagerBridge);
22 | const listeners: Array = [];
23 | let listenerRegistered = false;
24 |
25 | export default (functionName: string, handler: Handler): Promise => {
26 | if (!listenerRegistered) {
27 | // Register a global listener for Function Tag events
28 | functionCallTagEventEmitter.addListener(
29 | GTM_FUNCTION_CALL_TAG_EVENT,
30 | ({ _fn, payload }) => {
31 | // Pass on the event to listeners
32 | // _fn is basically the same as functionName
33 | listeners.forEach(listener => {
34 | if (listener.functionName === _fn) {
35 | try {
36 | handler(_fn, payload);
37 | } catch (e) {
38 | console.error(
39 | `Unhandled exception in FunctionCallTag handler: ${e.stack}`,
40 | `\nFunction Name: ${_fn}`,
41 | `\nPayload: ${JSON.stringify(payload)}`
42 | );
43 | }
44 | }
45 | });
46 | }
47 | );
48 |
49 | listenerRegistered = true;
50 | }
51 |
52 | return TagManagerBridge.registerFunctionCallTagHandler(functionName).then(
53 | () => {
54 | listeners.push({
55 | functionName,
56 | handler
57 | });
58 |
59 | return true;
60 | }
61 | );
62 | };
63 |
--------------------------------------------------------------------------------
/src/Helpers/FunctionCallTagHandler/index.ts:
--------------------------------------------------------------------------------
1 | import { Platform } from "react-native";
2 | import { RegisterHandler } from "./models";
3 | import FunctionCallTagHandlerAndroid from "./FunctionCallTagHandlerAndroid";
4 | import FunctionCallTagHandlerIOS from "./FunctionCallTagHandlerIOS";
5 |
6 | const FunctionCallTagHandler = Platform.select({
7 | ios: FunctionCallTagHandlerIOS,
8 | android: FunctionCallTagHandlerAndroid
9 | });
10 |
11 | export default FunctionCallTagHandler;
12 |
--------------------------------------------------------------------------------
/src/Helpers/FunctionCallTagHandler/models.ts:
--------------------------------------------------------------------------------
1 | export type Handler = (functionName: string, tagArguments: any) => any;
2 | export type RegisterHandler = (
3 | functionName: string,
4 | handler: Handler
5 | ) => Promise;
6 |
--------------------------------------------------------------------------------
/src/NativeBridges.ts:
--------------------------------------------------------------------------------
1 | import { HitPayload } from "./models/Analytics";
2 | import { NativeModules, EventSubscriptionVendor } from "react-native";
3 | import DataLayerEvent from "./models/DataLayerEvent";
4 | const {
5 | GoogleTagManagerBridge,
6 | GoogleAnalyticsBridge,
7 | GoogleAnalyticsSettings
8 | } = NativeModules;
9 |
10 | if (
11 | !GoogleTagManagerBridge ||
12 | !GoogleAnalyticsBridge ||
13 | !GoogleAnalyticsSettings
14 | ) {
15 | console.error(
16 | "Something went wrong initializing the native react-native-google-analytics-bridge module.\nPlease check your configuration.\nDid you forget to run 'react-native link' or install your node_modules?"
17 | );
18 | }
19 |
20 | export interface IGoogleAnalyticsBridge {
21 | trackScreenView(
22 | trackerId: string,
23 | screenName: string,
24 | payload: HitPayload
25 | ): void;
26 | trackEvent(
27 | trackerId: string,
28 | category: string,
29 | action: string,
30 | label: string,
31 | value: string,
32 | payload: HitPayload
33 | ): void;
34 | trackTiming(
35 | trackerId: string,
36 | category: string,
37 | interval: number,
38 | name: string,
39 | label: string,
40 | payload: HitPayload
41 | ): void;
42 | trackException(
43 | trackerId: string,
44 | error: string,
45 | fatal: boolean,
46 | payload: HitPayload
47 | ): void;
48 | trackSocialInteraction(
49 | trackerId: string,
50 | network: string,
51 | action: string,
52 | targetUrl: string,
53 | payload: HitPayload
54 | ): void;
55 | setUser(trackerId: string, userId: string): void;
56 | setClient(trackerId: string, clientId: string): void;
57 | getClientId(trackerId: string): Promise;
58 | allowIDFA(trackerId: string, enabled: boolean): void;
59 | setSamplingRate(trackerId: string, sampleRate: number): void;
60 | setAnonymizeIp(trackerId: string, enabled: boolean): void;
61 | setAppName(trackerId: string, appName: string): void;
62 | setAppVersion(trackerId: string, appVersion: string): void;
63 | setCurrency(trackerId: string, currencyCode: string): void;
64 | setTrackUncaughtExceptions(trackerId: string, enabled: boolean): void;
65 | dispatch(): Promise;
66 | }
67 |
68 | export interface IGoogleTagManagerBridge extends EventSubscriptionVendor {
69 | openContainerWithId(containerId: string): Promise;
70 | refreshContainer(): Promise;
71 | booleanForKey(key: string): Promise;
72 | stringForKey(key: string): Promise;
73 | doubleForKey(key: any): Promise;
74 | pushDataLayerEvent(event: DataLayerEvent): Promise;
75 | registerFunctionCallTagHandler(functionName: string): Promise;
76 | setVerboseLoggingEnabled(enabled: boolean): Promise;
77 | }
78 |
79 | export interface IGoogleAnalyticsSettings {
80 | setOptOut(enabled): void;
81 | setDispatchInterval(intervalInSeconds): void;
82 | setDryRun(enabled): void;
83 | }
84 |
85 | const AnalyticsBridge = GoogleAnalyticsBridge as IGoogleAnalyticsBridge;
86 | const TagManagerBridge = GoogleTagManagerBridge as IGoogleTagManagerBridge;
87 | const AnalyticsSettings = GoogleAnalyticsSettings as IGoogleAnalyticsSettings;
88 |
89 | export { TagManagerBridge };
90 | export { AnalyticsBridge };
91 | export { AnalyticsSettings };
92 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export { default as GoogleAnalyticsTracker } from "./GoogleAnalyticsTracker";
2 | export { default as GoogleAnalyticsSettings } from "./GoogleAnalyticsSettings";
3 | export { default as GoogleTagManager } from "./GoogleTagManager";
4 | export { default as DataLayerEvent } from "./models/DataLayerEvent";
5 | export {
6 | Product,
7 | ProductActionEnum,
8 | ProductAction,
9 | Transaction
10 | } from "./models/Product";
11 | export {
12 | CustomDimensionsByField,
13 | CustomDimensionsByIndex,
14 | CustomDimensionsFieldIndexMap,
15 | CustomMetrics
16 | } from "./models/Custom";
17 | export { HitPayload, EventMetadata, TimingMetadata } from "./models/Analytics";
18 |
--------------------------------------------------------------------------------
/src/models/Analytics.ts:
--------------------------------------------------------------------------------
1 | import {
2 | CustomDimensionsByIndex,
3 | CustomMetrics,
4 | CustomDimensionsByField
5 | } from "./Custom";
6 | import { Product, ProductAction } from "./Product";
7 |
8 | export interface EventMetadata {
9 | label?: string;
10 | value?: number;
11 | }
12 |
13 | export interface TimingMetadata {
14 | name: string;
15 | label?: string;
16 | }
17 |
18 | export interface HitPayload {
19 | products?: Product[];
20 | impressionProducts?: Product[];
21 | impressionList?: string;
22 | impressionSource?: string;
23 | productAction?: ProductAction;
24 | customDimensions?: CustomDimensionsByIndex | CustomDimensionsByField;
25 | customMetrics?: CustomMetrics;
26 | utmCampaignUrl?: string;
27 | session?: SessionState;
28 | }
29 |
30 | export enum SessionState {
31 | Start = "start",
32 | End = "end"
33 | }
34 |
35 | /**
36 | *
37 | * Used when tracking event
38 | *
39 | * @interface EventMetadata
40 | * @example
41 | * const eventMetadata = { label: "v1.0.3", value: 22 }
42 | * tracker.trackEvent("FinalizeOrderButton", "Click", eventMetadata);
43 | * @param {string} label (Optional)
44 | * @param {number} value (Optional)
45 | */
46 |
47 | /**
48 | *
49 | * Used when tracking time measurements
50 | *
51 | * @interface TimingMetadata
52 | * @example
53 | * const timingMetadata = { name: "LoadList" } // name is a required value when tracking timing
54 | * tracker.trackTiming("testcategory", 13000, timingMetadata);
55 | * @param {string} name (Required)
56 | * @param {string} label (Optional)
57 | */
58 |
59 | /**
60 | * The HitPayload object and possible values
61 | *
62 | * Used by the different tracking methods for adding metadata to the hit.
63 | *
64 | * @interface HitPayload
65 | * @example
66 | * // If you want to do send a purchase payload with an event:
67 | * const product = {
68 | * id: "P12345",
69 | * name: "Android Warhol T-Shirt",
70 | * category: "Apparel/T-Shirts",
71 | * brand: "Google",
72 | * variant: "Black",
73 | * price: 29.2,
74 | * quantity: 1,
75 | * couponCode: "APPARELSALE"
76 | * };
77 | * const transaction = {
78 | * id: "T12345",
79 | * affiliation: "Google Store - Online",
80 | * revenue: 37.39,
81 | * tax: 2.85,
82 | * shipping: 5.34,
83 | * couponCode: "SUMMER2013"
84 | * };
85 | * const productAction = {
86 | * transaction,
87 | * action: 7 // Purchase action, see ProductActionEnum
88 | * }
89 | * const payload = { products: [ product ], productAction: productAction }
90 | * tracker.trackEvent("FinalizeOrderButton", "Click", null, payload);
91 | * @example
92 | * // If you want to send custom dimensions with a screen view:
93 | * const customDimensions = {
94 | * 1: "Beta",
95 | * 3: "Premium"
96 | * };
97 | * const payload = { customDimensions };
98 | * tracker.trackScreenView("SaleScreen", payload);
99 | * @param {Product[]} products (Optional) Used for ecommerce
100 | * @param {Product[]} impressionProducts (Optional) Used for ecommerce
101 | * @param {string} impressionList (Optional) Used for ecommerce
102 | * @param {string} impressionSource (Optional) Used for ecommerce
103 | * @param {ProductAction} productAction (Optional) Used for ecommerce
104 | * @param {CustomDimensionsByIndex | CustomDimensionsByField} customDimensions (Optional)
105 | * @param {CustomMetrics} customMetrics (Optional)
106 | * @param {string} utmCampaignUrl (Optional) Used for campaigns
107 | * @param {string} session (Optional) Only two possible values, "start" or "end". This will either start or end a session.
108 | */
109 |
--------------------------------------------------------------------------------
/src/models/Custom.ts:
--------------------------------------------------------------------------------
1 | export interface CustomDimensionsFieldIndexMap {
2 | [key: string]: number;
3 | }
4 |
5 | export interface CustomDimensionsByIndex {
6 | [key: number]: number | string | boolean;
7 | }
8 |
9 | export interface CustomDimensionsByField {
10 | [key: string]: number | string | boolean;
11 | }
12 |
13 | export interface CustomMetrics {
14 | [key: number]: number;
15 | }
16 |
17 | /**
18 | * A dictionary describing mapping of field names to indices for custom dimensions.
19 | * This is an optional object used by the tracker.
20 | * @example
21 | * // Create something like:
22 | * const fieldIndexMap = { customerType: 1 };
23 | * // Construct tracker with it:
24 | * const tracker = new GoogleAnalyticsTracker("UA-12345-3", fieldIndexMap);
25 | * // This allows you to send in customDimensions in the`HitPayload by field name instead of index:
26 | * tracker.trackScreenView("Home", { customDimensions: { customerType: "Premium" } });
27 | * // If you do not provide a map, you instead have to send in by index:
28 | * tracker.trackScreenView("Home", { customDimensions: { 1: "Premium" } });
29 | * @see CustomDimensionsFieldIndexMap
30 | * @see CustomDimensionsByField
31 | * @interface CustomDimensionsFieldIndexMap
32 | */
33 |
34 | /**
35 | * A dictionary with custom dimensions values and their index keys.
36 | * @example
37 | * const customDimensions = { 1: "Premium", 3: "Beta", 5: 1200 }
38 | * tracker.trackScreenView("Home", { customDimensions });
39 | * @see CustomDimensionsFieldIndexMap
40 | * @see CustomDimensionsByField
41 | * @interface CustomDimensionsByIndex
42 | */
43 |
44 | /**
45 | * A dictionary with custom dimensions values and their (mapped) field name keys.
46 | * In order to use this and send in custom dimensions by field name, you must have
47 | * provided a `CustomDimensionsFieldIndexMap` when constructing the tracker.
48 | * @example
49 | * const customDimensions = { customerType: "Premium", appType: "Beta", credit: 1200 }
50 | * tracker.trackScreenView("Home", { customDimensions });
51 | * @see CustomDimensionsFieldIndexMap
52 | * @see CustomDimensionsByIndex
53 | * @interface CustomDimensionsByField
54 | */
55 |
56 | /**
57 | * A dictionary with custom metric values and their index keys.
58 | * @example
59 | * const customMetrics = { 1: 2389, 4: 15000 }
60 | * tracker.trackScreenView("Home", { customMetrics });
61 | * @interface CustomMetrics
62 | */
63 |
--------------------------------------------------------------------------------
/src/models/DataLayerEvent.ts:
--------------------------------------------------------------------------------
1 | export default interface DataLayerEvent {
2 | event: string;
3 | [key: string]: any;
4 | }
5 |
6 | /**
7 | * The Google Tag Manager DataLayerEvent dictionary.
8 | *
9 | * Populate this event-object with values to push to the DataLayer. The only required property is `event`.
10 | * @example
11 | * const dataLayerEvent = {
12 | * event: "eventName",
13 | * pageId: "/home"
14 | * };
15 | * GoogleTagManager.pushDataLayerEvent(dataLayerEvent);
16 | *
17 | * @interface DataLayerEvent
18 | * @param {string} event
19 | */
20 |
--------------------------------------------------------------------------------
/src/models/Product.ts:
--------------------------------------------------------------------------------
1 | export interface Product {
2 | id: string;
3 | name: string;
4 | category?: string;
5 | brand?: string;
6 | variant?: string;
7 | price?: number;
8 | couponCode?: string;
9 | quantity?: number;
10 | }
11 |
12 | /**
13 | * Enhanced Ecommerce ProductActionEnum
14 | *
15 | * Used by `ProductAction` when describing the type of product action. The possible values (numbers) are:
16 | *
17 | * * Detail = 1,
18 | * * Click = 2,
19 | * * Add = 3,
20 | * * Remove = 4,
21 | * * Checkout = 5,
22 | * * CheckoutOption = 6,
23 | * * Purchase = 7,
24 | * * Refund = 8
25 | *
26 | * @export
27 | * @enum {number}
28 | */
29 | export enum ProductActionEnum {
30 | Detail = 1,
31 | Click = 2,
32 | Add = 3,
33 | Remove = 4,
34 | Checkout = 5,
35 | CheckoutOption = 6,
36 | Purchase = 7,
37 | Refund = 8
38 | }
39 |
40 | export interface Transaction {
41 | id: string;
42 | affiliation?: string;
43 | revenue?: number;
44 | tax?: number;
45 | shipping?: number;
46 | couponCode?: string;
47 | }
48 |
49 | export interface ProductAction {
50 | action: ProductActionEnum;
51 | transaction?: Transaction;
52 | checkoutStep?: number;
53 | checkoutOption?: string;
54 | productActionList?: string;
55 | productListSource?: string;
56 | }
57 |
58 | /**
59 | * Enhanced Ecommerce Product
60 | *
61 | * Used by `HitPayload` when populating product actions or impressions
62 | *
63 | * @example
64 | * const product = {
65 | * id: "P12345",
66 | * name: "Android Warhol T-Shirt",
67 | * category: "Apparel/T-Shirts",
68 | * brand: "Google",
69 | * variant: "Black",
70 | * price: 29.2,
71 | * quantity: 1,
72 | * couponCode: "APPARELSALE"
73 | * };
74 | * @interface Product
75 | * @param {string} id
76 | * @param {string} name
77 | * @param {string} category (Optional)
78 | * @param {string} brand (Optional)
79 | * @param {string} variant (Optional)
80 | * @param {number} price (Optional)
81 | * @param {string} couponCode (Optional)
82 | * @param {number} quantity (Optional)
83 | */
84 |
85 | /**
86 | * Enhanced Ecommerce Transaction
87 | *
88 | * Used by `ProductAction` when populating describing a purchase/transaction
89 | * @example
90 | * const transaction = {
91 | * id: "T12345",
92 | * affiliation: "Google Store - Online",
93 | * revenue: 37.39,
94 | * tax: 2.85,
95 | * shipping: 5.34,
96 | * couponCode: "SUMMER2013"
97 | * };
98 | * @interface Transaction
99 | * @param {string} id
100 | * @param {string} affiliation (Optional)
101 | * @param {number} revenue (Optional - but not really)
102 | * @param {number} tax (Optional)
103 | * @param {number} shipping (Optional)
104 | * @param {string} couponCode (Optional)
105 | */
106 |
107 | /**
108 | * Enhanced Ecommerce Product Action
109 | *
110 | * Used by `HitPayload` when describing a product action
111 | * @example
112 | * const productAction = {
113 | * transaction,
114 | * action: 7 // Purchase action, see ProductActionEnum
115 | * }
116 | * @example
117 | * const productAction = {
118 | * action: 3 // Add action, see ProductActionEnum
119 | * }
120 | * @interface ProductAction
121 | * @param {ProductActionEnum} action
122 | * @param {Transaction} transaction (Optional)
123 | * @param {number} checkoutStep (Optional)
124 | * @param {string} checkoutOption (Optional)
125 | * @param {string} productActionList (Optional)
126 | * @param {string} productListSource (Optional)
127 | */
128 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2015",
4 | "module": "es2015",
5 | "moduleResolution": "node",
6 | "declaration": true,
7 | "allowSyntheticDefaultImports": true,
8 | "outDir": "./dist",
9 | "noUnusedLocals": true,
10 | "noImplicitAny": false,
11 | "skipLibCheck": true
12 | },
13 | "include": ["src/**/*"]
14 | }
15 |
--------------------------------------------------------------------------------