|
2 | 2 | declare module 'vue-analytics' { |
3 | 3 | import _Vue, { PluginFunction } from 'vue'; |
4 | 4 | import VueRouter, { Route } from 'vue-router'; |
| 5 | + import { Store } from 'vuex'; |
5 | 6 |
|
6 | 7 | interface eventFn { |
7 | 8 | (category: string, action?: string, label?: string, value?: number): void; |
@@ -51,73 +52,220 @@ declare module 'vue-analytics' { |
51 | 52 | }): void; |
52 | 53 | } |
53 | 54 |
|
54 | | - export default class VueAnalytics { |
55 | | - static install(Vue: typeof _Vue, options: { |
56 | | - id: string | string[] | (() => string) | (() => Promise<string>) | Promise<string>, |
57 | | - router?: VueRouter, |
58 | | - ignoreRoutes?: string[], |
59 | | - debug?: { |
60 | | - enabled?: boolean, |
61 | | - trace?: boolean, |
62 | | - sendHitTask?: boolean |
63 | | - }, |
64 | | - batch?: { |
65 | | - enabled?: boolean, |
66 | | - amount?: number, |
67 | | - delay?: number |
68 | | - }, |
69 | | - linkers?: string[], |
70 | | - customResourceURL?: string, |
71 | | - ecommerce?: { |
72 | | - enabled?: boolean, |
73 | | - enhanced?: boolean, |
74 | | - options?: any |
75 | | - }, |
76 | | - autoTracking?: { |
77 | | - exception?: boolean, |
78 | | - exceptionLogs?: boolean, |
79 | | - screenview?: boolean, |
80 | | - pageviewOnLoad?: boolean, |
81 | | - page?: boolean, |
82 | | - pageviewTemplate?: (route: Route) => pageDetails, |
83 | | - transformQueryString?: boolean, |
84 | | - prependBase?: boolean, |
85 | | - skipSamePath: boolean, |
86 | | - shouldRouterUpdate: (to: Route, from: Route) => string, |
87 | | - untracked?: boolean |
88 | | - }, |
89 | | - fields?: { |
90 | | - [field: string]: any |
91 | | - }, |
92 | | - customIdFields?: { |
93 | | - [id: string]: { |
94 | | - [field: string]: any |
95 | | - } |
96 | | - }, |
97 | | - disabled?: boolean | (() => boolean) | (() => Promise<boolean>) | Promise<boolean>, |
98 | | - checkDuplicatedScript?: boolean, |
99 | | - disableScriptLoader?: boolean |
100 | | - set?: { field: string, value: string }[], |
101 | | - commands?: any, |
102 | | - beforeFirstHit?: () => void, |
103 | | - ready?: () => void |
| 55 | + interface EcommerceItem { |
| 56 | + id: string; |
| 57 | + name: string; |
| 58 | + sku?: string; |
| 59 | + category?: string; |
| 60 | + price?: string; |
| 61 | + quantity?: number; |
| 62 | + } |
| 63 | + |
| 64 | + interface EcommerceTransaction { |
| 65 | + id: string; |
| 66 | + affiliation?: string; |
| 67 | + revenue?: string; |
| 68 | + shipping?: string; |
| 69 | + tax?: string; |
| 70 | + } |
| 71 | + |
| 72 | + interface EcommerceImpressionBase { |
| 73 | + list?: string; |
| 74 | + brand?: string; |
| 75 | + category?: string; |
| 76 | + variant?: string; |
| 77 | + position?: number; |
| 78 | + price?: string; |
| 79 | + } |
| 80 | + |
| 81 | + interface EcommerceImpressionWithId extends EcommerceImpressionBase { |
| 82 | + id: string; |
| 83 | + } |
| 84 | + |
| 85 | + interface EcommerceImpressionWithName extends EcommerceImpressionBase { |
| 86 | + name: string; |
| 87 | + } |
| 88 | + |
| 89 | + type EcommerceImpression = EcommerceImpressionWithId | EcommerceImpressionWithName; |
| 90 | + |
| 91 | + interface EcommerceProductBase { |
| 92 | + brand?: string; |
| 93 | + category?: string; |
| 94 | + variant?: string; |
| 95 | + price?: string; |
| 96 | + quantity?: number; |
| 97 | + coupon?: string; |
| 98 | + position?: number; |
| 99 | + } |
| 100 | + |
| 101 | + interface EcommerceProductWithId extends EcommerceProductBase { |
| 102 | + id: string; |
| 103 | + } |
| 104 | + |
| 105 | + interface EcommerceProductWithName extends EcommerceProductBase { |
| 106 | + name: string; |
| 107 | + } |
| 108 | + |
| 109 | + type EcommerceProduct = EcommerceImpressionWithId | EcommerceImpressionWithName; |
| 110 | + |
| 111 | + type EcommerceAction = |
| 112 | + | 'click' |
| 113 | + | 'detail' |
| 114 | + | 'add' |
| 115 | + | 'remove' |
| 116 | + | 'checkout' |
| 117 | + | 'checkout_option' |
| 118 | + | 'purchase' |
| 119 | + | 'refund' |
| 120 | + | 'promo_click' |
| 121 | + |
| 122 | + interface EcommerceActionData { |
| 123 | + id?: string; |
| 124 | + affiliation?: string; |
| 125 | + revenue?: number; |
| 126 | + tax?: number; |
| 127 | + shipping?: number; |
| 128 | + coupon?: string; |
| 129 | + list?: string; |
| 130 | + step?: number; |
| 131 | + option?: string; |
| 132 | + } |
| 133 | + |
| 134 | + interface EcommercePromoBase { |
| 135 | + creative?: string; |
| 136 | + position?: string; |
| 137 | + } |
| 138 | + |
| 139 | + interface EcommercePromoWithId extends EcommercePromoBase { |
| 140 | + id: string; |
| 141 | + } |
| 142 | + |
| 143 | + interface EcommercePromoWithName extends EcommercePromoBase { |
| 144 | + name: string; |
| 145 | + } |
| 146 | + |
| 147 | + type EcommercePromo = EcommercePromoWithId | EcommercePromoWithName; |
| 148 | + |
| 149 | + interface Ecommerce { |
| 150 | + addItem(item: EcommerceItem): void; |
| 151 | + addTransaction(transaction: EcommerceTransaction): void; |
| 152 | + addProduct(product: EcommerceProduct): void; |
| 153 | + addImpression(impression: EcommerceImpression): void; |
| 154 | + setAction(action: EcommerceAction, data: EcommerceActionData): void; |
| 155 | + addPromo(product: EcommercePromo): void; |
| 156 | + send(): void; |
| 157 | + } |
| 158 | + |
| 159 | + interface screenviewFn { |
| 160 | + (screen: string) :void; |
| 161 | + (option: { |
| 162 | + screenName: string; |
| 163 | + [otherProperties: string]: any; |
104 | 164 | }): void; |
105 | | - analyticsMiddleware: any; |
106 | | - onAnalyticsReady: () => Promise<void>; |
| 165 | + } |
| 166 | + |
| 167 | + interface requireFn { |
| 168 | + (pluginName: string, options?: any): void |
| 169 | + } |
| 170 | + |
| 171 | + interface exceptionFn { |
| 172 | + (exception: Error | string): void; |
| 173 | + } |
| 174 | + |
| 175 | + interface queryFn { |
| 176 | + (...args: any[]): any; |
| 177 | + } |
| 178 | + |
| 179 | + interface analyticsMiddlewareFn { |
| 180 | + <T>(store: Store<T>): void; |
| 181 | + } |
| 182 | + |
| 183 | + interface onAnalyticsReadyFn { |
| 184 | + (): Promise<void>; |
| 185 | + } |
| 186 | + |
| 187 | + export interface InstallOptions { |
| 188 | + id: string | string[] | (() => string) | (() => Promise<string>) | Promise<string>, |
| 189 | + router?: VueRouter, |
| 190 | + ignoreRoutes?: string[], |
| 191 | + debug?: { |
| 192 | + enabled?: boolean, |
| 193 | + trace?: boolean, |
| 194 | + sendHitTask?: boolean |
| 195 | + }, |
| 196 | + batch?: { |
| 197 | + enabled?: boolean, |
| 198 | + amount?: number, |
| 199 | + delay?: number |
| 200 | + }, |
| 201 | + linkers?: string[], |
| 202 | + customResourceURL?: string, |
| 203 | + ecommerce?: { |
| 204 | + enabled?: boolean, |
| 205 | + enhanced?: boolean, |
| 206 | + options?: any |
| 207 | + }, |
| 208 | + autoTracking?: { |
| 209 | + exception?: boolean, |
| 210 | + exceptionLogs?: boolean, |
| 211 | + screenview?: boolean, |
| 212 | + pageviewOnLoad?: boolean, |
| 213 | + page?: boolean, |
| 214 | + pageviewTemplate?: (route: Route) => pageDetails, |
| 215 | + transformQueryString?: boolean, |
| 216 | + prependBase?: boolean, |
| 217 | + skipSamePath: boolean, |
| 218 | + shouldRouterUpdate: (to: Route, from: Route) => string, |
| 219 | + untracked?: boolean |
| 220 | + }, |
| 221 | + fields?: { |
| 222 | + [field: string]: any |
| 223 | + }, |
| 224 | + customIdFields?: { |
| 225 | + [id: string]: { |
| 226 | + [field: string]: any |
| 227 | + } |
| 228 | + }, |
| 229 | + disabled?: boolean | (() => boolean) | (() => Promise<boolean>) | Promise<boolean>, |
| 230 | + checkDuplicatedScript?: boolean, |
| 231 | + disableScriptLoader?: boolean |
| 232 | + set?: { field: string, value: string }[], |
| 233 | + commands?: any, |
| 234 | + beforeFirstHit?: () => void, |
| 235 | + ready?: () => void |
| 236 | + } |
| 237 | + |
| 238 | + export default class VueAnalytics { |
| 239 | + static install(Vue: typeof _Vue, options: InstallOptions): void; |
| 240 | + analyticsMiddleware<T>(store: Store<T>): void; |
| 241 | + onAnalyticsReady: onAnalyticsReadyFn; |
107 | 242 | event: eventFn; |
108 | | - ecommerce: any; |
| 243 | + ecommerce: Ecommerce; |
109 | 244 | set: setFn; |
110 | 245 | page: pageFn; |
111 | | - query: any; |
112 | | - screenview: ((screen: string) => void) | ((option: { screenName: string, [otherProperties: string]: any }) => void); |
| 246 | + query: queryFn; |
| 247 | + screenview: screenviewFn; |
113 | 248 | time: timeFn; |
114 | | - require: (pluginName: string, options?: any) => void; |
115 | | - exception: (exception: Error | string) => void; |
| 249 | + require: requireFn; |
| 250 | + exception: exceptionFn; |
116 | 251 | social: socialFn; |
117 | 252 | disable: () => void; |
118 | 253 | enable: () => void; |
119 | 254 | } |
120 | 255 |
|
| 256 | + export const analyticsMiddleware: analyticsMiddlewareFn; |
| 257 | + export const onAnalyticsReady: onAnalyticsReadyFn; |
| 258 | + export const event: eventFn; |
| 259 | + export const ecommerce: Ecommerce; |
| 260 | + export const set: setFn; |
| 261 | + export const page: pageFn; |
| 262 | + export const query: queryFn; |
| 263 | + export const screenview: screenviewFn; |
| 264 | + export const time: timeFn; |
| 265 | + export const require: requireFn; |
| 266 | + export const exception: exceptionFn; |
| 267 | + export const social: socialFn; |
| 268 | + |
121 | 269 | module 'vue/types/options' { |
122 | 270 | interface ComponentOptions<V extends _Vue> { |
123 | 271 | ga?: VueAnalytics; |
|
0 commit comments