mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
Adds an optional onboarding survey to the new-organization form, so we
learn who new orgs are for and what they are building. Users in the
`org_form` arm of the `onboardingSurveyPlacement` PostHog flag see a
**Help improve Supabase** section. Users in `control` get today's form
unchanged and still record exposure, so the two arms can be compared;
users the flag doesn't assign get the existing form and record nothing.
**Changed:**
- **Survey on the new-org form**: asks **Who is this org for?** (plus
**How many people?** for companies) and **What are you building?** (AI
assistant or agent, AI search or knowledge base, B2B SaaS, internal
tool, consumer app, social or community, marketplace or booking,
e-commerce, developer tool or app builder, analytics or reporting,
other). Every question ends with **Prefer not to say**. Answers go to
`POST /platform/organizations/onboarding-survey` as `kind`, `size` and
`building`.
- **Follow-up card for a blank survey**: if the creator answers nothing,
a card in the bottom-right asks the same questions for 5 minutes after
the org is created (not on project creation pages). Only the creator
sees it, once, tracked in localStorage. A blank form sends nothing at
creation, because the platform keeps only the first survey response per
user and org. Skipping the card, closing it, or letting the 5 minutes
run out still saves the org type and size picked on the form.
- **Telemetry**: exposure for both arms, plus submit, submit failed,
dismissed (including `follow_up_expired` when the card times out) and
Answer clicked events with `surface` set to `org_form` or `follow_up`.
**Note:** I cut **How comfortable are you working with code?** from v1.
The survey endpoint doesn't accept `coding_experience` yet, and the
question is planned to move to the user level later.
## To test
Setup: override `onboardingSurveyPlacement` to `org_form` in the dev
toolbar. Close the Terms of Service banner first, since the follow-up
card shares its slot.
Tested on the PR preview:
- [x] Create an org with **Who is this org for?** and **What are you
building?** answered, expect one `POST
/platform/organizations/onboarding-survey` carrying `kind` and
`building` (plus `size` for companies), no `coding_experience` key, and
no `kind` or `size` in the org-create request. Observed: 204 with
`{"slug":"<slug>","kind":"COMPANY","size":"10","building":"b2b_saas"}`;
org-create body was `{"name":"<name>","tier":"tier_free"}`
- [x] Create an org with the survey left blank, then open its projects
page, expect the follow-up card; answer it, expect the same survey
request and a "Thanks for sharing" toast. Observed: no survey request at
creation; after answering, 204 with
`{"slug":"<slug>","kind":"PERSONAL","building":"consumer_app"}` and the
toast
- [x] Override to `control`, open the new-org form, expect the same form
as master (Name, Type, Company size with "How many people are in your
company?" for Company, then Plan), no survey section, and an
`onboarding_survey_placement_experiment_exposed` event with `variant:
control`. Observed: screenshots match master's form field for field; the
exposure arrived in PostHog with `variant: control`
- [x] Create an org with the survey left blank and don't act on the
follow-up card for 5 minutes, expect the card to disappear, one `POST
/platform/organizations/onboarding-survey` carrying the form's `kind`
(plus `size` for companies) and no `building`, and an
`onboarding_survey_dismissed` event with `reason: follow_up_expired`.
Observed (stored follow-up time moved to near expiry instead of
waiting): the card disappeared at the 5-minute mark with one 204
carrying `{"slug":"<slug>","kind":"AGENCY"}` and the `follow_up_expired`
event; an already-expired follow-up sends on page load; with the dialog
open past expiry nothing is sent until it is closed
## Linear
- fixes GROWTH-771
- part of GROWTH-1463
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Pamela Chia <pamelachiamayyee@gmail.com>
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
import { LOCAL_STORAGE_KEYS, safeLocalStorage } from 'common'
|
|
import { z } from 'zod'
|
|
|
|
import { ONBOARDING_SURVEY_FOLLOW_UP_WINDOW_MS } from './OnboardingSurvey.constants'
|
|
|
|
const followUpStateSchema = z.object({
|
|
status: z.enum(['pending', 'submitted', 'dismissed']),
|
|
orgCreatedAt: z.string(),
|
|
// The org's type and size from the new-org form, saved with the follow-up's
|
|
// answers since the form sent nothing at creation
|
|
kind: z.string().optional(),
|
|
size: z.string().optional(),
|
|
})
|
|
|
|
export type OnboardingSurveyFollowUpState = z.infer<typeof followUpStateSchema>
|
|
export type OnboardingSurveyFollowUpStatus = OnboardingSurveyFollowUpState['status']
|
|
|
|
export function parseFollowUpState(value: unknown): OnboardingSurveyFollowUpState | null {
|
|
const result = followUpStateSchema.safeParse(value)
|
|
return result.success ? result.data : null
|
|
}
|
|
|
|
/**
|
|
* Records that the org's creator left the survey blank on the new-org form, so
|
|
* the follow-up card can ask again. Written to the creator's browser only,
|
|
* which is what limits the follow-up to the creator.
|
|
*/
|
|
export function markFollowUpPending({
|
|
profileId,
|
|
orgSlug,
|
|
kind,
|
|
size,
|
|
now = new Date(),
|
|
}: {
|
|
profileId: string
|
|
orgSlug: string
|
|
kind?: string
|
|
size?: string
|
|
now?: Date
|
|
}) {
|
|
const state: OnboardingSurveyFollowUpState = {
|
|
status: 'pending',
|
|
orgCreatedAt: now.toISOString(),
|
|
kind,
|
|
size,
|
|
}
|
|
safeLocalStorage.setItem(
|
|
LOCAL_STORAGE_KEYS.ONBOARDING_SURVEY_FOLLOW_UP(profileId, orgSlug),
|
|
JSON.stringify(state)
|
|
)
|
|
}
|
|
|
|
/** Milliseconds left to show the follow-up for an org created at `orgCreatedAt`. */
|
|
export function getFollowUpRemainingMs(orgCreatedAt: string, now: number) {
|
|
const createdAt = Date.parse(orgCreatedAt)
|
|
if (Number.isNaN(createdAt)) return 0
|
|
return Math.max(0, createdAt + ONBOARDING_SURVEY_FOLLOW_UP_WINDOW_MS - now)
|
|
}
|
|
|
|
/**
|
|
* Project creation pages (/new/[slug] and the Vercel deploy-button flow) are
|
|
* where the creator is likely to land right after making the org; keep the
|
|
* follow-up out of their way there.
|
|
*/
|
|
export function isProjectCreationPath(pathname: string | null | undefined) {
|
|
if (!pathname) return false
|
|
return pathname === '/new' || pathname.startsWith('/new/') || pathname.endsWith('/new-project')
|
|
}
|