forked from idehub/react-native-google-analytics-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
347 lines (309 loc) · 13.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
declare module "react-native-google-analytics-bridge" {
export interface Product {
id: string
name: string
category?: string
brand?: string
variant?: string
price?: number
quantity?: number
couponCode?: string
}
export interface Transaction {
id: string
affiliation?: string
revenue?: number
tax?: number
shipping?: number
couponCode?: string
}
export interface OptionalValue {
label?: string
value?: number
}
export interface OptionalTimingValue {
name: string
label?: string
}
export interface CustomDimensionsFieldIndexMap {
[key: string]: number
}
export interface CustomDimensionsByIndex {
[key: number]: any
}
export interface CustomDimensionsByField {
[key: string]: any
}
export interface CustomMetrics {
[key: number]: number
}
/**
* Used to bridge tracker data to native Google analytics.
* Saves necessary tracker (specific) data to format data as native part of Google analytics expect.
*/
export class GoogleAnalyticsTracker {
/**
* Save all tracker related data that is needed to call native methods with proper data.
* @param {String} trackerId
* @param {{fieldName: fieldIndex}} customDimensionsFieldsIndexMap Custom dimensions field/index pairs
*/
constructor(trackerId: string, customDimensionsFieldsIndexMap?: CustomDimensionsFieldIndexMap)
/**
* If Tracker has customDimensionsFieldsIndexMap, it will transform
* customDimensions map pairs {field: value} to {fieldIndex: value}.
* Otherwise customDimensions are passed trough untouched.
* Underlay native methods will transform provided customDimensions map to expected format.
* Google analytics expect dimensions to be tracker with 'dimension{index}' keys,
* not dimension field names.
* @param {CustomDimensionsByIndex} customDimensions
* @returns {CustomDimensionsByField}
*/
transformCustomDimensionsFieldsToIndexes(customDimensions: CustomDimensionsByIndex): CustomDimensionsByField
/**
* Track the current screen/view
* @param {String} screenName The name of the current screen
*/
trackScreenView(screenName: string): void
/**
* Track the campaign from url
* @param {String} urlString The url of the deep link
*/
trackCampaignFromUrl(urlString: string): void
/**
* Track an event that has occured
* @param {String} category The event category
* @param {String} action The event action
* @param {OptionalValue} optionalValues An object containing optional label and value
*/
trackEvent(category: string, action: string, optionalValues?: OptionalValue): void
/**
* Track the current screen/view with custom dimension values
* @param {String} screenName The name of the current screen
* @param {CustomDimensionsByIndex | CustomDimensionsByField} customDimensionValues An object containing custom dimension key/value pairs
*/
trackScreenViewWithCustomDimensionValues(
screenName: string,
customDimensionValues: CustomDimensionsByIndex | CustomDimensionsByField
): void
/**
* Track a non-interaction event that has occured with custom dimension values
* @param {String} category The event category
* @param {String} action The event action
* @param {OptionalValue} optionalValues An object containing optional label and value
* @param {CustomDimensionsByIndex | CustomDimensionsByField} customDimensionValues An object containing custom dimension key/value pairs
*/
trackNonInteractionEventWithCustomDimensionValues(
category: string,
action: string,
optionalValues?: OptionalValue,
customDimensionValues?: CustomDimensionsByIndex | CustomDimensionsByField
): void
/**
* Track an event that has occured with custom dimension values
* @param {String} category The event category
* @param {String} action The event action
* @param {OptionalValue} optionalValues An object containing optional label and value
* @param {CustomDimensionsByIndex | CustomDimensionsByField} customDimensionValues An object containing custom dimension key/value pairs
*/
trackEventWithCustomDimensionValues(
category: string,
action: string,
optionalValues?: OptionalValue,
customDimensionValues?: CustomDimensionsByIndex | CustomDimensionsByField
): void
/**
* Track an event that has occured with custom dimension and metric values.
* @param {String} category The event category
* @param {String} action The event action
* @param {OptionalValue} optionalValues An object containing optional label and value
* @param {CustomDimensionsByIndex | CustomDimensionsByField} customDimensionValues An object containing custom dimension key/value pairs
* @param {CustomMetrics} customMetricValues An object containing custom metric key/value pairs
*/
trackEventWithCustomDimensionAndMetricValues(
category: string,
action: string,
optionalValues?: OptionalValue,
customDimensionValues?: CustomDimensionsByIndex | CustomDimensionsByField,
customMetricValues?: CustomMetrics
): void
/**
* Track an event that has occured
* @param {String} category The event category
* @param {Number} value The timing measurement in milliseconds
* @param {OptionalTimingValue} optionalValues An object containing optional name and label
*/
trackTiming(category: string, value: number, optionalValues: OptionalTimingValue): void
/**
* Track a purchase event. This uses the Enhanced Ecommerce GA feature.
* @param {Product} product An object with product values
* @param {Transaction} transaction An object with transaction values
* @param {String} eventCategory The event category, defaults to Ecommerce
* @param {String} eventAction The event action, defaults to Purchase
*/
trackPurchaseEvent(
product: Product,
transaction: Transaction,
eventCategory?: string,
eventAction?: string
): void
/**
* Track a purchase event. This uses the Enhanced Ecommerce GA feature.
* @param {Product[]} products An array with products
* @param {Transaction} transaction An object with transaction values
* @param {String} eventCategory The event category, defaults to Ecommerce
* @param {String} eventAction The event action, defaults to Purchase
*/
trackMultiProductsPurchaseEvent(
products: Product[],
transaction: Transaction,
eventCategory?: string,
eventAction?: string
): void
/**
* Track a purchase event with custom dimensions. This uses the Enhanced Ecommerce GA feature.
* @param {Product[]} products An array with products
* @param {Transaction} transaction An object with transaction values
* @param {String} eventCategory The event category, defaults to Ecommerce
* @param {String} eventAction The event action, defaults to Purchase
* @param {CustomDimensionsByIndex | CustomDimensionsByField} customDimensionValues An object containing custom dimension key/value pairs
*/
trackMultiProductsPurchaseEventWithCustomDimensionValues(
products: Product[],
transaction: Transaction,
eventCategory?: string,
eventAction?: string,
customDimensions?: CustomDimensionsByIndex | CustomDimensionsByField
): void
/**
* Track an exception
* @param {String} error The description of the error
* @param {Boolean} fatal A value indiciating if the error was fatal, defaults to false
*/
trackException(error: string, fatal?: boolean): void
/**
* Sets the current userId for tracking.
* @param {String} userId The current userId
*/
setUser(userId: string): void
/**
* Sets the current clientId for tracking.
* @param {String} clientId The current userId
*/
setClient(clientId: string): void
/**
* Sets if IDFA (identifier for advertisers) collection should be enabled
* @param {Boolean} enabled Defaults to true
*/
allowIDFA(enabled: boolean): void
/**
* Track a social interaction, Facebook, Twitter, etc.
* @param {String} network
* @param {String} action
* @param {String} targetUrl
*/
trackSocialInteraction(
network: string,
action: string,
targetUrl: string
): void
/**
* Sets if uncaught exceptions should be tracked
* @param {Boolean} enabled
*/
setTrackUncaughtExceptions(enabled: boolean): void
/**
* Sets the trackers appName
* The Bundle name is used by default
* @param {String} appName
*/
setAppName(appName: string): void
/**
* Sets the trackers appVersion
* @param {String} appVersion
*/
setAppVersion(appVersion: string): void
/**
* Sets if AnonymizeIp is enabled
* If enabled the last octet of the IP address will be removed
* @param {Boolean} enabled
*/
setAnonymizeIp(enabled: boolean): void
/**
* Sets tracker sampling rate.
* @param {Float} sampleRatio Percentage 0 - 100
*/
setSamplingRate(sampleRatio: number): void
/**
* Sets the currency for tracking.
* @param {String} currencyCode The currency ISO 4217 code
*/
setCurrency(currencyCode: string): void
/**
* This function lets you create a session manually. By default, Google Analytics will group hits that are received
* within 30 minutes of one another into the same session. So it is strictly not necessary to create a session manually.
* @param {String} screenName The current screen which the session started on
*/
createNewSession(screenName: string): void
}
/**
* Google analytics settings shared across all GoogleAnalyticsTracker instances.
*/
export class GoogleAnalyticsSettings {
/**
* Sets if OptOut is active and disables Google Analytics
* This has to be set each time the App starts
* @param {Boolean} enabled
*/
static setOptOut(enabled: boolean): void
/**
* Sets the trackers dispatch interval
* This will influence how often batches of events, screen views, etc
* are sent to your tracker.
* @param {Number} intervalInSeconds
*/
static setDispatchInterval(intervalInSeconds: number): void
/**
* Sets if the tracker should have dry run enabled.
* If dry run is enabled, no analytics data will be sent to your tracker.
* @param {Boolean} enabled
*/
static setDryRun(enabled: boolean): void
}
export interface DataLayerEvent {
event: string
[key: string]: any
}
export class GoogleTagManager {
/**
* Call once to open the container for all subsequent static calls.
* @param {String} containerId
* @returns {Promise<boolean>}
*/
static openContainerWithId(containerId: string): Promise<boolean>
/**
* Retrieves a boolean value with the given key from the opened container.
* @param {String} key
* @returns {Promise<boolean>}
*/
static boolForKey(key: string): Promise<boolean>
/**
* Retrieves a string with the given key from the opened container.
* @param {String} key
* @returns {String}
*/
static stringForKey(key: string): Promise<string>
/**
* Retrieves a number with the given key from the opened container.
* @param {String} key
* @returns {Promise<number>}
*/
static doubleForKey(key: string): Promise<number>
/**
* Push a datalayer event for Google Analytics through Google Tag Manager. The event must have at least one key "event" with event name.
* You can add optional values on top of that, example: {event: "eventName", pageId: "/home"}
* @param {Object} event An Map<String, Object> containing key and value pairs. It must have at least one key "event" with event name
* @returns {Promise<boolean>}
*/
static pushDataLayerEvent(event: DataLayerEvent): Promise<boolean>
}
}