Introduce analytics

This commit is contained in:
2025-05-22 16:01:34 +03:00
parent e080f3978c
commit 76338eff71
4 changed files with 40 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { trackEvent } from "@aptabase/web";
import type { FormSubmitEvent } from "@nuxt/ui"; import type { FormSubmitEvent } from "@nuxt/ui";
const { user } = useUserSession(); const { user } = useUserSession();
@@ -34,6 +35,10 @@ const validate = ({
}; };
const submit = async (event: FormSubmitEvent<typeof formData>) => { const submit = async (event: FormSubmitEvent<typeof formData>) => {
trackEvent("rewrite_activity", {
activityUrl: event.data.activityUrl,
});
await $fetch("/api/rewrite", { await $fetch("/api/rewrite", {
method: "POST", method: "POST",
query: { query: {

View File

@@ -13,6 +13,9 @@ export default defineNuxtConfig({
stravaVerifyToken: "", stravaVerifyToken: "",
openaiApiKey: "", openaiApiKey: "",
databaseUrl: "", databaseUrl: "",
public: {
aptabaseAppKey: "",
},
}, },
future: { compatibilityVersion: 4 }, future: { compatibilityVersion: 4 },
compatibilityDate: "2025-03-01", compatibilityDate: "2025-03-01",

View File

@@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { omit } from "radash"; import { diff, omit } from "radash";
import { trackEvent } from "@aptabase/web";
useHead({ title: "Ghostwriter" }); useHead({ title: "Ghostwriter" });
@@ -43,7 +44,17 @@ const saveOp = watchPausable(
body: toValue(preferences), body: toValue(preferences),
}); });
}, },
{ initialState: "paused", deep: true }, {
initialState: "paused",
deep: true,
onTrigger: (event) => {
trackEvent("update_preferences", {
key: event.key,
value: event.newValue,
oldValue: event.oldValue,
});
},
},
); );
</script> </script>

View File

@@ -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),
});
});
});