-
Notifications
You must be signed in to change notification settings - Fork 67
/
vue-gtag.d.ts
319 lines (285 loc) · 9.07 KB
/
vue-gtag.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
declare module "vue-gtag" {
import type { App } from "vue";
import type { Router, RouteLocationNormalized } from "vue-router";
/**
* Types copied from @types/gtag.js.
*
* @see https://www.npmjs.com/package/@types/gtag.js
*/
namespace Gtag {
interface Gtag {
(command: 'config', targetId: string, config?: ControlParams | EventParams | CustomParams): void;
(command: 'set', config: CustomParams): void;
(command: 'js', config: Date): void;
(command: 'event', eventName: EventNames | string, eventParams?: ControlParams | EventParams | CustomParams): void;
}
interface CustomParams {
[key: string]: any;
}
interface ControlParams {
groups?: string | string[];
send_to?: string | string[];
event_callback?: () => void;
event_timeout?: number;
}
type EventNames = 'add_payment_info'
| 'add_to_cart'
| 'add_to_wishlist'
| 'begin_checkout'
| 'checkout_progress'
| 'exception'
| 'generate_lead'
| 'login'
| 'page_view'
| 'purchase'
| 'refund'
| 'remove_from_cart'
| 'screen_view'
| 'search'
| 'select_content'
| 'set_checkout_option'
| 'share'
| 'sign_up'
| 'timing_complete'
| 'view_item'
| 'view_item_list'
| 'view_promotion'
| 'view_search_results';
interface EventParams {
checkout_option?: string;
checkout_step?: number;
content_id?: string;
content_type?: string;
coupon?: string;
currency?: string;
description?: string;
fatal?: boolean;
items?: Item[];
method?: string;
number?: string;
promotions?: Promotion[];
screen_name?: string;
search_term?: string;
shipping?: Currency;
tax?: Currency;
transaction_id?: string;
value?: number;
event_label?: string;
event_category?: string;
non_interaction?: boolean
}
type Currency = string | number;
interface Item {
brand?: string;
category?: string;
creative_name?: string;
creative_slot?: string;
id?: string;
location_id?: string;
name?: string;
price?: Currency;
quantity?: number;
}
interface Promotion {
creative_name?: string;
creative_slot?: string;
id?: string;
name?: string;
}
}
export interface PageView {
/** The page's title. */
page_title?: string;
/** The page's URL. */
page_location?: string;
/** The path portion of location. This value must start with a slash (/) character. */
page_path?: string;
}
export interface ScreenView {
/** The name of the screen. */
screen_name: string;
/** The name of the application. */
app_name: string;
}
/**
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#action_data
*/
export interface EcommerceAction {
/** Unique ID for the transaction. */
transaction_id: string;
/** The store or affiliation from which this transaction occurred */
affiliation?: string;
/** Value (i.e., revenue) associated with the event */
value?: number;
/** Tax amount */
tax?: number;
/** Shipping cost */
shipping?: number;
/** The array containing the associated products */
items?: Gtag.Item[];
/** The step (a number) in the checkout process */
checkout_step?: number;
/** Checkout option (i.e. selected payment method) */
checkout_option?: string;
}
export interface Linker {
domains: string[];
decorate_forms?: boolean;
accept_incoming?: boolean;
url_position?: "fragment" | "query";
}
export interface Exception {
/** A description of the error. */
description?: string;
/** true if the error was fatal. */
fatal?: boolean;
}
export interface Timing {
/** A string to identify the variable being recorded (e.g. 'load'). */
name: string;
/** The number of milliseconds in elapsed time to report to Google Analytics (e.g. 20). */
value: number;
/** A string for categorizing all user timing variables into logical groups (e.g. 'JS Dependencies'). */
event_category?: string;
/** A string that can be used to add flexibility in visualizing user timings in the reports (e.g. 'Google CDN'). */
event_label?: string;
}
export type GtagOptIO = () => void;
/**
* Send a Google Analytics Event.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/events
*
* @param action string that will appear as the event action in Google Analytics Event reports
* @param eventParams
*/
export type GtagEvent = (action: Gtag.EventNames | string, eventParams?: Gtag.ControlParams | Gtag.EventParams | Gtag.CustomParams) => void;
/**
* Send an ad-hoc Google Analytics pageview.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/pages
*/
export type GtagPageView = (pageView: PageView) => void;
/**
* Send a Google Analytics screen view.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/screens
*/
export type GtagScreenView = (screenView: ScreenView) => void;
/**
* Configure a map of custom dimensions and metrics.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
*/
export type GtagCustomMap = (map: Dictionary<string>) => void;
/**
* Measure a transaction.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_purchases
*/
export type GtagPurchase = (purchase: EcommerceAction) => void;
/**
* Send user timing information to Google Analytics.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/user-timings
*/
export type GtagTime = (timing: Timing) => void;
/**
* Measure an exception.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/exceptions
*/
export type GtagException = (ex: Exception) => void;
/**
* Automatically link domains.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/cross-domain#automatically_link_domains
*/
export type GtagLinker = (config: Linker) => void;
/**
* Set parameters that will be associated with every subsequent event on the page.
*
* @see https://developers.google.com/gtagjs/devguide/configure#send_data_on_every_event_with_set
*/
export type GtagSet = (config: Gtag.CustomParams) => void;
/**
* Initialize and configure settings for a particular product account.
*
* @see https://developers.google.com/gtagjs/devguide/configure
*/
export type GtagConfig = (config?: Gtag.ControlParams | Gtag.EventParams | Gtag.CustomParams) => void;
/**
* Measure a full refund of a transaction.
*
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_refunds
*/
export type GtagRefund = (refund: EcommerceAction) => void;
export type Dictionary<T> = { [key: string]: T };
export interface VueGtag {
query: Gtag.Gtag;
optIn: GtagOptIO;
optOut: GtagOptIO;
pageview: GtagPageView;
event: GtagEvent;
screenview: GtagScreenView;
customMap: GtagCustomMap;
purchase: GtagPurchase;
refund: GtagRefund;
linker: GtagLinker;
exception: GtagException;
set: GtagSet;
config: GtagConfig;
time: GtagTime;
}
export interface DomainConfig {
id: string;
params?: Gtag.ControlParams | Gtag.EventParams | Gtag.CustomParams;
}
export interface PluginOptions {
appName?: string;
pageTrackerTemplate?: (to: RouteLocationNormalized, from: RouteLocationNormalized) => PageView;
onBeforeTrack?: (to: RouteLocationNormalized, from?: RouteLocationNormalized) => void;
onAfterTrack?: (to: RouteLocationNormalized, from?: RouteLocationNormalized) => void;
onReady?: (gtag: Gtag.Gtag) => void;
enabled?: boolean;
deferScriptLoad?: boolean;
customResourceURL: string;
disableScriptLoad?: boolean;
bootstrap?: boolean;
globalObjectName?: string;
pageTrackerEnabled?: boolean;
pageTrackerScreenviewEnabled?: boolean;
defaultGroupName?: string;
includes?: DomainConfig[];
config?: DomainConfig;
}
export class VueGtagPlugin {
static install(
app: App,
options: PluginOptions,
router?: Router
): void;
}
export function bootstrap(): Promise<Gtag.Gtag>;
export function setOptions(options: PluginOptions): void;
export default VueGtagPlugin;
export const query: Gtag.Gtag;
export const config: GtagConfig;
export const event: GtagEvent;
export const pageview: GtagPageView;
export const screenview: GtagScreenView;
export const customMap: GtagCustomMap;
export const time: GtagTime;
export const exception: GtagException;
export const linker: GtagLinker;
export const purchase: GtagPurchase;
export const set: GtagSet;
export const optIn: GtagOptIO;
export const optOut: GtagOptIO;
export const refund: GtagRefund;
module "vue/types/vue" {
interface Vue {
$gtag: VueGtag;
}
}
}