📈 Include pollId when capturing events (#555)

This commit is contained in:
Luke Vella 2023-03-13 17:41:49 +00:00 committed by GitHub
parent e77ed269f5
commit d14a88e9eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 63 deletions

View file

@ -93,6 +93,7 @@ const Page: React.FunctionComponent<CreatePollPageProps> = ({
onSuccess: (res) => { onSuccess: (res) => {
setIsRedirecting(true); setIsRedirecting(true);
posthog.capture("created poll", { posthog.capture("created poll", {
pollId: res.id,
numberOfOptions: formData.options?.options?.length, numberOfOptions: formData.options?.options?.length,
optionsView: formData?.options?.view, optionsView: formData?.options?.view,
}); });

View file

@ -15,8 +15,9 @@ export const normalizeVotes = (
export const useAddParticipantMutation = () => { export const useAddParticipantMutation = () => {
return trpc.polls.participants.add.useMutation({ return trpc.polls.participants.add.useMutation({
onSuccess: (_, { name }) => { onSuccess: (_, { pollId, name }) => {
posthog.capture("add participant", { posthog.capture("add participant", {
pollId,
name, name,
}); });
}, },
@ -61,8 +62,9 @@ export const useDeleteParticipantMutation = () => {
}, },
); );
}, },
onSuccess: (_, { participantId }) => { onSuccess: (_, { pollId, participantId }) => {
posthog.capture("remove participant", { posthog.capture("remove participant", {
pollId,
participantId, participantId,
}); });
}, },

View file

@ -94,73 +94,80 @@ export const polls = router({
demo: z.boolean().optional(), demo: z.boolean().optional(),
}), }),
) )
.mutation(async ({ ctx, input }): Promise<{ urlId: string }> => { .mutation(
const adminUrlId = await nanoid(); async ({ ctx, input }): Promise<{ id: string; urlId: string }> => {
const participantUrlId = await nanoid(); const adminUrlId = await nanoid();
let verified = false; const participantUrlId = await nanoid();
let verified = false;
if (ctx.session.user.isGuest === false) { if (ctx.session.user.isGuest === false) {
const user = await prisma.user.findUnique({ const user = await prisma.user.findUnique({
where: { id: ctx.session.user.id }, where: { id: ctx.session.user.id },
});
// If user is logged in with the same email address
if (user?.email === input.user.email) {
verified = true;
}
}
const poll = await prisma.poll.create({
select: {
adminUrlId: true,
id: true,
title: true,
},
data: {
id: await nanoid(),
title: input.title,
type: input.type,
timeZone: input.timeZone,
location: input.location,
description: input.description,
authorName: input.user.name,
demo: input.demo,
verified: verified,
notifications: verified,
adminUrlId,
participantUrlId,
user: {
connectOrCreate: {
where: {
email: input.user.email,
},
create: {
id: await nanoid(),
...input.user,
},
},
},
options: {
createMany: {
data: input.options.map((value) => ({
value,
})),
},
},
},
}); });
// If user is logged in with the same email address const adminLink = absoluteUrl(`/admin/${adminUrlId}`);
if (user?.email === input.user.email) { const participantLink = absoluteUrl(`/p/${participantUrlId}`);
verified = true;
}
}
const poll = await prisma.poll.create({ await sendEmail("NewPollEmail", {
data: { to: input.user.email,
id: await nanoid(), subject: `Let's find a date for ${poll.title}`,
title: input.title, props: {
type: input.type, title: poll.title,
timeZone: input.timeZone, name: input.user.name,
location: input.location, adminLink,
description: input.description, participantLink,
authorName: input.user.name,
demo: input.demo,
verified: verified,
notifications: verified,
adminUrlId,
participantUrlId,
user: {
connectOrCreate: {
where: {
email: input.user.email,
},
create: {
id: await nanoid(),
...input.user,
},
},
}, },
options: { });
createMany: {
data: input.options.map((value) => ({
value,
})),
},
},
},
});
const adminLink = absoluteUrl(`/admin/${adminUrlId}`); return { id: poll.id, urlId: adminUrlId };
const participantLink = absoluteUrl(`/p/${participantUrlId}`); },
),
await sendEmail("NewPollEmail", {
to: input.user.email,
subject: `Let's find a date for ${poll.title}`,
props: {
title: poll.title,
name: input.user.name,
adminLink,
participantLink,
},
});
return { urlId: adminUrlId };
}),
update: publicProcedure update: publicProcedure
.input( .input(
z.object({ z.object({