1
- declare module 'vue-gtag' {
2
- import _Vue , { PluginFunction } from 'vue' ;
3
- import VueRouter from 'vue-router' ;
1
+ declare module "vue-gtag" {
2
+ import VueRouter from "vue-router" ;
3
+ import _Vue , { PluginFunction } from "vue" ;
4
+ type Currency = string | number ;
5
+
6
+ type EventNames =
7
+ | "add_payment_info"
8
+ | "add_to_cart"
9
+ | "add_to_wishlist"
10
+ | "begin_checkout"
11
+ | "checkout_progress"
12
+ | "exception"
13
+ | "generate_lead"
14
+ | "login"
15
+ | "page_view"
16
+ | "purchase"
17
+ | "refund"
18
+ | "remove_from_cart"
19
+ | "screen_view"
20
+ | "search"
21
+ | "select_content"
22
+ | "set_checkout_option"
23
+ | "share"
24
+ | "sign_up"
25
+ | "timing_complete"
26
+ | "view_item"
27
+ | "view_item_list"
28
+ | "view_promotion"
29
+ | "view_search_results" ;
30
+
31
+ interface GtagPromotion {
32
+ creative_name ?: string ;
33
+ creative_slot ?: string ;
34
+ id ?: string ;
35
+ name ?: string ;
36
+ }
37
+ interface GtagItem {
38
+ brand ?: string ;
39
+ category ?: string ;
40
+ creative_name ?: string ;
41
+ creative_slot ?: string ;
42
+ id ?: string ;
43
+ location_id ?: string ;
44
+ name ?: string ;
45
+ price ?: Currency ;
46
+ quantity ?: number ;
47
+ }
48
+
49
+ type GtagControlParams = {
50
+ groups ?: string | string [ ] ;
51
+ send_to ?: string | string [ ] ;
52
+ event_callback ?: ( ) => void ;
53
+ event_timeout ?: number ;
54
+ } ;
55
+
56
+ type GtagEventParams = {
57
+ checkout_option ?: string ;
58
+ checkout_step ?: number ;
59
+ content_id ?: string ;
60
+ content_type ?: string ;
61
+ coupon ?: string ;
62
+ currency ?: string ;
63
+ description ?: string ;
64
+ fatal ?: boolean ;
65
+ items ?: GtagItem [ ] ;
66
+ method ?: string ;
67
+ number ?: string ;
68
+ promotions ?: GtagPromotion [ ] ;
69
+ screen_name ?: string ;
70
+ search_term ?: string ;
71
+ shipping ?: Currency ;
72
+ tax ?: Currency ;
73
+ transaction_id ?: string ;
74
+ value ?: number ;
75
+ event_label ?: string ;
76
+ event_category ?: string ;
77
+ } ;
78
+ interface CustomParams {
79
+ [ key : string ] : any ;
80
+ }
81
+ interface Gtag {
82
+ (
83
+ command : "config" ,
84
+ targetId : string ,
85
+ config ?: GtagControlParams | GtagEventParams | CustomParams
86
+ ) : void ;
87
+ ( command : "set" , config : CustomParams ) : void ;
88
+ ( command : "js" , config : Date ) : void ;
89
+ (
90
+ command : "event" ,
91
+ eventName : EventNames | string ,
92
+ eventParams ?: GtagControlParams | GtagEventParams | CustomParams
93
+ ) : void ;
94
+ }
95
+ type GtagGenericParams = GtagControlParams | GtagEventParams | CustomParams ;
4
96
5
97
export interface PageView {
6
98
page_title : string ;
7
99
page_location : string ;
8
100
page_path : string ;
9
101
}
10
102
11
- export interface EventParams {
12
- /** string that will appear as the event category */
13
- event_category ?: string ;
14
- /** string that will appear as the event label */
15
- event_label ?: string ;
16
- /** non-negative integer that will appear as the event value */
17
- value ?: number ;
18
- [ key : string ] : any ;
103
+ export interface Event extends GtagEventParams {
104
+ event_category : string ;
105
+ event_label : string ;
106
+ value : number ;
19
107
}
20
108
21
109
export interface ScreenView {
@@ -25,8 +113,13 @@ declare module 'vue-gtag' {
25
113
26
114
export interface Purchase {
27
115
transaction_id : string ;
28
- affiliation : string ;
29
- value : number ;
116
+ affiliation ?: string ;
117
+ value ?: number ;
118
+ tax ?: number ;
119
+ shipping ?: number ;
120
+ items ?: GtagItem [ ] ;
121
+ checkout_step ?: number ;
122
+ checkout_option ?: string ;
30
123
}
31
124
32
125
export interface Refund {
@@ -37,38 +130,58 @@ declare module 'vue-gtag' {
37
130
38
131
export interface Linker {
39
132
domains : string [ ] ;
133
+ decorate_forms ?: boolean ;
134
+ accept_incoming ?: boolean ;
135
+ url_position ?: "fragment" | "query" ;
40
136
}
41
137
42
138
export interface Exception {
43
139
description : string ;
44
140
fatal : boolean ;
45
141
}
46
142
143
+ export interface Timing {
144
+ name : string ;
145
+ value : number ;
146
+ event_category ?: string ;
147
+ event_label ?: string ;
148
+ }
149
+
47
150
export type Dictionary < T > = { [ key : string ] : T } ;
48
151
49
152
export interface VueGtag {
153
+ optIn ( ) : void ;
154
+ optOut ( ) : void ;
50
155
pageview ( pageView : PageView ) : void ;
51
-
52
156
/**
53
157
* Send a Google Analytics Event.
54
158
*
55
159
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/events
56
160
*
57
161
* @param action string that will appear as the event action in Google Analytics Event reports
58
- * @param eventParams
162
+ * @param event
59
163
*/
60
- event ( action : string , eventParams ?: EventParams ) : void ;
164
+ event ( action : EventNames | string , event : Event ) : void ;
61
165
screenview ( screenView : ScreenView ) : void ;
62
166
customMap ( map : Dictionary < string > ) : void ;
167
+ purchase ( puchase : Event ) : void ;
63
168
purchase ( purchase : Purchase ) : void ;
64
169
refund ( refund : Refund ) : void ;
65
170
linker ( config : Linker ) : void ;
66
171
exception ( ex : Exception ) : void ;
172
+ set ( config : CustomParams ) : void ;
173
+ config ( config ?: GtagGenericParams ) ;
174
+ time ( timing : Timing ) ;
175
+ }
176
+
177
+ export interface DomainConfig {
178
+ id : string ;
179
+ params ?: GtagGenericParams & { send_page_view : boolean } ;
67
180
}
68
181
69
182
export interface PluginOptions {
70
183
appName ?: string ;
71
- pageTrackerTemplate ?: ( ) => void ;
184
+ pageTrackerTemplate ?: ( ) => PageView ;
72
185
onBeforeTrack ?: ( ) => void ;
73
186
onAfterTrack ?: ( ) => void ;
74
187
onReady ?: ( ) => void ;
@@ -79,20 +192,24 @@ declare module 'vue-gtag' {
79
192
pageTrackerEnabled ?: boolean ;
80
193
pageTrackerScreenviewEnabled ?: boolean ;
81
194
defaultGroupName ?: string ;
82
- includes ?: any ;
83
- config ?: {
84
- id : string ,
85
- params ?: Dictionary < any >
86
- } ;
195
+ includes ?: DomainConfig [ ] ;
196
+ config ?: DomainConfig ;
87
197
}
88
198
89
199
export class VueGtagPlugin {
90
- static install ( Vue : typeof _Vue , options : PluginOptions , router ?: VueRouter ) : void ;
200
+ static install (
201
+ Vue : typeof _Vue ,
202
+ options : PluginOptions ,
203
+ router ?: VueRouter
204
+ ) : void ;
91
205
}
92
206
207
+ export function bootstrap ( ) : Promise < Gtag > ;
208
+ export function setOptions ( PluginOptions ) : void ;
209
+
93
210
export default VueGtagPlugin ;
94
211
95
- module ' vue/types/vue' {
212
+ module " vue/types/vue" {
96
213
interface Vue {
97
214
$gtag : VueGtag ;
98
215
}
0 commit comments