From 76338eff7199baff0e2f3698584dffa1fac57dd5 Mon Sep 17 00:00:00 2001 From: Marios Antonoudiou Date: Thu, 22 May 2025 16:01:34 +0300 Subject: [PATCH] Introduce analytics --- components/rewrite-card.vue | 5 +++++ nuxt.config.ts | 3 +++ pages/index.vue | 15 +++++++++++++-- plugins/aptabase.client.ts | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 plugins/aptabase.client.ts diff --git a/components/rewrite-card.vue b/components/rewrite-card.vue index e85de11..04a2a32 100644 --- a/components/rewrite-card.vue +++ b/components/rewrite-card.vue @@ -1,4 +1,5 @@ diff --git a/plugins/aptabase.client.ts b/plugins/aptabase.client.ts new file mode 100644 index 0000000..f4f9bf7 --- /dev/null +++ b/plugins/aptabase.client.ts @@ -0,0 +1,19 @@ +import { init, trackEvent } from "@aptabase/web"; + +export default defineNuxtPlugin((nuxtApp) => { + const config = useRuntimeConfig(); + + nuxtApp.hook("app:mounted", () => { + init(config.public.aptabaseAppKey, { isDebug: import.meta.dev }); + }); + + nuxtApp.hook("page:finish", (ctx) => { + const route = useRoute(); + + trackEvent("page_view", { + path: route.path, + name: String(route.name), + redirectedFrom: String(route.redirectedFrom), + }); + }); +});