refactor(analytics): add module context to all Umami events

Resolves event name collisions in the unified app (e.g. view_changed,
deck_created, search_performed) by adding a `module` property to every
tracked event via createModuleTracker. Also fixes duplicate tracking in
Planta routes (now only tracked in mutations.ts).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-02 16:35:27 +02:00
parent 779a8ba322
commit 5280cc6dc7
6 changed files with 260 additions and 224 deletions

View file

@ -6,7 +6,7 @@
import { db } from '$lib/data/database';
import { toPlant, toWateringSchedule } from './queries';
import { trackEvent } from '@manacore/shared-utils/analytics';
import { PlantaEvents } from '@manacore/shared-utils/analytics';
import type {
LocalPlant,
LocalWateringSchedule,
@ -39,7 +39,7 @@ export const plantMutations = {
updatedAt: now,
};
await db.table('plants').add(newLocal);
trackEvent('plant_created');
PlantaEvents.plantCreated();
return toPlant(newLocal);
} catch (e) {
console.error('Failed to create plant:', e);
@ -78,7 +78,7 @@ export const plantMutations = {
deletedAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
});
trackEvent('plant_deleted');
PlantaEvents.plantDeleted();
return true;
} catch (e) {
console.error('Failed to delete plant:', e);
@ -117,7 +117,7 @@ export const wateringMutations = {
});
}
trackEvent('plant_watered');
PlantaEvents.plantWatered();
return true;
} catch (e) {
console.error('Failed to log watering:', e);

View file

@ -1,7 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { getContext } from 'svelte';
import { trackEvent } from '@manacore/shared-utils/analytics';
import { wateringMutations } from '$lib/modules/planta/mutations';
import {
getActivePlants,
@ -49,10 +48,7 @@
async function handleWater(plantId: string, e: Event) {
e.stopPropagation();
const success = await wateringMutations.logWatering(plantId);
if (success) {
trackEvent('plant_watered');
}
await wateringMutations.logWatering(plantId);
}
</script>

View file

@ -2,7 +2,6 @@
import { page } from '$app/stores';
import { goto } from '$app/navigation';
import { getContext } from 'svelte';
import { trackEvent } from '@manacore/shared-utils/analytics';
import { plantMutations, wateringMutations } from '$lib/modules/planta/mutations';
import {
getPlantById,
@ -31,10 +30,7 @@
async function handleWater() {
if (!plant) return;
watering = true;
const success = await wateringMutations.logWatering(plant.id);
if (success) {
trackEvent('plant_watered');
}
await wateringMutations.logWatering(plant.id);
watering = false;
}
@ -43,10 +39,7 @@
if (!confirm(`Moechtest du "${plant.name}" wirklich loeschen?`)) return;
const success = await plantMutations.delete(plant.id);
if (success) {
trackEvent('plant_deleted');
goto('/planta');
}
if (success) goto('/planta');
}
function formatDate(date: Date | string | undefined | null): string {

View file

@ -1,7 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { plantMutations } from '$lib/modules/planta/mutations';
import { trackEvent } from '@manacore/shared-utils/analytics';
let plantName = $state('');
let scientificName = $state('');
@ -30,7 +29,6 @@
return;
}
trackEvent('plant_created');
goto(`/planta/${plant.id}`);
}
</script>