Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/app/api/volunteer/details/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
SHEET_COLUMNS,
SHEET_TAB,
} from "@/app/toronto/volunteer/build-the-vote";
import { identifyToCustomerio } from "@/lib/customerio";
import { upsertSheetRow } from "@/lib/google-sheet";

// Build the Vote step 2: optional details, added to the volunteer's row in the
// Sheet shared with CJPAC. The row is found by the email step 1's response put
// in an httpOnly cookie, so the email is never in a URL or the page. These
// answers (including a mayoral preference) go to the Sheet only, not to
// Customer.io.
// in an httpOnly cookie, so the email is never in a URL or the page. The
// answers also go to Customer.io, best-effort as in step 1.

export async function POST(req: NextRequest) {
try {
Expand Down Expand Up @@ -41,6 +41,16 @@ export async function POST(req: NextRequest) {
},
});

try {
await identifyToCustomerio(email, {
toronto_2026_build_the_vote_availability: availability.join(", "),
toronto_2026_build_the_vote_mayoral_candidate: mayoral,
toronto_2026_build_the_vote_issues: issues,
});
} catch (err) {
console.error(err);
}

return NextResponse.json({ success: true });
} catch (err) {
console.error(err);
Expand Down
8 changes: 6 additions & 2 deletions src/app/api/volunteer/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { sheetTimestamp, upsertSheetRow } from "@/lib/google-sheet";
// aren't newsletter subscribers created by our newsletter form.
//
// The Sheet write must succeed, or the volunteer is told to try again: a
// sign-up CJPAC never sees is lost. Customer.io is best-effort. The phone
// number goes to the Sheet only; CJPAC calls, we don't.
// sign-up CJPAC never sees is lost. Customer.io is best-effort.

const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

Expand Down Expand Up @@ -71,9 +70,14 @@ export async function POST(req: NextRequest) {
first_name: firstName,
last_name: lastName,
name: `${firstName} ${lastName}`,
phone,
city,
postal_code: postalCode,
toronto_2026_build_the_vote_volunteer: true,
toronto_2026_build_the_vote_consent_to_share_with_cjpac: true,
toronto_2026_build_the_vote_utm_source: str(body.utm_source, 100),
toronto_2026_build_the_vote_utm_medium: str(body.utm_medium, 100),
toronto_2026_build_the_vote_utm_campaign: str(body.utm_campaign, 100),
// A Unix timestamp, so date-based segments can use it.
toronto_2026_build_the_vote_signed_up_at: Math.floor(Date.now() / 1000),
});
Expand Down
Loading