From 755ba17dab1ef8fb8422887999fa56b5ebdceda0 Mon Sep 17 00:00:00 2001 From: Kieran Date: Sun, 10 Dec 2023 18:40:01 +0000 Subject: [PATCH] chore: track events with props --- .../src/Element/Event/Create/NoteCreator.tsx | 41 +++++++++++-------- packages/app/src/Pages/ZapPool.tsx | 2 +- packages/app/src/Pages/onboarding/profile.tsx | 2 +- packages/app/src/Pages/onboarding/start.tsx | 5 +-- packages/app/src/SnortUtils/index.ts | 4 +- packages/app/src/ZapPoolController.ts | 2 +- packages/app/src/index.tsx | 2 +- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/packages/app/src/Element/Event/Create/NoteCreator.tsx b/packages/app/src/Element/Event/Create/NoteCreator.tsx index 4fb291a12..cdb47e745 100644 --- a/packages/app/src/Element/Event/Create/NoteCreator.tsx +++ b/packages/app/src/Element/Event/Create/NoteCreator.tsx @@ -158,16 +158,21 @@ export function NoteCreator() { async function sendNote() { const ev = await buildNote(); if (ev) { - trackEvent("PostNote"); + let props: Record | undefined = undefined; if (ev.tags.find(a => a[0] === "content-warning")) { - trackEvent("PostNote:WithContentWarning"); + props ??= {}; + props["content-warning"] = true; } if (ev.tags.find(a => a[0] === "poll_option")) { - trackEvent("PostNote:WithPoll"); + props ??= {}; + props["poll"] = true; } if (ev.tags.find(a => a[0] === "zap")) { - trackEvent("PostNote:WithZapSplit"); + props ??= {}; + props["zap-split"] = true; } + trackEvent("PostNote", props); + const events = (note.otherEvents ?? []).concat(ev); events.map(a => sendEventToRelays(system, a, note.selectedCustomRelays, r => { @@ -269,7 +274,7 @@ export function NoteCreator() { note.update(v => (v.preview = undefined)); } else if (publisher) { const tmpNote = await buildNote(); - trackEvent("PostNote:Preview"); + trackEvent("PostNotePreview"); note.update(v => (v.preview = tmpNote)); } } @@ -352,18 +357,18 @@ export function NoteCreator() { onChange={e => { note.update( v => - (v.selectedCustomRelays = - // set false if all relays selected - e.target.checked && + (v.selectedCustomRelays = + // set false if all relays selected + e.target.checked && note.selectedCustomRelays && note.selectedCustomRelays.length == a.length - 1 - ? undefined - : // otherwise return selectedCustomRelays with target relay added / removed - a.filter(el => - el === r - ? e.target.checked - : !note.selectedCustomRelays || note.selectedCustomRelays.includes(el), - )), + ? undefined + : // otherwise return selectedCustomRelays with target relay added / removed + a.filter(el => + el === r + ? e.target.checked + : !note.selectedCustomRelays || note.selectedCustomRelays.includes(el), + )), ); }} /> @@ -432,9 +437,9 @@ export function NoteCreator() { onChange={e => note.update( v => - (v.zapSplits = arr.map((vv, ii) => - ii === i ? { ...vv, weight: Number(e.target.value) } : vv, - )), + (v.zapSplits = arr.map((vv, ii) => + ii === i ? { ...vv, weight: Number(e.target.value) } : vv, + )), ) } /> diff --git a/packages/app/src/Pages/ZapPool.tsx b/packages/app/src/Pages/ZapPool.tsx index b4242dc80..f448e855f 100644 --- a/packages/app/src/Pages/ZapPool.tsx +++ b/packages/app/src/Pages/ZapPool.tsx @@ -150,7 +150,7 @@ export default function ZapPoolPage() { {wallet && ( { - trackEvent("ZapPool:Manual"); + trackEvent("ZapPool", { manual: true }); await ZapPoolController?.payout(wallet); }}> diff --git a/packages/app/src/Pages/onboarding/profile.tsx b/packages/app/src/Pages/onboarding/profile.tsx index 967f035c4..d6d1a6d36 100644 --- a/packages/app/src/Pages/onboarding/profile.tsx +++ b/packages/app/src/Pages/onboarding/profile.tsx @@ -24,7 +24,7 @@ export function Profile() { name: state.name, picture, }); - trackEvent("Login:NewAccount"); + trackEvent("Login", { newAccount: true }); navigate("/login/sign-up/topics"); } catch (e) { if (e instanceof Error) { diff --git a/packages/app/src/Pages/onboarding/start.tsx b/packages/app/src/Pages/onboarding/start.tsx index b721ba3d0..ba84cd860 100644 --- a/packages/app/src/Pages/onboarding/start.tsx +++ b/packages/app/src/Pages/onboarding/start.tsx @@ -28,7 +28,7 @@ export function SignIn() { "getRelays" in unwrap(window.nostr) ? await unwrap(window.nostr?.getRelays).call(window.nostr) : undefined;*/ const pubKey = await unwrap(window.nostr).getPublicKey(); LoginStore.loginWithPubkey(pubKey, LoginSessionType.Nip7); - trackEvent("Login:NIP7"); + trackEvent("Login", { type: "NIP7" }); navigate("/"); } @@ -41,8 +41,7 @@ export function SignIn() { setError(""); try { await loginHandler.doLogin(key, key => Promise.resolve(new NotEncrypted(key))); - - trackEvent("Login:Key"); + trackEvent("Login", { type: "Key" }); navigate("/"); } catch (e) { if (e instanceof Error) { diff --git a/packages/app/src/SnortUtils/index.ts b/packages/app/src/SnortUtils/index.ts index 3cf2ebb30..f43f5202b 100644 --- a/packages/app/src/SnortUtils/index.ts +++ b/packages/app/src/SnortUtils/index.ts @@ -533,8 +533,8 @@ export function getCountry() { }; } -export function trackEvent(event: string) { - window.plausible?.(event); +export function trackEvent(event: string, props?: Record) { + window.plausible?.(event, props ? { props } : undefined); } export function storeRefCode() { diff --git a/packages/app/src/ZapPoolController.ts b/packages/app/src/ZapPoolController.ts index ac4eb2f74..f10e9a33f 100644 --- a/packages/app/src/ZapPoolController.ts +++ b/packages/app/src/ZapPoolController.ts @@ -168,7 +168,7 @@ class ZapPool extends ExternalStore> { if (wallet.canAutoLogin()) { await wallet.login(); } - trackEvent("ZapPool:Automatic"); + trackEvent("ZapPool", { automatic: true }); await this.payout(wallet); } } diff --git a/packages/app/src/index.tsx b/packages/app/src/index.tsx index af485a0f1..37e80305b 100644 --- a/packages/app/src/index.tsx +++ b/packages/app/src/index.tsx @@ -60,7 +60,7 @@ import NetworkGraph from "@/Pages/NetworkGraph"; declare global { interface Window { - plausible?: (tag: string) => void; + plausible?: (tag: string, e?: object) => void; } }