Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 7986a44

Browse files
Merge pull request #263 from romansp/improve-typescript-declarations
Improve typescript declarations
2 parents 8d13398 + a55cb6c commit 7986a44

File tree

3 files changed

+211
-57
lines changed

3 files changed

+211
-57
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"terser-webpack-plugin": "^2.2.1",
5757
"vue": "^2.6.10",
5858
"vue-router": "^3.1.3",
59+
"vuex": "^3.1.2",
5960
"webpack": "^4.41.2",
6061
"webpack-cli": "^3.3.10"
6162
}

vue-analytics.d.ts

Lines changed: 205 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
declare module 'vue-analytics' {
33
import _Vue, { PluginFunction } from 'vue';
44
import VueRouter, { Route } from 'vue-router';
5+
import { Store } from 'vuex';
56

67
interface eventFn {
78
(category: string, action?: string, label?: string, value?: number): void;
@@ -51,73 +52,220 @@ declare module 'vue-analytics' {
5152
}): void;
5253
}
5354

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;
104164
}): 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;
107242
event: eventFn;
108-
ecommerce: any;
243+
ecommerce: Ecommerce;
109244
set: setFn;
110245
page: pageFn;
111-
query: any;
112-
screenview: ((screen: string) => void) | ((option: { screenName: string, [otherProperties: string]: any }) => void);
246+
query: queryFn;
247+
screenview: screenviewFn;
113248
time: timeFn;
114-
require: (pluginName: string, options?: any) => void;
115-
exception: (exception: Error | string) => void;
249+
require: requireFn;
250+
exception: exceptionFn;
116251
social: socialFn;
117252
disable: () => void;
118253
enable: () => void;
119254
}
120255

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+
121269
module 'vue/types/options' {
122270
interface ComponentOptions<V extends _Vue> {
123271
ga?: VueAnalytics;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8600,6 +8600,11 @@ vue@^2.6.10:
86008600
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637"
86018601
integrity sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ==
86028602

8603+
vuex@^3.1.2:
8604+
version "3.1.2"
8605+
resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.1.2.tgz#a2863f4005aa73f2587e55c3fadf3f01f69c7d4d"
8606+
integrity sha512-ha3jNLJqNhhrAemDXcmMJMKf1Zu4sybMPr9KxJIuOpVcsDQlTBYLLladav2U+g1AvdYDG5Gs0xBTb0M5pXXYFQ==
8607+
86038608
w3c-hr-time@^1.0.1:
86048609
version "1.0.1"
86058610
resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"

0 commit comments

Comments
 (0)