UNPKG

27.8 kBTypeScriptView Raw
1// Type definitions for Google Analytics (Classic and Universal)
2// Project: https://developers.google.com/analytics/devguides/collection/gajs/, https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference
3// Definitions by: Ronnie Haakon Hegelund <http://ronniehegelund.blogspot.dk>, Pat Kujawa <http://patkujawa.com>, Tyler Murphy <https://github.com/tyler-murphy>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6declare class Tracker {
7 _trackPageview(): void;
8 _getName(): string;
9 _getAccount(): string;
10 _getVersion(): string;
11 _getVisitorCustomVar(index: number): string;
12 _setAccount(): string;
13 _setCustomVar(index: number, name: string, value: string, opt_scope?: number): boolean;
14 _setSampleRate(newRate: string): void;
15 _setSessionCookieTimeout(cookieTimeoutMillis: number): void;
16 _setSiteSpeedSampleRate(sampleRate: number): void;
17 _setVisitorCookieTimeout(milliseconds: number): void;
18 _trackPageLoadTime(): void;
19}
20
21interface GoogleAnalyticsCode {
22 push(commandArray: Array<string | boolean | number>): void;
23 push(func: Function): void;
24}
25
26interface GoogleAnalyticsTracker {
27 _getTracker(account: string): Tracker;
28 _createTracker(opt_account: string, opt_name?: string): Tracker;
29 _getTrackerByName(opt_name?: string): Tracker;
30 _anonymizeIp(): void;
31}
32
33interface GoogleAnalytics {
34 type: string;
35 src: string;
36 async: boolean;
37}
38
39declare namespace UniversalAnalytics {
40 // https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference
41
42 // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#hitType
43 type HitType = "pageview" | "screenview" | "event" | "transaction" | "item" | "social" | "exception" | "timing";
44
45 // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference
46
47 interface FieldsObject {
48 affiliation?: string | undefined;
49 allowAnchor?: boolean | undefined;
50 allowLinker?: boolean | undefined;
51 alwaysSendReferrer?: boolean | undefined;
52 anonymizeIp?: boolean | undefined;
53 appId?: string | undefined;
54 appInstallerId?: string | undefined;
55 appName?: string | undefined;
56 appVersion?: string | undefined;
57 brand?: string | undefined;
58 campaignId?: string | undefined;
59 campaignContent?: string | undefined;
60 campaignKeyword?: string | undefined;
61 campaignMedium?: string | undefined;
62 campaignName?: string | undefined;
63 campaignSource?: string | undefined;
64 category?: string | undefined;
65 clientId?: string | undefined;
66 contentGroup1?: string | undefined;
67 contentGroup2?: string | undefined;
68 contentGroup3?: string | undefined;
69 contentGroup4?: string | undefined;
70 contentGroup5?: string | undefined;
71 contentGroup6?: string | undefined;
72 contentGroup7?: string | undefined;
73 contentGroup8?: string | undefined;
74 contentGroup9?: string | undefined;
75 contentGroup10?: string | undefined;
76 cookieName?: string | undefined;
77 cookieDomain?: string | undefined;
78 cookieExpires?: number | undefined;
79 cookieFlags?: string | undefined;
80 cookiePath?: string | undefined;
81 cookieUpdate?: boolean | undefined;
82 coupon?: string | undefined;
83 creative?: string | undefined;
84 currencyCode?: string | undefined;
85 dataSource?: string | undefined;
86 dimension1?: string | undefined;
87 dimension2?: string | undefined;
88 dimension3?: string | undefined;
89 dimension4?: string | undefined;
90 dimension5?: string | undefined;
91 dimension6?: string | undefined;
92 dimension7?: string | undefined;
93 dimension8?: string | undefined;
94 dimension9?: string | undefined;
95 dimension10?: string | undefined;
96 dimension11?: string | undefined;
97 dimension12?: string | undefined;
98 dimension13?: string | undefined;
99 dimension14?: string | undefined;
100 dimension15?: string | undefined;
101 dimension16?: string | undefined;
102 dimension17?: string | undefined;
103 dimension18?: string | undefined;
104 dimension19?: string | undefined;
105 dimension20?: string | undefined;
106 dimension21?: string | undefined;
107 dimension22?: string | undefined;
108 dimension23?: string | undefined;
109 dimension24?: string | undefined;
110 dimension25?: string | undefined;
111 dimension26?: string | undefined;
112 dimension27?: string | undefined;
113 dimension28?: string | undefined;
114 dimension29?: string | undefined;
115 dimension30?: string | undefined;
116 dimension31?: string | undefined;
117 dimension32?: string | undefined;
118 dimension33?: string | undefined;
119 dimension34?: string | undefined;
120 dimension35?: string | undefined;
121 dimension36?: string | undefined;
122 dimension37?: string | undefined;
123 dimension38?: string | undefined;
124 dimension39?: string | undefined;
125 dimension40?: string | undefined;
126 dimension41?: string | undefined;
127 dimension42?: string | undefined;
128 dimension43?: string | undefined;
129 dimension44?: string | undefined;
130 dimension45?: string | undefined;
131 dimension46?: string | undefined;
132 dimension47?: string | undefined;
133 dimension48?: string | undefined;
134 dimension49?: string | undefined;
135 dimension50?: string | undefined;
136 dimension51?: string | undefined;
137 dimension52?: string | undefined;
138 dimension53?: string | undefined;
139 dimension54?: string | undefined;
140 dimension55?: string | undefined;
141 dimension56?: string | undefined;
142 dimension57?: string | undefined;
143 dimension58?: string | undefined;
144 dimension59?: string | undefined;
145 dimension60?: string | undefined;
146 dimension61?: string | undefined;
147 dimension62?: string | undefined;
148 dimension63?: string | undefined;
149 dimension64?: string | undefined;
150 dimension65?: string | undefined;
151 dimension66?: string | undefined;
152 dimension67?: string | undefined;
153 dimension68?: string | undefined;
154 dimension69?: string | undefined;
155 dimension70?: string | undefined;
156 dimension71?: string | undefined;
157 dimension72?: string | undefined;
158 dimension73?: string | undefined;
159 dimension74?: string | undefined;
160 dimension75?: string | undefined;
161 dimension76?: string | undefined;
162 dimension77?: string | undefined;
163 dimension78?: string | undefined;
164 dimension79?: string | undefined;
165 dimension80?: string | undefined;
166 dimension81?: string | undefined;
167 dimension82?: string | undefined;
168 dimension83?: string | undefined;
169 dimension84?: string | undefined;
170 dimension85?: string | undefined;
171 dimension86?: string | undefined;
172 dimension87?: string | undefined;
173 dimension88?: string | undefined;
174 dimension89?: string | undefined;
175 dimension90?: string | undefined;
176 dimension91?: string | undefined;
177 dimension92?: string | undefined;
178 dimension93?: string | undefined;
179 dimension94?: string | undefined;
180 dimension95?: string | undefined;
181 dimension96?: string | undefined;
182 dimension97?: string | undefined;
183 dimension98?: string | undefined;
184 dimension99?: string | undefined;
185 dimension100?: string | undefined;
186 dimension101?: string | undefined;
187 dimension102?: string | undefined;
188 dimension103?: string | undefined;
189 dimension104?: string | undefined;
190 dimension105?: string | undefined;
191 dimension106?: string | undefined;
192 dimension107?: string | undefined;
193 dimension108?: string | undefined;
194 dimension109?: string | undefined;
195 dimension110?: string | undefined;
196 dimension111?: string | undefined;
197 dimension112?: string | undefined;
198 dimension113?: string | undefined;
199 dimension114?: string | undefined;
200 dimension115?: string | undefined;
201 dimension116?: string | undefined;
202 dimension117?: string | undefined;
203 dimension118?: string | undefined;
204 dimension119?: string | undefined;
205 dimension120?: string | undefined;
206 dimension121?: string | undefined;
207 dimension122?: string | undefined;
208 dimension123?: string | undefined;
209 dimension124?: string | undefined;
210 dimension125?: string | undefined;
211 dimension126?: string | undefined;
212 dimension127?: string | undefined;
213 dimension128?: string | undefined;
214 dimension129?: string | undefined;
215 dimension130?: string | undefined;
216 dimension131?: string | undefined;
217 dimension132?: string | undefined;
218 dimension133?: string | undefined;
219 dimension134?: string | undefined;
220 dimension135?: string | undefined;
221 dimension136?: string | undefined;
222 dimension137?: string | undefined;
223 dimension138?: string | undefined;
224 dimension139?: string | undefined;
225 dimension140?: string | undefined;
226 dimension141?: string | undefined;
227 dimension142?: string | undefined;
228 dimension143?: string | undefined;
229 dimension144?: string | undefined;
230 dimension145?: string | undefined;
231 dimension146?: string | undefined;
232 dimension147?: string | undefined;
233 dimension148?: string | undefined;
234 dimension149?: string | undefined;
235 dimension150?: string | undefined;
236 dimension151?: string | undefined;
237 dimension152?: string | undefined;
238 dimension153?: string | undefined;
239 dimension154?: string | undefined;
240 dimension155?: string | undefined;
241 dimension156?: string | undefined;
242 dimension157?: string | undefined;
243 dimension158?: string | undefined;
244 dimension159?: string | undefined;
245 dimension160?: string | undefined;
246 dimension161?: string | undefined;
247 dimension162?: string | undefined;
248 dimension163?: string | undefined;
249 dimension164?: string | undefined;
250 dimension165?: string | undefined;
251 dimension166?: string | undefined;
252 dimension167?: string | undefined;
253 dimension168?: string | undefined;
254 dimension169?: string | undefined;
255 dimension170?: string | undefined;
256 dimension171?: string | undefined;
257 dimension172?: string | undefined;
258 dimension173?: string | undefined;
259 dimension174?: string | undefined;
260 dimension175?: string | undefined;
261 dimension176?: string | undefined;
262 dimension177?: string | undefined;
263 dimension178?: string | undefined;
264 dimension179?: string | undefined;
265 dimension180?: string | undefined;
266 dimension181?: string | undefined;
267 dimension182?: string | undefined;
268 dimension183?: string | undefined;
269 dimension184?: string | undefined;
270 dimension185?: string | undefined;
271 dimension186?: string | undefined;
272 dimension187?: string | undefined;
273 dimension188?: string | undefined;
274 dimension189?: string | undefined;
275 dimension190?: string | undefined;
276 dimension191?: string | undefined;
277 dimension192?: string | undefined;
278 dimension193?: string | undefined;
279 dimension194?: string | undefined;
280 dimension195?: string | undefined;
281 dimension196?: string | undefined;
282 dimension197?: string | undefined;
283 dimension198?: string | undefined;
284 dimension199?: string | undefined;
285 dimension200?: string | undefined;
286 encoding?: string | undefined;
287 eventAction?: string | undefined;
288 eventCategory?: string | undefined;
289 eventLabel?: string | undefined;
290 eventValue?: number | undefined;
291 exDescription?: string | undefined;
292 exFatal?: boolean | undefined;
293 expId?: string | undefined;
294 expVar?: string | undefined;
295 flashVersion?: string | undefined;
296 forceSSL?: boolean | undefined;
297 hitCallback?(): void;
298 hitType?: HitType | undefined;
299 hostname?: string | undefined;
300 id?: string | undefined;
301 javaEnabled?: boolean | undefined;
302 language?: string | undefined;
303 legacyCookieDomain?: string | undefined;
304 legacyHistoryImport?: boolean | undefined;
305 linkid?: string | undefined;
306 list?: string | undefined;
307 location?: string | undefined;
308 metric1?: string | number | undefined;
309 metric2?: string | number | undefined;
310 metric3?: string | number | undefined;
311 metric4?: string | number | undefined;
312 metric5?: string | number | undefined;
313 metric6?: string | number | undefined;
314 metric7?: string | number | undefined;
315 metric8?: string | number | undefined;
316 metric9?: string | number | undefined;
317 metric10?: string | number | undefined;
318 metric11?: string | number | undefined;
319 metric12?: string | number | undefined;
320 metric13?: string | number | undefined;
321 metric14?: string | number | undefined;
322 metric15?: string | number | undefined;
323 metric16?: string | number | undefined;
324 metric17?: string | number | undefined;
325 metric18?: string | number | undefined;
326 metric19?: string | number | undefined;
327 metric20?: string | number | undefined;
328 metric21?: string | number | undefined;
329 metric22?: string | number | undefined;
330 metric23?: string | number | undefined;
331 metric24?: string | number | undefined;
332 metric25?: string | number | undefined;
333 metric26?: string | number | undefined;
334 metric27?: string | number | undefined;
335 metric28?: string | number | undefined;
336 metric29?: string | number | undefined;
337 metric30?: string | number | undefined;
338 metric31?: string | number | undefined;
339 metric32?: string | number | undefined;
340 metric33?: string | number | undefined;
341 metric34?: string | number | undefined;
342 metric35?: string | number | undefined;
343 metric36?: string | number | undefined;
344 metric37?: string | number | undefined;
345 metric38?: string | number | undefined;
346 metric39?: string | number | undefined;
347 metric40?: string | number | undefined;
348 metric41?: string | number | undefined;
349 metric42?: string | number | undefined;
350 metric43?: string | number | undefined;
351 metric44?: string | number | undefined;
352 metric45?: string | number | undefined;
353 metric46?: string | number | undefined;
354 metric47?: string | number | undefined;
355 metric48?: string | number | undefined;
356 metric49?: string | number | undefined;
357 metric50?: string | number | undefined;
358 metric51?: string | number | undefined;
359 metric52?: string | number | undefined;
360 metric53?: string | number | undefined;
361 metric54?: string | number | undefined;
362 metric55?: string | number | undefined;
363 metric56?: string | number | undefined;
364 metric57?: string | number | undefined;
365 metric58?: string | number | undefined;
366 metric59?: string | number | undefined;
367 metric60?: string | number | undefined;
368 metric61?: string | number | undefined;
369 metric62?: string | number | undefined;
370 metric63?: string | number | undefined;
371 metric64?: string | number | undefined;
372 metric65?: string | number | undefined;
373 metric66?: string | number | undefined;
374 metric67?: string | number | undefined;
375 metric68?: string | number | undefined;
376 metric69?: string | number | undefined;
377 metric70?: string | number | undefined;
378 metric71?: string | number | undefined;
379 metric72?: string | number | undefined;
380 metric73?: string | number | undefined;
381 metric74?: string | number | undefined;
382 metric75?: string | number | undefined;
383 metric76?: string | number | undefined;
384 metric77?: string | number | undefined;
385 metric78?: string | number | undefined;
386 metric79?: string | number | undefined;
387 metric80?: string | number | undefined;
388 metric81?: string | number | undefined;
389 metric82?: string | number | undefined;
390 metric83?: string | number | undefined;
391 metric84?: string | number | undefined;
392 metric85?: string | number | undefined;
393 metric86?: string | number | undefined;
394 metric87?: string | number | undefined;
395 metric88?: string | number | undefined;
396 metric89?: string | number | undefined;
397 metric90?: string | number | undefined;
398 metric91?: string | number | undefined;
399 metric92?: string | number | undefined;
400 metric93?: string | number | undefined;
401 metric94?: string | number | undefined;
402 metric95?: string | number | undefined;
403 metric96?: string | number | undefined;
404 metric97?: string | number | undefined;
405 metric98?: string | number | undefined;
406 metric99?: string | number | undefined;
407 metric100?: string | number | undefined;
408 metric101?: string | number | undefined;
409 metric102?: string | number | undefined;
410 metric103?: string | number | undefined;
411 metric104?: string | number | undefined;
412 metric105?: string | number | undefined;
413 metric106?: string | number | undefined;
414 metric107?: string | number | undefined;
415 metric108?: string | number | undefined;
416 metric109?: string | number | undefined;
417 metric110?: string | number | undefined;
418 metric111?: string | number | undefined;
419 metric112?: string | number | undefined;
420 metric113?: string | number | undefined;
421 metric114?: string | number | undefined;
422 metric115?: string | number | undefined;
423 metric116?: string | number | undefined;
424 metric117?: string | number | undefined;
425 metric118?: string | number | undefined;
426 metric119?: string | number | undefined;
427 metric120?: string | number | undefined;
428 metric121?: string | number | undefined;
429 metric122?: string | number | undefined;
430 metric123?: string | number | undefined;
431 metric124?: string | number | undefined;
432 metric125?: string | number | undefined;
433 metric126?: string | number | undefined;
434 metric127?: string | number | undefined;
435 metric128?: string | number | undefined;
436 metric129?: string | number | undefined;
437 metric130?: string | number | undefined;
438 metric131?: string | number | undefined;
439 metric132?: string | number | undefined;
440 metric133?: string | number | undefined;
441 metric134?: string | number | undefined;
442 metric135?: string | number | undefined;
443 metric136?: string | number | undefined;
444 metric137?: string | number | undefined;
445 metric138?: string | number | undefined;
446 metric139?: string | number | undefined;
447 metric140?: string | number | undefined;
448 metric141?: string | number | undefined;
449 metric142?: string | number | undefined;
450 metric143?: string | number | undefined;
451 metric144?: string | number | undefined;
452 metric145?: string | number | undefined;
453 metric146?: string | number | undefined;
454 metric147?: string | number | undefined;
455 metric148?: string | number | undefined;
456 metric149?: string | number | undefined;
457 metric150?: string | number | undefined;
458 metric151?: string | number | undefined;
459 metric152?: string | number | undefined;
460 metric153?: string | number | undefined;
461 metric154?: string | number | undefined;
462 metric155?: string | number | undefined;
463 metric156?: string | number | undefined;
464 metric157?: string | number | undefined;
465 metric158?: string | number | undefined;
466 metric159?: string | number | undefined;
467 metric160?: string | number | undefined;
468 metric161?: string | number | undefined;
469 metric162?: string | number | undefined;
470 metric163?: string | number | undefined;
471 metric164?: string | number | undefined;
472 metric165?: string | number | undefined;
473 metric166?: string | number | undefined;
474 metric167?: string | number | undefined;
475 metric168?: string | number | undefined;
476 metric169?: string | number | undefined;
477 metric170?: string | number | undefined;
478 metric171?: string | number | undefined;
479 metric172?: string | number | undefined;
480 metric173?: string | number | undefined;
481 metric174?: string | number | undefined;
482 metric175?: string | number | undefined;
483 metric176?: string | number | undefined;
484 metric177?: string | number | undefined;
485 metric178?: string | number | undefined;
486 metric179?: string | number | undefined;
487 metric180?: string | number | undefined;
488 metric181?: string | number | undefined;
489 metric182?: string | number | undefined;
490 metric183?: string | number | undefined;
491 metric184?: string | number | undefined;
492 metric185?: string | number | undefined;
493 metric186?: string | number | undefined;
494 metric187?: string | number | undefined;
495 metric188?: string | number | undefined;
496 metric189?: string | number | undefined;
497 metric190?: string | number | undefined;
498 metric191?: string | number | undefined;
499 metric192?: string | number | undefined;
500 metric193?: string | number | undefined;
501 metric194?: string | number | undefined;
502 metric195?: string | number | undefined;
503 metric196?: string | number | undefined;
504 metric197?: string | number | undefined;
505 metric198?: string | number | undefined;
506 metric199?: string | number | undefined;
507 metric200?: string | number | undefined;
508 name?: string | undefined;
509 nonInteraction?: boolean | undefined;
510 option?: string | undefined;
511 page?: string | undefined;
512 position?: number | string | undefined;
513 price?: string | undefined;
514 quantity?: number | undefined;
515 queueTime?: number | undefined;
516 referrer?: string | undefined;
517 revenue?: string | undefined;
518 sampleRate?: number | undefined;
519 sessionControl?: string | undefined;
520 siteSpeedSampleRate?: number | undefined;
521 screenColors?: string | undefined;
522 screenName?: string | undefined;
523 screenResolution?: string | undefined;
524 shipping?: string | undefined;
525 socialAction?: string | undefined;
526 socialNetwork?: string | undefined;
527 socialTarget?: string | undefined;
528 some?: string | undefined;
529 step?: boolean | number | undefined;
530 storage?: string | undefined;
531 storeGac?: boolean | undefined;
532 tax?: string | undefined;
533 timingCategory?: string | undefined;
534 timingLabel?: string | undefined;
535 timingValue?: number | undefined;
536 timingVar?: string | undefined;
537 title?: string | undefined;
538 transport?: string | undefined;
539 useBeacon?: boolean | undefined;
540 userId?: string | undefined;
541 variant?: string | undefined;
542 viewportSize?: string | undefined;
543 }
544
545 interface ga {
546 l: number;
547 q: any[];
548
549 (
550 command: "send",
551 hitType: "event",
552 eventCategory: string,
553 eventAction: string,
554 eventLabel?: string,
555 eventValue?: number,
556 fieldsObject?: FieldsObject,
557 ): void;
558 (
559 command: "send",
560 hitType: "event",
561 fieldsObject: {
562 eventCategory: string;
563 eventAction: string;
564 eventLabel?: string | undefined;
565 eventValue?: number | undefined;
566 nonInteraction?: boolean | undefined;
567 },
568 ): void;
569 (
570 command: "send",
571 fieldsObject: {
572 hitType: HitType; // 'event'
573 eventCategory: string;
574 eventAction: string;
575 eventLabel?: string | undefined;
576 eventValue?: number | undefined;
577 nonInteraction?: boolean | undefined;
578 },
579 ): void;
580 (command: "send", hitType: "pageview", page: string): void;
581 (
582 command: "send",
583 hitType: "social",
584 socialNetwork: string,
585 socialAction: string,
586 socialTarget: string,
587 ): void;
588 (
589 command: "send",
590 hitType: "social",
591 fieldsObject: {
592 socialNetwork: string;
593 socialAction: string;
594 socialTarget: string;
595 },
596 ): void;
597 (
598 command: "send",
599 hitType: "timing",
600 timingCategory: string,
601 timingVar: string,
602 timingValue: number,
603 ): void;
604 (
605 command: "send",
606 hitType: "timing",
607 fieldsObject: {
608 timingCategory: string;
609 timingVar: string;
610 timingValue: number;
611 },
612 ): void;
613 (command: "send", fieldsObject: FieldsObject): void;
614 (command: string, hitType: HitType, ...fields: any[]): void;
615 (command: "require", pluginName: string, pluginOptions?: any): void;
616 (
617 command: "provide",
618 pluginName: string,
619 pluginConstructor: (tracker: Tracker, pluginOptions?: Object) => void,
620 ): void;
621
622 (
623 command: "create",
624 trackingId: string,
625 cookieDomain?: string,
626 name?: string,
627 fieldsObject?: FieldsObject,
628 ): void;
629 (command: "remove"): void;
630
631 (command: string, ...fields: any[]): void;
632
633 (readyCallback: (defaultTracker?: Tracker) => void): void;
634
635 create(trackingId: string, cookieDomain: string, name: string, fieldsObject?: FieldsObject): Tracker;
636 create(trackingId: string, cookieDomain: string, fieldsObject?: FieldsObject): Tracker;
637 create(trackingId: string, fieldsObject?: FieldsObject): Tracker;
638
639 getAll(): Tracker[];
640 getByName(name: string): Tracker;
641 remove(name: string): void;
642 }
643
644 interface Tracker {
645 get(fieldName: string): any;
646 set(fieldName: string, fieldValue: any): void;
647 set(fieldsObject: {}): void;
648 send(hitType: string, ...fields: any[]): void;
649 send(hitType: string, fieldsObject: {}): void;
650 }
651
652 interface Model {
653 get(fieldName: string): any;
654 set(fieldName: string, fieldValue: any, temporary?: boolean): void;
655 set(fields: {}, fieldValue?: null, temporary?: boolean): void;
656 }
657}
658
659declare var gaClassic: GoogleAnalytics;
660declare var ga: UniversalAnalytics.ga;
661declare var _gaq: GoogleAnalyticsCode;
662declare var _gat: GoogleAnalyticsTracker;