From 3175c8c42fd852433a2a73ff3a565f73ef387b5c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 15 Nov 2022 17:22:50 +0100 Subject: [PATCH 1/2] feat: send events to growth --- src/lib/actions/analytics.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index ca4f4667ea..0385ab986a 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -2,6 +2,7 @@ import Analytics from 'analytics'; import googleAnalytics from '@analytics/google-analytics'; import { get } from 'svelte/store'; import { page } from '$app/stores'; +import { user } from '$lib/stores/user'; const analytics = Analytics({ app: 'appwrite', @@ -16,8 +17,9 @@ export function trackEvent(name: string, data: object = null): void { if (!isTrackingAllowed()) { return; } - - analytics.track(name, { ...data, path: get(page).routeId }); + const path = get(page).routeId; + analytics.track(name, { ...data, path }); + sendEventToGrowth(name, path, data); } export function trackPageView(path: string) { @@ -30,6 +32,26 @@ export function trackPageView(path: string) { }); } +function sendEventToGrowth(event: string, path: string, data: object = null): void { + const { email, name } = get(user); + + fetch('https://growth.appwrite.io/v1/analytics', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + action: event, + url: window.location.origin + path, + data: { + email, + name, + ...data + } + }) + }); +} + function isTrackingAllowed() { if (window.navigator?.doNotTrack) { if (navigator.doNotTrack === '1' || navigator.doNotTrack === 'yes') { From c2135f022dd30ca318e7b3e8503c96b438688c10 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 15 Nov 2022 18:20:58 +0100 Subject: [PATCH 2/2] growth: add label --- src/lib/actions/analytics.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 0385ab986a..46a0b11dd7 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -42,6 +42,7 @@ function sendEventToGrowth(event: string, path: string, data: object = null): vo }, body: JSON.stringify({ action: event, + label: event, url: window.location.origin + path, data: { email,