Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

📈 Track participant form opens and require email setting changes (#3616)

Luke Vella7d71b75a5ad9
diff --git a/apps/web/src/features/poll/components/voting-form.tsx b/apps/web/src/features/poll/components/voting-form.tsx
index 198d024e9..8eaa53696 100644
--- a/apps/web/src/features/poll/components/voting-form.tsx
+++ b/apps/web/src/features/poll/components/voting-form.tsx
@@ -1,4 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod";
+import { posthog } from "@rallly/posthog/client";
import { Dialog, DialogContent } from "@rallly/ui/dialog";
import { toast } from "@rallly/ui/sonner";
import React from "react";
@@ -77,7 +78,8 @@ export const useVotingForm = () => {
};
export const VotingForm = ({ children }: React.PropsWithChildren) => {
- const { options } = usePoll();
+ const poll = usePoll();
+ const { options } = poll;
const { t } = useTranslation();
const updateParticipantVotes = useUpdateParticipantVotes();
const token = useEditToken();
@@ -146,6 +148,13 @@ export const VotingForm = ({ children }: React.PropsWithChildren) => {
});
} else {
// new participant
+ // Plain properties, not groups, to match poll_response_submit:
+ // guest events are personless and PostHog drops their groups.
+ posthog?.capture("poll_response:form_open", {
+ poll_id: poll.id,
+ require_email: poll.requireParticipantEmail,
+ tier: poll.space?.tier,
+ });
setIsNewParticipantModalOpen(true);
}
})}
diff --git a/apps/web/src/features/poll/vote/components/vote-form.tsx b/apps/web/src/features/poll/vote/components/vote-form.tsx
index ccd35826c..6890423a0 100644
--- a/apps/web/src/features/poll/vote/components/vote-form.tsx
+++ b/apps/web/src/features/poll/vote/components/vote-form.tsx
@@ -1,5 +1,6 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
+import { posthog } from "@rallly/posthog/client";
import { Dialog, DialogContent } from "@rallly/ui/dialog";
import { toast } from "@rallly/ui/sonner";
import * as React from "react";
@@ -14,6 +15,7 @@ import { NewParticipantForm } from "@/features/poll/components/new-participant-m
import type { VoteType } from "@/features/poll/constants";
import { getVoteTypes } from "@/features/poll/constants";
import type { VotePageView, VoteResult } from "@/features/poll/vote/types";
+import type { SpaceTier } from "@/features/space/schema";
import { useTranslation } from "@/i18n/client";
const schema = z.object({
@@ -201,6 +203,7 @@ const emptyVotes = (results: VotePageView["results"]) =>
*/
export function VoteForm({
pollId,
+ tier,
requireParticipantEmail,
results,
response,
@@ -208,6 +211,7 @@ export function VoteForm({
children,
}: {
pollId: string;
+ tier: SpaceTier | undefined;
requireParticipantEmail: boolean;
results: VotePageView["results"];
response: VotePageView["response"];
@@ -255,6 +259,13 @@ export function VoteForm({
id="vote-form"
onSubmit={form.handleSubmit(async (data) => {
if (!response) {
+ // Plain properties, not groups, to match poll_response_submit:
+ // guest events are personless and PostHog drops their groups.
+ posthog?.capture("poll_response:form_open", {
+ poll_id: pollId,
+ require_email: requireParticipantEmail,
+ tier,
+ });
setIsNewParticipantOpen(true);
return;
}
diff --git a/apps/web/src/features/poll/vote/components/vote-panel.tsx b/apps/web/src/features/poll/vote/components/vote-panel.tsx
index 1605d7ef3..ec47380b7 100644
--- a/apps/web/src/features/poll/vote/components/vote-panel.tsx
+++ b/apps/web/src/features/poll/vote/components/vote-panel.tsx
@@ -97,6 +97,7 @@ export function VotePanel({
<UserProvider user={user}>
<VoteForm
pollId={poll.id}
+ tier={poll.space?.tier}
requireParticipantEmail={requireParticipantEmail}
results={results}
response={response}
diff --git a/apps/web/src/features/poll/vote/loaders.ts b/apps/web/src/features/poll/vote/loaders.ts
index 37be38ee1..bdf4b3af6 100644
--- a/apps/web/src/features/poll/vote/loaders.ts
+++ b/apps/web/src/features/poll/vote/loaders.ts
@@ -81,6 +81,7 @@ export const loadVotePage = cache(
? {
name: poll.space.name,
image: poll.space.image,
+ tier: poll.space.tier,
showBranding: poll.space.showBranding,
hideAttribution: poll.space.hideAttribution,
primaryColor: poll.space.primaryColor,
diff --git a/apps/web/src/features/poll/vote/types.ts b/apps/web/src/features/poll/vote/types.ts
index 2f4565f0f..5cdd60d18 100644
--- a/apps/web/src/features/poll/vote/types.ts
+++ b/apps/web/src/features/poll/vote/types.ts
@@ -1,6 +1,7 @@
import type { PollConferencing } from "@/features/conferencing/schema";
import type { VoteType } from "@/features/poll/constants";
import type { PollClosedReason, PollStatus } from "@/features/poll/schema";
+import type { SpaceTier } from "@/features/space/schema";
/** One option with its tally. `score` is null when the poll hides scores. */
export type VoteResult = {
@@ -41,6 +42,7 @@ export type VotePageView = {
space: {
name: string;
image: string | null;
+ tier: SpaceTier;
showBranding: boolean;
hideAttribution: boolean;
primaryColor: string | null;
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index 97aa3d974..aa3f16669 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -418,6 +418,9 @@ export const polls = router({
title: poll.title,
kind,
source: "web",
+ // A property as well as the group: guest events are personless and
+ // PostHog drops their group associations.
+ pollId: poll.id,
optionCount: poll.options.length,
hasLocation: !!location,
hasConferencing: !!conferencing,
@@ -548,6 +551,10 @@ export const polls = router({
};
}
+ // Set inside the transaction: once it commits, a concurrent edit can
+ // change the setting before any later read.
+ let savedRequireEmail: boolean | undefined;
+
await prisma.$transaction(async (tx) => {
const newOptions =
input.optionsToAdd?.map((optionValue) => {
@@ -766,6 +773,12 @@ export const polls = router({
},
});
+ savedRequireEmail = changes.some(
+ (change) => change.field === "requireParticipantEmail",
+ )
+ ? input.requireParticipantEmail
+ : undefined;
+
await recordPollActivities(tx, [
...(deletedOptions.length > 0
? [
@@ -834,6 +847,7 @@ export const polls = router({
hideScores: true,
timeZone: true,
muted: true,
+ space: { select: { tier: true } },
_count: {
select: {
participants: true,
@@ -926,6 +940,20 @@ export const polls = router({
});
}
+ if (savedRequireEmail !== undefined) {
+ track(ctx.user, {
+ event: "poll_settings:require_email_change",
+ properties: {
+ poll_id: pollId,
+ value: savedRequireEmail,
+ tier: updatedPoll.space?.tier,
+ },
+ groups: {
+ poll: pollId,
+ },
+ });
+ }
+
return { ok: true as const };
}),
markAsDeleted: possiblyPublicProcedure