Skip to content

Commit

Permalink
chore: track events with props
Browse files Browse the repository at this point in the history
  • Loading branch information
v0l committed Dec 10, 2023
1 parent d00f8b0 commit 755ba17
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
41 changes: 23 additions & 18 deletions packages/app/src/Element/Event/Create/NoteCreator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,21 @@ export function NoteCreator() {
async function sendNote() {
const ev = await buildNote();
if (ev) {
trackEvent("PostNote");
let props: Record<string, boolean> | 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 => {
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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),
)),
);
}}
/>
Expand Down Expand Up @@ -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,
)),
)
}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Pages/ZapPool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default function ZapPoolPage() {
{wallet && (
<AsyncButton
onClick={async () => {
trackEvent("ZapPool:Manual");
trackEvent("ZapPool", { manual: true });
await ZapPoolController?.payout(wallet);
}}>
<FormattedMessage defaultMessage="Payout Now" id="+PzQ9Y" />
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Pages/onboarding/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions packages/app/src/Pages/onboarding/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
}

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/SnortUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ export function getCountry() {
};
}

export function trackEvent(event: string) {
window.plausible?.(event);
export function trackEvent(event: string, props?: Record<string, string | boolean>) {
window.plausible?.(event, props ? { props } : undefined);
}

export function storeRefCode() {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/ZapPoolController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ZapPool extends ExternalStore<Array<ZapPoolRecipient>> {
if (wallet.canAutoLogin()) {
await wallet.login();
}
trackEvent("ZapPool:Automatic");
trackEvent("ZapPool", { automatic: true });
await this.payout(wallet);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import NetworkGraph from "@/Pages/NetworkGraph";

declare global {
interface Window {
plausible?: (tag: string) => void;
plausible?: (tag: string, e?: object) => void;
}
}

Expand Down

0 comments on commit 755ba17

Please sign in to comment.