forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ga.d.ts
106 lines (91 loc) · 4.26 KB
/
ga.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
// Type definitions for Google Analytics (Classic and Universal)
// Project: https://developers.google.com/analytics/devguides/collection/gajs/, https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference
// Definitions by: Ronnie Haakon Hegelund <http://ronniehegelund.blogspot.dk>, Pat Kujawa <http://patkujawa.com>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class Tracker {
_trackPageview(): void;
_getName(): string;
_getAccount(): string;
_getVersion(): string;
_getVisitorCustomVar(index: number): string;
_setAccount(): string;
_setCustomVar(index: number, name: string, value: string, opt_scope?: number): boolean;
_setSampleRate(newRate: string): void;
_setSessionCookieTimeout(cookieTimeoutMillis: number): void;
_setSiteSpeedSampleRate(sampleRate: number): void;
_setVisitorCookieTimeout(milliseconds: number): void;
_trackPageLoadTime(): void;
}
interface GoogleAnalyticsCode {
push(commandArray: string[]): void;
push(func: Function): void;
}
interface GoogleAnalyticsTracker {
_getTracker(account: string): Tracker;
_createTracker(opt_account: string, opt_name?: string): Tracker;
_getTrackerByName(opt_name?: string): Tracker;
_anonymizeIp(): void;
}
interface GoogleAnalytics {
type: string;
src: string;
async: boolean;
}
declare namespace UniversalAnalytics {
// https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference
enum HitType {
'pageview', 'screenview', 'event', 'transaction', 'item', 'social', 'exception', 'timing'
}
interface ga {
l: number;
q: any[];
(command: 'send', hitType: 'event', eventCategory: string, eventAction: string,
eventLabel?: string, eventValue?: number, fieldsObject?: {}): void;
(command: 'send', hitType: 'event', fieldsObject: {
eventCategory: string,
eventAction: string,
eventLabel?: string,
eventValue?: number,
nonInteraction?: boolean}): void;
(command: 'send', fieldsObject: {
hitType: HitType, // 'event'
eventCategory: string,
eventAction: string,
eventLabel?: string,
eventValue?: number,
nonInteraction?: boolean}): void;
(command: 'send', hitType: 'pageview', page: string): void;
(command: 'send', hitType: 'social',
socialNetwork: string, socialAction: string, socialTarget: string): void;
(command: 'send', hitType: 'social',
fieldsObject: {socialNetwork: string, socialAction: string, socialTarget: string}): void;
(command: 'send', hitType: 'timing',
timingCategory: string, timingVar: string, timingValue: number): void;
(command: 'send', hitType: 'timing',
fieldsObject: {timingCategory: string, timingVar: string, timingValue: number}): void;
(command: 'send', fieldsObject: {}): void;
(command: string, hitType: HitType, ...fields: any[]): void;
(command: 'create', trackingId: string, cookieDomain?: string, name?: string, fieldsObject?: {}): void;
(command: 'remove'): void;
(command: string, ...fields: any[]): void;
(readyCallback: (defaultTracker?: UniversalAnalytics.Tracker) => void): void;
create(trackingId: string, cookieDomain: string, name: string, fieldsObject?: {}): UniversalAnalytics.Tracker;
create(trackingId: string, cookieDomain: string, fieldsObject?: {}): UniversalAnalytics.Tracker;
create(trackingId: string, fieldsObject?: {}): UniversalAnalytics.Tracker;
getAll(): UniversalAnalytics.Tracker[];
getByName(name: string): UniversalAnalytics.Tracker;
remove(name:string): void;
}
interface Tracker {
get<T>(fieldName: string): T;
send(hitType: string, opt_fieldObject?: {}): void;
set(fieldName: string, value: string): void;
set(fieldName: string, value: {}): void;
set(fieldName: string, value: number): void;
set(fieldName: string, value: boolean): void;
}
}
declare var gaClassic: GoogleAnalytics;
declare var ga: UniversalAnalytics.ga;
declare var _gaq: GoogleAnalyticsCode;
declare var _gat: GoogleAnalyticsTracker;