-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track run/abort annotation event to Matomo
- Loading branch information
Showing
5 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
declare module "vue-matomo"; | ||
declare module "vue-matomo" { | ||
// See https://github.com/AmazingDreams/vue-matomo/blob/master/src/utils.js | ||
|
||
/** | ||
* The default export is the Vue plugin. | ||
* Usage: | ||
* import matomo from "vue-matomo"; | ||
* app.use(matomo, {...}) | ||
*/ | ||
export default import("vue").Plugin; | ||
|
||
/** | ||
* Inject `matomoKey` to use the Matomo object. | ||
* Usage: | ||
* const matomo = inject<Matomo>(matomoKey); | ||
* matomo?.trackEvent("Vote", "Up") | ||
*/ | ||
export const matomoKey: string; | ||
|
||
/** | ||
* This thing is returned when injecting `matomoKey`. | ||
* Extend as needed. | ||
* Fully described on https://developer.matomo.org/api-reference/tracking-javascript | ||
*/ | ||
export type Matomo = { | ||
trackEvent: ( | ||
category: string, | ||
action: string, | ||
name?: string, | ||
value?: number, | ||
) => void; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { inject } from "vue"; | ||
import { matomoKey, type Matomo } from "vue-matomo"; | ||
|
||
/** Use this to call Matomo methods in the context of a setup function. */ | ||
export function useMatomo(): Matomo | undefined { | ||
// Specifying the default value avoids console warnings, even if it's just `undefined`. | ||
return inject<Matomo | undefined>(matomoKey, undefined); | ||
} | ||
|
||
/** | ||
* Exposes supported Matomo commands as methods, which then use `window._paq`. | ||
* If the queue is not loaded, nothing happens. | ||
*/ | ||
export const MatomoProxy = new Proxy<Matomo>({} as Matomo, { | ||
get: | ||
<F extends keyof Matomo>(target: {}, prop: F) => | ||
(...args: Parameters<Matomo[F]>) => | ||
(window as any)._paq?.push([prop, ...args]), | ||
}); |