mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-05 20:21:50 +02:00
♻️ Add abstractions for tracking server-side events (#1143)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
81d2f2c0bd
commit
d43bc631f1
9 changed files with 69 additions and 12 deletions
|
@ -12,7 +12,6 @@
|
|||
"@rallly/database": "*",
|
||||
"@rallly/emails": "*",
|
||||
"@rallly/utils": "*",
|
||||
"@vercel/functions": "^1.0.2",
|
||||
"@trpc/server": "^10.13.0",
|
||||
"iron-session": "^6.3.1",
|
||||
"spacetime": "^7.4.7",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { EmailClient } from "@rallly/emails";
|
||||
import { inferAsyncReturnType, TRPCError } from "@trpc/server";
|
||||
import { CreateNextContextOptions } from "@trpc/server/adapters/next";
|
||||
import type { PostHog } from "posthog-node";
|
||||
|
||||
export type GetUserFn = (opts: CreateNextContextOptions) => Promise<{
|
||||
id: string;
|
||||
|
@ -12,6 +13,7 @@ export interface TRPCContextParams {
|
|||
emailClient: EmailClient;
|
||||
isSelfHosted: boolean;
|
||||
isEmailBlocked?: (email: string) => boolean;
|
||||
posthogClient?: PostHog;
|
||||
/**
|
||||
* Takes a relative path and returns an absolute URL to the app
|
||||
* @param path
|
||||
|
|
|
@ -626,6 +626,7 @@ export const polls = router({
|
|||
},
|
||||
select: {
|
||||
id: true,
|
||||
createdAt: true,
|
||||
timeZone: true,
|
||||
title: true,
|
||||
location: true,
|
||||
|
@ -859,7 +860,23 @@ export const polls = router({
|
|||
});
|
||||
});
|
||||
|
||||
waitUntil(Promise.all([emailToHost, ...emailsToParticipants]));
|
||||
ctx.posthogClient?.capture({
|
||||
distinctId: ctx.user.id,
|
||||
event: "finalize poll",
|
||||
properties: {
|
||||
number_of_participants: poll.participants.length,
|
||||
number_of_attendees: attendees.length,
|
||||
dayjs_since_created: dayjs().diff(poll.createdAt, "day"),
|
||||
},
|
||||
});
|
||||
|
||||
waitUntil(
|
||||
Promise.all([
|
||||
emailToHost,
|
||||
...emailsToParticipants,
|
||||
ctx.posthogClient?.flushAsync(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}),
|
||||
reopen: possiblyPublicProcedure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue