From d2a797c32b9acdb3666344157ad3c665ad4ca3e4 Mon Sep 17 00:00:00 2001 From: Roman Pavlov Date: Sat, 14 Dec 2019 22:24:01 -0800 Subject: [PATCH 1/3] feat(types): extract options for `install` method into separate interface for convenient usage --- vue-analytics.d.ts | 102 +++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/vue-analytics.d.ts b/vue-analytics.d.ts index eb5d199..e8c34f1 100644 --- a/vue-analytics.d.ts +++ b/vue-analytics.d.ts @@ -50,58 +50,60 @@ declare module 'vue-analytics' { timingLabel: string }): void; } + + export interface InstallOptions { + id: string | string[] | (() => string) | (() => Promise) | Promise, + router?: VueRouter, + ignoreRoutes?: string[], + debug?: { + enabled?: boolean, + trace?: boolean, + sendHitTask?: boolean + }, + batch?: { + enabled?: boolean, + amount?: number, + delay?: number + }, + linkers?: string[], + customResourceURL?: string, + ecommerce?: { + enabled?: boolean, + enhanced?: boolean, + options?: any + }, + autoTracking?: { + exception?: boolean, + exceptionLogs?: boolean, + screenview?: boolean, + pageviewOnLoad?: boolean, + page?: boolean, + pageviewTemplate?: (route: Route) => pageDetails, + transformQueryString?: boolean, + prependBase?: boolean, + skipSamePath: boolean, + shouldRouterUpdate: (to: Route, from: Route) => string, + untracked?: boolean + }, + fields?: { + [field: string]: any + }, + customIdFields?: { + [id: string]: { + [field: string]: any + } + }, + disabled?: boolean | (() => boolean) | (() => Promise) | Promise, + checkDuplicatedScript?: boolean, + disableScriptLoader?: boolean + set?: { field: string, value: string }[], + commands?: any, + beforeFirstHit?: () => void, + ready?: () => void + } export default class VueAnalytics { - static install(Vue: typeof _Vue, options: { - id: string | string[] | (() => string) | (() => Promise) | Promise, - router?: VueRouter, - ignoreRoutes?: string[], - debug?: { - enabled?: boolean, - trace?: boolean, - sendHitTask?: boolean - }, - batch?: { - enabled?: boolean, - amount?: number, - delay?: number - }, - linkers?: string[], - customResourceURL?: string, - ecommerce?: { - enabled?: boolean, - enhanced?: boolean, - options?: any - }, - autoTracking?: { - exception?: boolean, - exceptionLogs?: boolean, - screenview?: boolean, - pageviewOnLoad?: boolean, - page?: boolean, - pageviewTemplate?: (route: Route) => pageDetails, - transformQueryString?: boolean, - prependBase?: boolean, - skipSamePath: boolean, - shouldRouterUpdate: (to: Route, from: Route) => string, - untracked?: boolean - }, - fields?: { - [field: string]: any - }, - customIdFields?: { - [id: string]: { - [field: string]: any - } - }, - disabled?: boolean | (() => boolean) | (() => Promise) | Promise, - checkDuplicatedScript?: boolean, - disableScriptLoader?: boolean - set?: { field: string, value: string }[], - commands?: any, - beforeFirstHit?: () => void, - ready?: () => void - }): void; + static install(Vue: typeof _Vue, options: InstallOptions): void; analyticsMiddleware: any; onAnalyticsReady: () => Promise; event: eventFn; From 440d2e21bd5f87a226cefb5919d52b1fc2440745 Mon Sep 17 00:00:00 2001 From: Roman Pavlov Date: Sat, 14 Dec 2019 23:32:39 -0800 Subject: [PATCH 2/3] feat(types): add typings for ecommerce --- vue-analytics.d.ts | 134 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/vue-analytics.d.ts b/vue-analytics.d.ts index e8c34f1..9e8add6 100644 --- a/vue-analytics.d.ts +++ b/vue-analytics.d.ts @@ -51,6 +51,138 @@ declare module 'vue-analytics' { }): void; } + interface EcommerceItem { + id: string; + name: string; + sku?: string; + category?: string; + price?: string; + quantity?: number; + } + + interface EcommerceTransaction { + id: string; + affiliation?: string; + revenue?: string; + shipping?: string; + tax?: string; + } + + interface EcommerceImpressionBase { + list?: string; + brand?: string; + category?: string; + variant?: string; + position?: number; + price?: string; + } + + interface EcommerceImpressionWithId extends EcommerceImpressionBase { + id: string; + } + + interface EcommerceImpressionWithName extends EcommerceImpressionBase { + name: string; + } + + type EcommerceImpression = EcommerceImpressionWithId | EcommerceImpressionWithName; + + interface EcommerceProductBase { + brand?: string; + category?: string; + variant?: string; + price?: string; + quantity?: number; + coupon?: string; + position?: number; + } + + interface EcommerceProductWithId extends EcommerceProductBase { + id: string; + } + + interface EcommerceProductWithName extends EcommerceProductBase { + name: string; + } + + type EcommerceProduct = EcommerceImpressionWithId | EcommerceImpressionWithName; + + type EcommerceAction = + | 'click' + | 'detail' + | 'add' + | 'remove' + | 'checkout' + | 'checkout_option' + | 'purchase' + | 'refund' + | 'promo_click' + + interface EcommerceActionData { + id?: string; + affiliation?: string; + revenue?: number; + tax?: number; + shipping?: number; + coupon?: string; + list?: string; + step?: number; + option?: string; + } + + interface EcommercePromoBase { + creative?: string; + position?: string; + } + + interface EcommercePromoWithId extends EcommercePromoBase { + id: string; + } + + interface EcommercePromoWithName extends EcommercePromoBase { + name: string; + } + + type EcommercePromo = EcommercePromoWithId | EcommercePromoWithName; + + interface Ecommerce { + addItem(item: EcommerceItem): void; + addTransaction(transaction: EcommerceTransaction): void; + addProduct(product: EcommerceProduct): void; + addImpression(impression: EcommerceImpression): void; + setAction(action: EcommerceAction, data: EcommerceActionData): void; + addPromo(product: EcommercePromo): void; + send(): void; + } + + interface screenviewFn { + (screen: string) :void; + (option: { + screenName: string; + [otherProperties: string]: any; + }): void; + } + + interface requireFn { + (pluginName: string, options?: any): void + } + + interface exceptionFn { + (exception: Error | string): void; + } + + interface queryFn { + (...args: any[]): any; + } + + interface analyticsMiddlewareFn { + (store: Store): void; + } + + interface onAnalyticsReadyFn { + (): Promise; + } + export interface InstallOptions { id: string | string[] | (() => string) | (() => Promise) | Promise, router?: VueRouter, @@ -107,7 +239,7 @@ declare module 'vue-analytics' { analyticsMiddleware: any; onAnalyticsReady: () => Promise; event: eventFn; - ecommerce: any; + ecommerce: Ecommerce; set: setFn; page: pageFn; query: any; From fdb2dad261bd01d89b7e01ffbca80bc30c077c0f Mon Sep 17 00:00:00 2001 From: Roman Pavlov Date: Sat, 14 Dec 2019 23:34:42 -0800 Subject: [PATCH 3/3] feat(types): export events library functions --- package.json | 1 + vue-analytics.d.ts | 28 +++++++++++++++++++++------- yarn.lock | 5 +++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index b860370..6910632 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "terser-webpack-plugin": "^2.2.1", "vue": "^2.6.10", "vue-router": "^3.1.3", + "vuex": "^3.1.2", "webpack": "^4.41.2", "webpack-cli": "^3.3.10" } diff --git a/vue-analytics.d.ts b/vue-analytics.d.ts index 9e8add6..6f77b4b 100644 --- a/vue-analytics.d.ts +++ b/vue-analytics.d.ts @@ -2,6 +2,7 @@ declare module 'vue-analytics' { import _Vue, { PluginFunction } from 'vue'; import VueRouter, { Route } from 'vue-router'; + import { Store } from 'vuex'; interface eventFn { (category: string, action?: string, label?: string, value?: number): void; @@ -50,7 +51,7 @@ declare module 'vue-analytics' { timingLabel: string }): void; } - + interface EcommerceItem { id: string; name: string; @@ -236,22 +237,35 @@ declare module 'vue-analytics' { export default class VueAnalytics { static install(Vue: typeof _Vue, options: InstallOptions): void; - analyticsMiddleware: any; - onAnalyticsReady: () => Promise; + analyticsMiddleware(store: Store): void; + onAnalyticsReady: onAnalyticsReadyFn; event: eventFn; ecommerce: Ecommerce; set: setFn; page: pageFn; - query: any; - screenview: ((screen: string) => void) | ((option: { screenName: string, [otherProperties: string]: any }) => void); + query: queryFn; + screenview: screenviewFn; time: timeFn; - require: (pluginName: string, options?: any) => void; - exception: (exception: Error | string) => void; + require: requireFn; + exception: exceptionFn; social: socialFn; disable: () => void; enable: () => void; } + export const analyticsMiddleware: analyticsMiddlewareFn; + export const onAnalyticsReady: onAnalyticsReadyFn; + export const event: eventFn; + export const ecommerce: Ecommerce; + export const set: setFn; + export const page: pageFn; + export const query: queryFn; + export const screenview: screenviewFn; + export const time: timeFn; + export const require: requireFn; + export const exception: exceptionFn; + export const social: socialFn; + module 'vue/types/options' { interface ComponentOptions { ga?: VueAnalytics; diff --git a/yarn.lock b/yarn.lock index a474685..751186b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8542,6 +8542,11 @@ vue@^2.6.10: resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637" integrity sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ== +vuex@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.1.2.tgz#a2863f4005aa73f2587e55c3fadf3f01f69c7d4d" + integrity sha512-ha3jNLJqNhhrAemDXcmMJMKf1Zu4sybMPr9KxJIuOpVcsDQlTBYLLladav2U+g1AvdYDG5Gs0xBTb0M5pXXYFQ== + w3c-hr-time@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"