Skip to content

feat(tracking): email each member once when a brand's first results are ready - #1810

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/first-run-ready-email
Oct 30, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/first-run-ready-email

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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.

  • Once per person: 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.
  • Existing email path: it goes through the existing Resend pattern.
  • Server only: the in-app toast and the Action Center refresh come in a separate web PR.
  • Help: help/visibility/first-results-after-setup.md mentions the email.

Related issue

None. Product owner's onboarding feedback.

Type of change

  • feat — New feature

How to test

  1. cd server && npx vitest run on 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.
  2. On staging with Resend and 00385 applied, finish a new brand's setup. When the first run completes, each member gets the email once, and a second brand's first run doesn't send it again.

Deploy: apply 00385 before the server.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • bash supabase/build-schema.sh: schema.sql is current (00385)
  • Server: format, lint and the related tests pass (full suite left to CI)
  • Tests added
  • Help article updated

🤖 Generated with Claude Code

…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]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
…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
gkhngyk previously approved these changes Oct 30, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 an unknown outcome 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 profiles policies and guard cover it. 00385 is unique among main and the open PRs, and build-schema.sh leaves schema.sql unchanged.
  • No embeds. first-results-email, job-runner and tracking-worker.first-run pass 36/36, the full server suite passes (the known timing tests pass alone), and eslint, prettier and plan-row.test.ts pass.

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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gkhngyk
gkhngyk merged commit 8c17113 into ansvisor:main Oct 30, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants