Skip to content

Commit

Permalink
feat: add posthog submission tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
arian81 committed Oct 24, 2024
1 parent 4199229 commit c0e1c68
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"papaparse": "^5.3.2",
"planby": "^1.1.2",
"posthog-js": "^1.150.0",
"posthog-node": "^4.2.1",
"prisma-generate": "^0.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
89 changes: 89 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/server/router/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ export const applicationRouter = router({
description: `${user.name} has submitted their RSVP.`,
icon: "🎉",
});
// await ctx.posthog.capture("RSVP Submitted", {
// user_id: `${user.name} - ${user.email}`,
// description: `${user.name} has submitted their RSVP.`,
// $set: {
// "RSVP Submitted": true,
// },
// });
}),
submit: protectedProcedure
.input(z.object({ id: z.string() }))
Expand Down Expand Up @@ -445,6 +452,17 @@ export const applicationRouter = router({
User: { connect: { id: ctx.session.user.id } },
},
});

const user = await ctx.prisma.user.update({
where: { id: ctx.session.user.id },
data: { status: Status.IN_REVIEW },
});

await ctx.posthog.capture({
distinctId: user.id,
event: "Application Submitted",
properties: { "Application Submitted": true },
});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
if (e.code === "P2002")
Expand Down Expand Up @@ -485,6 +503,13 @@ export const applicationRouter = router({
description: "A user has deleted their application.",
icon: "🗑️",
});
// await ctx.posthog.capture("Application Deleted", {
// user_id: `${user.name} - ${user.email}`,
// description: "A user has deleted their application.",
// $set: {
// "Application Deleted": true,
// },
// });
} catch (error) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
Expand Down
6 changes: 6 additions & 0 deletions src/server/router/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { getServerAuthSession } from "../../server/common/get-server-auth-sessio
import { prisma } from "../db/client";
import { LogSnag } from "@logsnag/node";
import { env } from "../../env/server.mjs";
import { PostHog } from "posthog-node";

const logsnag = new LogSnag({
token: env.LOGSNAG_TOKEN,
project: "deltahacks-11",
});

const posthog = new PostHog(env.NEXT_PUBLIC_POSTHOG_KEY, {
host: "https://ui.i.posthog.com",
});

type CreateContextOptions = {
session: Session | null;
};
Expand All @@ -24,6 +29,7 @@ export const createContextInner = async (opts: CreateContextOptions) => {
session: opts.session,
prisma,
logsnag,
posthog,
};
};

Expand Down

0 comments on commit c0e1c68

Please sign in to comment.