Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #258 from justindra/master
Browse files Browse the repository at this point in the history
feat: added typings for vue-analytics
  • Loading branch information
MatteoGabriele authored Dec 10, 2019
2 parents 10325c8 + 1f483f7 commit b05fb0d
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
"vue"
],
"main": "dist/vue-analytics.js",
"types": "vue-analytics.d.ts",
"files": [
"dist"
"dist",
"vue-analytics.d.ts"
],
"author": {
"name": "Matteo Gabriele",
Expand Down
132 changes: 132 additions & 0 deletions vue-analytics.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

declare module 'vue-analytics' {
import _Vue, { PluginFunction } from 'vue';
import VueRouter, { Route } from 'vue-router';

interface eventFn {
(category: string, action?: string, label?: string, value?: number): void;
(options: {
eventCategory: string,
eventAction: string,
eventLabel: string,
eventValue: number
}): void;
}

type pageDetails = {
page: string,
title: string,
location: string
};

interface pageFn {
(path: string): void;
(options: pageDetails): void;
(route: VueRouter): void;
}

interface setFn {
(fieldName: string, fieldValue: string): void;
(options: {
field: string, value: string
}): void;
}

interface socialFn {
(network: string, action: string, target: string): void;
(options: {
socialNetwork: string,
socialAction: string,
socialTarget: string
}): void;
}

interface timeFn {
(category: string, variable: string, value: number, label: string): void;
(options: {
timingCategory: string,
timingVar: string,
timingValue: number,
timingLabel: string
}): void;
}

export default class VueAnalytics {
static install(Vue: typeof _Vue, options: {
id: string | string[] | (() => string) | (() => Promise<string>) | Promise<string>,
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<boolean>) | Promise<boolean>,
checkDuplicatedScript?: boolean,
disableScriptLoader?: boolean
set?: { field: string, value: string }[],
commands?: any,
beforeFirstHit?: () => void,
ready?: () => void
}): void;
analyticsMiddleware: any;
onAnalyticsReady: () => Promise<void>;
event: eventFn;
ecommerce: any;
set: setFn;
page: pageFn;
query: any;
screenview: ((screen: string) => void) | ((option: { screenName: string, [otherProperties: string]: any }) => void);
time: timeFn;
require: (pluginName: string, options?: any) => void;
exception: (exception: Error | string) => void;
social: socialFn;
disable: () => void;
enable: () => void;
}

module 'vue/types/options' {
interface ComponentOptions<V extends _Vue> {
ga?: VueAnalytics;
}
}

module 'vue/types/vue' {
interface Vue {
$ga: VueAnalytics;
}
}
}

0 comments on commit b05fb0d

Please sign in to comment.