forked from lukeed/ganalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ganalytics.d.ts
617 lines (531 loc) · 18.7 KB
/
ganalytics.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
declare module "ganalytics" {
export type Number = string | number;
export type Boolean = 1 | 0 | '1' | '0';
export type ProductAction = 'detail' | 'click' | 'add' | 'remove' | 'checkout' | 'checkout_option' | 'purchase' | 'refund';
export interface EventMap {
'event': EventParams,
'social': SocialParams,
'pageview': CommonParams,
'exception': ExceptionParams,
'screenview': ScreenviewParams,
'transaction': TransactionParams,
'timing': TimingParams,
'item': ItemParams,
}
export type EventOptional = 'pageview' | 'exception' | 'screenview';
export interface GAnalytics {
send<K extends keyof EventMap>(type: K, params: EventMap[K]): void;
send(type: EventOptional): void;
}
export interface CommonParams {
/**
* Anonymize the sender's IP address.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aip
* @example '0', 1
*/
aip?: Boolean;
/**
* The hit's data source type.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ds
* @example 'call center', 'web'
*/
ds?: string;
/**
* The time delta (in milliseconds) between the hit's occurrence and when it was reported.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#qt
* @example 560, '560'
*/
qt?: Number;
/**
* The application or site owner's known identifier for the user.
* @note This becomes required if `cid` is not defined.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uid
* @example 'as8eknlll', 'foobar'
*/
uid?: string;
/**
* The application or site owner's generated identifier for the client device.
* @note This becomes required if `uid` is not defined.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid
* @example 'as8eknlll', 'foobar'
*/
cid?: string;
/**
* Control the session duration. The session will begin or end with this hit.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sc
* @example 'start', 'end'
*/
sc?: 'start' | 'end';
/**
* The IP address of the user in IPV4 or IPV6 format
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uip
* @example '1.2.3.4'
*/
uip?: string;
/**
* The User Agent of the browser.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ua
* @example 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14'
*/
ua?: string;
/**
* The geographical location of the user. It should be a two-letter country code or a [Geographical ID](http://developers.google.com/analytics/devguides/collection/protocol/v1/geoid).
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#geoid
* @example 'US', '21137'
*/
geoid?: string;
/**
* The referral source that brought traffic to the application.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dr
* @example 'http://example.com'
*/
dr?: string;
/**
* The campaign name.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cn
* @example '(direct)'
*/
cn?: string;
/**
* The campaign source.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cs
* @example '(direct)'
*/
cs?: string;
/**
* The campaign medium.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cm
* @example 'organic'
*/
cm?: string;
/**
* The campaign keyword.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ck
* @example 'Blue Shoes'
*/
ck?: string;
/**
* The campaign content.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cc
* @example 'content'
*/
cc?: string;
/**
* The campaign identifier.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ci
* @example 'ID'
*/
ci?: string;
/**
* The Google Ads ID.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#gclid
* @example 'CL6Q-OXyqKUCFcgK2goddQuoHg'
*/
gclid?: string;
/**
* Google Display Ads identifier.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dclid
* @example 'd_click_id'
*/
dclid?: string;
/**
* The screen resolution.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sr
* @example '800x600'
*/
sr?: string;
/**
* The viewport size.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#vp
* @example '123x456'
*/
vp?: string;
/**
* The character set used to encode the current page/document.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#de
* @default 'UTF-8'
* @example 'UTF-8'
*/
de?: string;
/**
* The screen's color depth.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sd
* @example '24-bits'
*/
sd?: string;
/**
* The user's language.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ul
* @example 'en-us'
*/
ul?: string;
/**
* Specify whether Java was enabled.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#je
* @example '1', 0
*/
je?: Boolean;
/**
* Specify the version of Flash available.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#fl
* @example '10 1 r103'
*/
fl?: string;
/**
* Consider the hit as non-interactive.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ni
* @example 'd_click_id'
*/
ni?: Boolean;
/**
* The full URL (document location) of the document.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dl
* @example 'http://foo.com/home?a=b'
*/
dl?: string;
/**
* The document's hostname.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dh
* @example 'foo.com'
*/
dh?: string;
/**
* The path portion of the document's URL location.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dp
* @example '/foo'
*/
dp?: string;
/**
* The document's title.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dt
* @example 'Settings'
*/
dt?: string;
/**
* The document's content group. You may have up to 5 groupings, each of which cna have up to 100 groups.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cg_
* @example 'news/sports'
*/
cg1?: string;
/**
* The document's content group. You may have up to 5 groupings, each of which cna have up to 100 groups.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cg_
* @example 'news/sports'
*/
cg2?: string;
/**
* The document's content group. You may have up to 5 groupings, each of which cna have up to 100 groups.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cg_
* @example 'news/sports'
*/
cg3?: string;
/**
* The document's content group. You may have up to 5 groupings, each of which cna have up to 100 groups.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cg_
* @example 'news/sports'
*/
cg4?: string;
/**
* The document's content group. You may have up to 5 groupings, each of which cna have up to 100 groups.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cg_
* @example 'news/sports'
*/
cg5?: string;
/**
* The ID of a clicked DOM element, used to disambiguate multiple links to the same URL for In-Page Analytics reports.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#linkid
* @example 'nav_bar'
*/
linkid?: string;
/**
* The application's name.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an
* @example 'My App'
*/
an?: string;
/**
* The application identifier.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aid
* @example 'com.company.app'
*/
aid?: string;
/**
* The application's version.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#av
* @example '1.2'
*/
av?: string;
/**
* The application's installer identifier.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aiid
* @example 'com.platform.vending'
*/
aiid?: string;
/**
* The role of the products included in a git. If no Product Action is specified, all product definitions included with the hit will be ignored.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#pa
* @example 'detail'
*/
pa?: ProductAction,
/**
* The list or collection from which a product action occurred. This is an additional parameter that can be sent when Product Action is set to 'detail' or 'click'.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#pal
* @example 'Search Results'
*/
pal?: string,
/**
* The step number in a checkout funnel. This is an additional parameter that can be sent when Product Action is set to 'checkout'.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cos
* @example '2'
*/
cos?: Number,
/**
* Additional information about a checkout step. This is an additional parameter that can be sent when Product Action is set to 'checkout'.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#col
* @example 'Visa'
*/
col?: string,
/**
* Indicate the local currency for all transaction currency values. Value should be a valid ISO 4217 currency code.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cu
* @example 'EUR'
*/
cu?: string,
/**
* Specify the experiment ID that the user is exposed to, if any. It should be sent in conjunction with the `xvar` parameter.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#xid
* @example 'Qp0gahJ3RAO3DJ18b0XoUQ'
*/
xid?: string,
/**
* The experiment's version number, if any. It should be sent in conjunction with the `xid` parameter.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#xvar
* @example '1'
*/
xvar?: string,
}
export interface ScreenviewParams extends CommonParams {
/**
* The document's screen name. Required for mobile applications. Optional for web applications, defaulting to `dl` value.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cd
* @example 'High Scores'
*/
cd?: string,
}
export interface EventParams extends CommonParams {
/**
* The event category.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ec
* @example 'Category'
*/
ec: string;
/**
* The event action.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ea
* @example 'Action'
*/
ea: string;
/**
* The event label.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#el
* @example 'Label'
*/
el?: string;
/**
* The event's non-negative value.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ev
* @example 55
*/
ev?: Number;
}
export interface ExceptionParams extends CommonParams {
/**
* The exception's description.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#exd
* @example 'DatabaseError'
*/
exd?: string;
/**
* Specify if the exception was fatal.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#exf
* @example 'DatabaseError'
*/
exf?: Boolean;
}
export interface SocialParams extends CommonParams {
/**
* The social network.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sn
* @example 'facebook'
*/
sn: string;
/**
* The social interaction action; for example, on Facebook when a user clicks the 'Like' button, the social action is 'like'.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sa
* @example 'like'
*/
sa: string;
/**
* The social interaction's target, which is typically a URL but can be any text value.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#st
* @example 'http://foo.com'
*/
st: string;
}
export interface TimingParams extends CommonParams {
/**
* The user's timing category.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#utc
* @example 'category'
*/
utc: string;
/**
* The user's timing variable.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#utv
* @example 'lookup'
*/
utv: string;
/**
* The user's timing value.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#utt
* @example 123
*/
utt: Number;
/**
* The user's timing label.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#utl
* @example 'label'
*/
utl?: string;
/**
* The time (in milliseconds) it took for the page to load.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#plt
* @example 3554
*/
plt?: Number;
/**
* The time (in milliseconds) it took to perform a DNS lookup.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dns
* @example 43
*/
dns?: Number;
/**
* The time (in milliseconds) it took for the page to be downloaded.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#pdt
* @example 500
*/
pdt?: Number;
/**
* The time (in milliseconds) it took for any redirects to happen.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#rrt
* @example 500
*/
rrt?: Number;
/**
* The time (in milliseconds) it took for a TCP connection to be established.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tcp
* @example 500
*/
tcp?: Number;
/**
* The time (in milliseconds) it took for the server to respond after connecting.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#srt
* @example 500
*/
srt?: Number;
/**
* The time (in milliseconds) it took for the `document.readyState` to be 'interactive'.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dit
* @example 500
*/
dit?: Number;
/**
* The time (in milliseconds) it took for the `DOMContentLoaded` event to fire.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#clt
* @example 500
*/
clt?: Number;
}
export interface ItemParams extends CommonParams {
/**
* A unique identifier for the transaction. This value should be the same for both the 'transaction' hit and 'item' hits associated with the transaction.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ti
* @example 'OD564'
*/
ti: string;
/**
* The item's name
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#in
* @example 'Shoe'
*/
in: string;
/**
* The price for a single item or unit.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ip
* @example 'OD564'
*/
ip?: Number;
/**
* The number of items purchased.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#iq
* @example 4
*/
iq?: Number;
/**
* The SKU or item code.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ic
* @example 'SKU47'
*/
ic?: string;
/**
* The category that the item belongs to.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#iv
* @example 'Blue'
*/
iv?: string;
}
export interface TransactionParams extends CommonParams {
/**
* A unique identifier for the transaction. This value should be the same for both the 'transaction' hit and 'item' hits associated with the transaction.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ti
* @example 'OD564'
*/
ti: string;
/**
* The store or affiliation from which this transaction occurred.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ta
* @example 'Member'
*/
ta?: string;
/**
* The total revenue associated with the transaction. This value should include any shipping or tax costs.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tr
* @example '15.47'
*/
tr?: Number;
/**
* The total shipping cost of the transaction.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ts
* @example '3.50'
*/
ts?: Number;
/**
* The total tax of the transaction.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tt
* @example '11.20'
*/
tt?: Number;
/**
* The coupon redeemed with the transaction.
* @see https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tcc
* @example 'SUMMER08'
*/
tcc?: string;
}
/**
* @param trackerID Your Google Analytics tracker ID; eg UA-XXXXXXXX-X
* @param options Options
* @param toWait When truthy, a pageview event will not be sent immediately upon initialization.
*/
export default function (trackerID: string, options?: Partial<CommonParams>, toWait?: boolean): GAnalytics;
}