From b976bba9916c9443d7c6246fe57f5f8edc215892 Mon Sep 17 00:00:00 2001 From: Arild Matsson Date: Tue, 19 Sep 2023 12:53:28 +0200 Subject: [PATCH] Basic Matomo logging --- .env | 2 ++ package.json | 1 + src/main.js | 17 ++++++++++++++--- yarn.lock | 5 +++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 82cde0e..5205b0d 100644 --- a/.env +++ b/.env @@ -3,3 +3,5 @@ VITE_BACKEND_URL=https://ws.spraakbanken.gu.se/ws/mink/ VITE_AUTH_URL=https://sp.spraakbanken.gu.se/auth/ VITE_KORP_URL=https://spraakbanken.gu.se/korp/ VITE_STRIX_URL=https://spraakbanken.gu.se/strix/ +VITE_MATOMO_URL=https://spraakbanken.gu.se/stats +# VITE_MATOMO_ID= # Do not report to the real backend when developing \ No newline at end of file diff --git a/package.json b/package.json index 23227f4..ed095e7 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "vite-plugin-rewrite-all": "^1.0.1", "vue": "^3.2.6", "vue-i18n": "9", + "vue-matomo": "^4.2.0", "vue-router": "4" }, "devDependencies": { diff --git a/src/main.js b/src/main.js index fd3e212..a315e13 100644 --- a/src/main.js +++ b/src/main.js @@ -5,14 +5,25 @@ import { createPinia } from "pinia"; import i18n from "./i18n/i18n"; import { formkit, formkitConfig } from "./formkit"; import { FontAwesomeIcon } from "./fontawesome"; +import matomo from "vue-matomo"; import "./index.css"; const pinia = createPinia(); -createApp(App) // +const app = createApp(App) // .use(router) .use(pinia) .use(i18n) .use(formkit, formkitConfig) - .component("icon", FontAwesomeIcon) - .mount("#app"); + .component("icon", FontAwesomeIcon); + +// Use the Matomo plugin only if configured in env. +if (import.meta.env.VITE_MATOMO_URL && import.meta.env.VITE_MATOMO_ID) { + app.use(matomo, { + host: import.meta.env.VITE_MATOMO_URL, + siteId: import.meta.env.VITE_MATOMO_ID, + router: router, + }); +} + +app.mount("#app"); diff --git a/yarn.lock b/yarn.lock index 51ae28f..9ab1835 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2302,6 +2302,11 @@ vue-i18n@9: "@intlify/vue-devtools" "9.2.2" "@vue/devtools-api" "^6.2.1" +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: version "4.1.6" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.1.6.tgz#b70303737e12b4814578d21d68d21618469375a1"