diff --git a/dev/zimit_ui_dev/config.json b/dev/zimit_ui_dev/config.json index 28c13ea..f0b53da 100644 --- a/dev/zimit_ui_dev/config.json +++ b/dev/zimit_ui_dev/config.json @@ -47,5 +47,9 @@ ], "zimit_size_limit": 2147483648, "zimit_time_limit": 5400, - "zimit_refresh_after": 60 + "zimit_refresh_after": 60, + "matomo_enabled": false, + "matomo_host": "", + "matomo_site_id": 0, + "matomo_tracker_file_name": "matomo" } diff --git a/ui/package.json b/ui/package.json index 04ffcd4..271a9c9 100644 --- a/ui/package.json +++ b/ui/package.json @@ -17,6 +17,7 @@ "pinia": "^2.2.2", "vue": "^3.5.6", "vue-i18n": "10.0.1", + "vue-matomo": "^4.2.0", "vue-router": "^4.4.5", "vuetify": "^3.7.1" }, diff --git a/ui/public/config.json b/ui/public/config.json index d7a5d38..0651f52 100644 --- a/ui/public/config.json +++ b/ui/public/config.json @@ -47,5 +47,9 @@ ], "zimit_size_limit": 2147483648, "zimit_time_limit": 5400, - "zimit_refresh_after": 60 + "zimit_refresh_after": 60, + "matomo_enabled": false, + "matomo_host": "", + "matomo_site_id": 0, + "matomo_tracker_file_name": "matomo" } diff --git a/ui/src/config.ts b/ui/src/config.ts index 5802fce..3bbe904 100644 --- a/ui/src/config.ts +++ b/ui/src/config.ts @@ -18,6 +18,10 @@ export type Config = { zimit_size_limit: number zimit_time_limit: number zimit_refresh_after: number + matomo_enabled: boolean + matomo_host: string + matomo_site_id: number + matomo_tracker_file_name: string } async function loadConfig() { diff --git a/ui/src/main.ts b/ui/src/main.ts index f96a4ce..9cfb046 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -47,6 +47,9 @@ import loadI18n, { i18nPlugin } from './i18n' // config import loadConfig, { configPlugin } from './config' +// Matomo stats +import VueMatomo from 'vue-matomo' + // load translation asynchronously and only then mount the app Promise.all([loadI18n(), loadConfig()]).then(([i18n, config]) => { app.use(vuetify) @@ -54,6 +57,16 @@ Promise.all([loadI18n(), loadConfig()]).then(([i18n, config]) => { app.use(pinia) app.use(i18n) + // activate matomo stats + if (config.matomo_enabled) { + app.use(VueMatomo, { + host: config.matomo_host, + siteId: config.matomo_site_id, + trackerFileName: config.matomo_tracker_file_name, + router: router + }) + } + // provide config app-wide app.provide(constants.config, config) diff --git a/ui/src/types/vue-matomo.d.ts b/ui/src/types/vue-matomo.d.ts new file mode 100644 index 0000000..ee92d7b --- /dev/null +++ b/ui/src/types/vue-matomo.d.ts @@ -0,0 +1,18 @@ +/* Declare what we use in vue-matomo (this is far from complete but sufficient for our + usage, so that TypeScript compiler can check what needs to be) */ +declare module 'vue-matomo' { + import { PluginFunction } from 'vue' + + interface VueMatomoOptions { + host: string + siteId: number + trackerFileName?: string + router: Router + } + + const VueMatomo: { + install: PluginFunction + } + + export default VueMatomo +} diff --git a/ui/yarn.lock b/ui/yarn.lock index 29db3a4..e9080d3 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -2648,6 +2648,11 @@ vue-i18n@10.0.1: "@intlify/shared" "10.0.1" "@vue/devtools-api" "^6.5.0" +vue-matomo@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/vue-matomo/-/vue-matomo-4.2.0.tgz#d65e369e4ead1d95ef790bef3627512cac3d25e9" + integrity sha512-m5hCw7LH3wPDcERaF4sp/ojR9sEx7Rl8TpOyH/4jjQxMF2DuY/q5pO+i9o5Dx+BXLSa9+IQ0qhAbWYRyESQXmA== + vue-router@^4.4.5: version "4.4.5" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.4.5.tgz#bdf535e4cf32414ebdea6b4b403593efdb541388"