Repository navigation
feat(tracking): email each member once when a brand's first results are ready - #1810
Conversation
…first run finishes A new customer's first tracking run takes 30 to 65 minutes, and most leave the app meanwhile. Nothing told them when the results were in. - When a brand's first full run stamps (now, or once its late answers are in), the API e-mails the organization's members "Your first results are ready", with a link to Brand Visibility (server/src/lib/first-results-email.js, sent from job-runner.js's afterStamp). The tracking worker's result now says whether it was the brand's first run. - Once per person: profiles.first_results_emailed_at (00385). The members never sent it are claimed in one update before the send, so two first runs finishing at once can't both send it, and a later brand's first run doesn't send it again. A send Resend refused, or one skipped where e-mail isn't set up, gives the claim back. - Help: first-results-after-setup says the e-mail comes once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…irst results A workspace that had results before (from another brand) adding a brand was told its first results were ready. Send only when the brand's run is the earliest stamped run among the organization's real brands, and never for a demo brand.
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good with ab4fd83 (one commit on this branch). isFirstRun was per brand and the new column starts null for everyone, so a workspace that already had results told every member "Your first results are ready" again when it added a brand, and so did someone who joined later. The commit sends only when this brand's run is the earliest stamped run among the workspace's non-demo brands, and skips a demo brand in the sender before anything is read or claimed. Four new tests in first-results-email.test.js fail without it. No backfill is needed, and the migration and schema.sql are unchanged.
Checked, fine
- Sending once: the claim is a single
update … where first_results_emailed_at is null returning id. A refused or skipped send gives it back, and anunknownoutcome keeps it. - Only this workspace's profiles get it, so removed members are left out. Demo brands and workspaces without an active plan never start a job.
- 00385 adds a nullable column with no rewrite and is idempotent. The existing
profilespolicies and guard cover it. 00385 is unique among main and the open PRs, andbuild-schema.shleavesschema.sqlunchanged. - No embeds.
first-results-email,job-runnerandtracking-worker.first-runpass 36/36, the full server suite passes (the known timing tests pass alone), and eslint, prettier andplan-row.test.tspass.
For later: all members go in one to, so they see each other's addresses, and Resend refuses more than 50 recipients. One email per person would fix both. If getUserById fails, that person is claimed without an email.
Deploy: apply 00385, then merge.
gkhngyk
left a comment
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main and keeps #1803's first-run text in the Getting started article, with this PR's e-mail sentence. Migration 00385 is applied on production just before the merge.
Summary
From onboarding testing: the first tracking run takes a while, so people should hear when it's done, without having to wait on the page. Nothing sent an email for this until now.
When a brand's first tracking run completes, the organization's members get Your first results are ready, with a link to Brand Visibility.
profiles.first_results_emailed_at(migration 00385) stops a repeat, so a second brand's first run doesn't send it again. A failed send clears the mark, and the next first run tries again.help/visibility/first-results-after-setup.mdmentions the email.Related issue
None. Product owner's onboarding feedback.
Type of change
feat— New featureHow to test
cd server && npx vitest runon the changed tests (32/32). They cover: sent once per person, not on a later brand, the mark cleared on a failed send, and no email without Resend.Deploy: apply 00385 before the server.
Checklist
bash supabase/build-schema.sh:schema.sqlis current (00385)🤖 Generated with Claude Code