mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
docs/tutorial-template
14
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d336555617 |
fix(telemetry): redact url params and page titles (#54044)
The frontend apps send the current URL and page title with every analytics event. The redaction added in #53500 and extended in #53955 only covers the `keywords` and `schema` params, so Table Editor filters, search text, invite tokens, OAuth codes and the auth redirect hash still go out in URL properties, and Studio's title carries the table, project and org names. **Changed:** - **Query values are redacted by default**: every `name=value` in a URL property now goes out as `name=redacted`, unless the name is one that attribution reads downstream (`utm_*`, the click ids the first-referrer cookie already collects, `dub_id`, `campaign_id`, `cid`, `promo_code`). Param names and the `?` stay, so reports that match on a param being present keep working. Fixed-vocabulary params such as `tab` are not on the list: nothing reads them today, and several of those names carry customer data on other pages. - **A change to a redacted value no longer sends a pageview**: picking a new filter value on the same page used to send a pageview, which would now be identical to the previous one. The dedupe check compares the redacted URL, so it is skipped. This lowers Studio pageview counts: on current traffic, at most about 9% of dashboard pageviews repeat the previous path with a query string. - **Events from both transports are covered, and the hash is dropped**: `identify` and `group` let the SDK stamp its own `$current_url` with the hash, and `$set_once` pinned that on the person. `before_send` now strips it, and the SDK no longer captures hashes itself. Custom events skip `before_send`, so the same redaction also runs on their `pathname` field, where www was appending the raw query string. The SDK's copy of a search-engine referrer's query (`ph_keyword`) is dropped too. - **Studio sends a route-level title**: `Tables | Database | Supabase` in place of `users | Tables | Database | <project> | <org> | Supabase`. The tab title users see is unchanged, and so are titles in the other apps, which are public content. - **Dead clicks, heatmaps and web vitals are pinned off**: each one puts page text or the page URL in a nested payload the redaction does not walk, and each can be switched on from project settings without a deploy. All three are off today. **Note:** One path is only partly covered. Feature-flag requests carry the first URL and referrer the SDK stored for the browser, and they never pass through `before_send`. The hash is now gone from them; query values in that first URL (for example an invite link opened in a fresh browser) still go out on those requests. ## To test Signed in on the Studio preview, with analytics consent accepted. Check events in the staging analytics project, filtered to the preview host. Tested on the PR preview: - [x] Open the Table Editor, add a filter with the value `leaktest@example.com` and a sort, type `leaktest` in the Tables search and in a logs search, then click through a few pages. Expect no event containing `leaktest`, and `filter=redacted`, `sort=redacted`, `search=redacted` and `s=redacted` in `$current_url`. Observed: zero events from the preview host contained `leaktest`; custom events, `$pageview`, `$pageleave` and `$set` all carried the `=redacted` forms. The filter and sort were applied by loading the Table Editor URL with them, which is how the app restores them - [x] Same session: expect `page_title` and `title` on every event to hold only page names (for example `Tables | Database | Supabase`), with no project, org or table name. Observed: `Table Editor | Supabase`, `Tables | Database | Supabase`, `Postgres Logs | Logs | Supabase`, `Team | Supabase` and similar; no event carried the project, org or table name. `explorer_*` events keep their existing fixed title `Explorer` - [x] Load `/dashboard/project/<ref>?token=leaktest1&projectName=leaktest2#access_token=leaktest3`, then open `/join?token=leaktest4&slug=x`. Expect zero events containing `leaktest`, including `$set`, `$identify` and `$groupidentify`. Observed: zero, with `token=redacted&projectName=redacted` and no hash on any stored URL. `$set` and `$groupidentify` fired and were clean; no `$identify` fired in this session (the user was already identified), so that event was not observed - [x] Load any page with `?utm_source=readable5` appended. Expect `utm_source=readable5` readable in `$current_url`. Observed on Database > Tables with `?utm_source=readable5&gclid=readable6&tab=readable7`: both attribution params readable, `tab=redacted`. The Table Editor route rewrites its own query string and drops unknown params before any event fires, so use another page - [x] Open a table in the Table Editor. Expect the browser tab title to still lead with the table name and include the project and org names. Observed: `<table> | Table Editor | <project> | <org> | Supabase` - [x] On the Table Editor with a filter applied, change the filter value twice, then add a sort. Expect no new `$pageview` for the two value changes and one for the added sort (a new param name). Observed, all through the UI with no reload: adding the filter sent one pageview, the two value changes sent none, adding the sort sent one, and a sidebar navigation sent one; the staging analytics project shows the same four pageviews ## Linear - fixes GROWTH-1572 |
||
|
|
bbb0af65cb |
[FE-3106] (part 14) – refactor(studio): drop the dual-runtime shims and aliases (#53223)
Drops the remaining Next-era shims and aliases that only existed for the dual runtime (FE-3106). Part 14 of the stack. **Depends on:** #53222 **Changed:** - ~45 files – import Sentry from `@sentry/react` directly instead of the aliased `@sentry/nextjs` - `hooks/ui/usePreventNavigationOnUnsavedChanges.ts` – is now the TanStack `useBlocker` implementation (previously swapped in by a Vite alias) - `components/interfaces/App/RouteValidationWrapper.tsx` – `next/router` → `useNavigate` + the leaf route's `fullPath` (`/project/$ref/sql/$id`) for the exempt-route and last-visited checks - `hooks/misc/withAuth.tsx` – no `getLayout` forwarding - `TemplateEditor.test.tsx` – renders inside a router for the unsaved-changes blocker **Removed:** - `compat/sentry-nextjs.ts` and its Vite alias, the `usePreventNavigationOnUnsavedChanges` alias and Next hook, `types/next.ts` (`NextPageWithLayout`), the `@sentry/nextjs` dependency The `compat/next/*` shims for `link`, `router`, `head`, `image`, `navigation`, `dynamic` and `script` stay: about 300 components outside `routes/**` still import them. Addresses [FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages). ## To test - Trigger an error (e.g. a failing query) – it reaches Sentry as before - Edit an email template or edge function and navigate away – the unsaved-changes prompt appears - Open an org you don't belong to – toast and redirect home; open a SQL snippet, leave and come back – last snippet is restored --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com> |
||
|
|
d862ac18f2 |
feat(telemetry): stamp the app's platform on every event (#53078)
Every first-party PostHog event now carries a `platform` property naming
the supabase.com app that sent it. Each app passes its directory name
(`studio`, `www`, `docs`, `kb`, `learn`, `ui-library`) once at telemetry
setup, and I stamp it on both send paths.
**Changed:**
- **Events sent through the Management API**
(`/platform/telemetry/event`): `buildTelemetryEventRequest` adds
`platform` to `custom_properties`. This also covers kb's search events,
which build the request without `sendTelemetryEvent`.
- **Events sent by posthog-js** (pageviews, page leaves, identify,
experiment exposures): a `before_send` hook stamps `platform` at send
time.
- **App setup**: `PageTelemetry` takes a required `platform` prop, and
kb's island sets the value directly. While unset, the property is left
off instead of defaulting to an app.
**Note:** I used `before_send` instead of `posthog.register()`. Super
properties persist in localStorage, which every supabase.com app shares,
so events sent before `register()` runs would carry the previous app's
value.
**Do not merge yet.** Studio's `trackFeatureFlag` body still needs
`platform`. That commit waits for the Management API change that accepts
the field to reach production, plus an `api-types` regen. The flag-track
body is strict, so sending `platform` early returns 400 on every flag
call.
## To test
On each app's preview, accept cookies and add `?__posthog_debug=true` to
the URL.
- [x] Studio: load a page, expect `$pageview` with `properties.platform:
"studio"` (seen at ingestion: the staging PostHog project has
`$pageview` and `$pageleave` events from the studio-staging preview
host, all with `platform: "studio"`)
- [x] www: load the homepage, expect `send "$pageview"` with `platform:
"www"`; click "Start your project", expect the
`/platform/telemetry/event` request body to have
`custom_properties.platform: "www"` (both seen)
- [x] docs: load a guide, expect `send "$pageview"` with `platform:
"docs"` (seen); added: "Copy as Markdown" sends `custom_properties:
{"pageType":"guide","platform":"docs"}`
- [x] kb: load a page, expect `send "$pageview"` with `platform: "kb"`;
run a search, expect the `/platform/telemetry/event` body to have
`custom_properties.platform: "kb"` (seen on both `kb_search_submitted`
and `kb_search_result_clicked`)
- [ ] learn and ui-library: load a page, expect `send "$pageview"` with
`platform: "learn"` and `"ui-library"` respectively. Not checkable on
previews: learn has no preview deployment, and the ui-library preview
host is not on the consent provider's allowlist, so telemetry never
starts there.
- [x] Added, negative check: on docs, kb and www, no captured posthog-js
event had `platform` unset or set to another app
- [x] Added, ingestion: in the staging PostHog project,
`copy_as_markdown_clicked` (docs) and `start_project_button_clicked`
(www) carry `platform` as a top-level event property
## Linear
- fixes GROWTH-1450
|
||
|
|
e88a3723e1 |
feat(studio): add PostHog session replay with masked-by-default policy (#48515)
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Telemetry feature. ## What is the current behavior? - Session replay is off, and nothing in the code keeps it off. - `packages/common/posthog-client.ts` sets no recording config at all. - So PostHog's project setting alone decides, for every app sharing that project. - Studio, www and docs share one project. - Studio shows customer data almost everywhere: SQL editor, table rows, connection strings, API keys. - posthog-js masks inputs by default. It does not mask rendered text. - [GROWTH-1055](https://linear.app/supabase/issue/GROWTH-1055) ## What is the new behavior? - `posthogClient.init()` takes a masking config, and disables recording when it gets none. - Studio passes one behind `NEXT_PUBLIC_POSTHOG_SESSION_REPLAY`. - Every other app passes nothing, so it never loads the recorder. - Studio masks all text and all inputs. - `data-ph-capture="true"` opts one element's text back in. Unused so far. - Canvas is blocked, because it records as images that text masking cannot reach. - Query strings and fragments are stripped from recorded URLs, where auth callbacks carry tokens. - Request and response bodies are never recorded. - Console logs are never recorded, since masking only reaches DOM text. - Masking is set in code, so PostHog's settings cannot loosen it. - Consent gating is unchanged. Nothing records before a user accepts. ## Additional context - Recording needs three things: this env var, the PostHog project toggle, and user consent. - All three are off or unset, so merging this changes nothing at runtime. - `NEXT_PUBLIC_POSTHOG_SESSION_REPLAY` goes into Vercel on Preview scope first, to test on a preview build. - Production scope comes later, once we are ready to record there. - `NEXT_PUBLIC_*` is inlined at build time, so each scope needs a rebuild afterwards. - Text inside HTML attributes (`title`, `alt`, `href`) is still recorded as-is. - posthog-js exposes no hook for masking attributes, so covering it needs `ph-no-capture` per component. - Staging has no server-side masking config, so that is where this gets verified. - Plan: enable recording on staging, verify masked text on a preview, then decide on production. - Network timing stays on for the dashboard performance work. Payloads stay off. - Tests cover both masking functions and the config values. ## Screenshots https://github.com/user-attachments/assets/aa064a04-f977-4453-a3da-2fe0cdcead08 <img width="889" height="651" alt="CleanShot 2026-07-31 at 10 13 43" src="https://github.com/user-attachments/assets/f1d07946-fd68-42b2-89f1-d201bc605638" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **New Features** * Added privacy-focused session replay for Studio. * Text and form inputs are masked by default, with explicit opt-in capture. * Network recordings remove query strings and fragments. * Headers, request bodies, canvas data, and console logs are excluded. * **Bug Fixes** * Improved whitespace and capture-attribute handling during masking. * Session replay remains disabled without a masking policy or explicit enablement. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
fae2c5b96e |
chore: Add org slug and project ref as tags to the Sentry data (#47442)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced telemetry to include the active project reference and selected organization on events. * Cleared and re-applied project and organization tags when navigating to prevent stale tagging. * Only applies user identification when user account details are available. * **Tests** * Updated telemetry tests to cover the additional tagging behavior by extending Sentry mocks accordingly. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
a9565c1645 |
refactor: Optimize Sentry user ids (#47342)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved signed-in user identification in error tracking to use the current authenticated user ID directly. * Removed reliance on previously stored anonymous identifiers, reducing inconsistent user matching across sessions. * **Tests** * Added coverage to confirm error tracking user identity is set when a user is signed in and not set when signed out. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
9eab4f8fbf |
build(studio): Vite/TanStack-Start build pipeline behind flag (stack 1/6, from #46424) (#47107)
**Stack 1/6** of the TanStack Start migration (#46424), split into reviewable, independently-mergeable PRs. > [!IMPORTANT] > **Next stays the default and only active framework after this PR.** This wires up the Vite/TanStack-Start build pipeline behind the `STUDIO_FRAMEWORK` flag, but there are no TanStack routes yet — so the TanStack build isn't functional or tested until later PRs in the stack. Nothing about the Next build, dev, or deploy changes behaviourally here. ## What's in this PR - **Dispatch:** `dev`/`build`/`start` now go through `scripts/dispatch.js`, which runs the Next variant unless `STUDIO_FRAMEWORK=tanstack`. The original commands are preserved as `dev:next`/`build:next`/`start:next`. - **Build pipeline:** `vite.config.ts`, `serve.js`, `smoke-server.mjs`, vite/tanstack deps, `turbo.jsonc`. - **`tsconfig.json`:** `jsx: react-jsx`, `moduleResolution: Bundler`, `target: ES2022`. Because `include` is `**/*.ts(x)`, this re-typechecks the whole app, so the companion adaptations below land with it. - **Shared adaptations (companions to the tsconfig change):** `BufferSource` casts, `packages/ui` unused-`React` import removals, etc. - **Routing/middleware plumbing:** `next.config.ts` + `redirects.shared.ts` (redirect rules now shared with `vercel.ts`), `proxy.ts`/`start.ts` middleware + `hosted-api-allowlist.ts`. ## Verification Run locally off `master`: frozen install ✓, `studio` typecheck ✓, **Next build ✓** (compiles + generates all routes), lint ratchet ✓ ("some rules improved"), prettier ✓. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a hosted API endpoint allowlist to return 404 for non-supported `/api/*` routes. * Introduced a TanStack route-migration checklist and expanded TanStack Start routing support. * **Improvements** * Enhanced deployment refresh/detection by tightening cookie handling for “latest deployment” updates. * Centralized redirect/maintenance-mode rules for consistent platform vs self-hosted behavior. * Improved production serving with a dedicated static + proxy server and a post-build smoke test. * **Dependencies** * Updated TanStack-related packages and React Table/query tooling versions. * **Documentation / Chores** * Updated formatting and tooling config; added shared build environment parsing utilities. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com> |
||
|
|
1c2d28d5b3 |
chore: wrap local storage into helper methods that are safer (#46628)
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? - Noticing our code we have many patterns of calling localstorage and handling those errors - We should add those in a single well tested file - Handle those errors in the singleton which makes it easier for us to debug customer issues. Logger is outputing local storage warnings for feature we expose - Side effect of this is random crashes on studio when local storage isn't available or handled correctly <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Improved browser storage handling across the app for more reliable persistence and graceful behavior in restricted or non-browser environments (settings, previews, charts, tabs, sign-in/session flows, integrations, and UI state). * **New Features** * Introduced a safe storage layer to standardize and harden local/session persistence. * **Tests** * Added comprehensive tests covering the new safe storage behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
0eb37adb19 | fix(telemetry): pass signup_timestamp on org_count identify (#46005) | ||
|
|
4c77ab5fef |
feat(telemetry): mirror org_count to PostHog person property (#45946)
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Feature + two follow-on fixes — small, scoped to telemetry / experiment plumbing. ## What is the current behavior? PostHog feature flags evaluated in Studio only have access to the `gotrue_id` person property (set in `useTelemetryIdentify`) and the `organization`/`project` group associations from pageviews. Flags can't target users by org membership without a behavioral cohort, which refreshes on a ~hourly schedule and lags behind real-time signup state. This is blocking the rollout of the `dataApiRevokeOnCreateDefault` experiment ahead of the May 30 default-privileges breaking change — we need to target brand-new dashboard signups with no prior org membership, and there's no person property to filter on. ## What is the new behavior? Three changes, scoped tightly to make experiment targeting reliable for brand-new signups: ### 1. Mirror `org_count` to a PostHog person property (`apps/studio/lib/telemetry.tsx`) The Studio `Telemetry` component now mirrors the user's current org-list length to a PostHog person property `org_count` via `posthog.identify(user.id, { org_count })`. The effect: - Subscribes to `useOrganizationsQuery` (shares the same React Query cache as `useSelectedOrganizationQuery`, so no extra network requests). - Dedupes via a ref keyed on `{ userId, orgCount }` so we only call identify when the value actually changes — handles user-switch (logout/login as different user with same count) correctly. - Generic enough to be useful beyond this experiment — analytics segmentation by org membership, future flags that depend on multi-org behavior, etc. ### 2. Merge pre-init identify properties (`packages/common/posthog-client.ts`) The previous `pendingIdentification` slot was a single-write buffer — calling `posthogClient.identify()` before the PostHog SDK initialized would overwrite any prior queued identify. Latent until this PR added a second identify caller (`org_count`), which exposed the last-write-wins behavior on first-visitor-before-consent flows. Now merges properties across pre-init calls for the same user so both `{ gotrue_id }` and `{ org_count }` land on the person record when the SDK flushes. Caught during Codex review. ### 3. Gate the exposure event on `org_count` being present (`apps/studio/hooks/misc/useDataApiRevokeOnCreateDefault.ts`) `useTrackDefaultPrivilegesExposure` previously fired on the first non-undefined value of the `dataApiRevokeOnCreateDefault` flag. For brand-new signups, this races the `org_count` identify: the initial `/flags/` response (before targeting can match) returns the untargeted variant, the exposure locks it in via `hasTracked`, then our identify fires and a subsequent `/flags/` refresh updates the flag — but the exposure has already recorded the wrong variant. Fix: gate the exposure on `org_count` being present on the SDK person, subscribing via `onFeatureFlags` so we pick up the post-identify `/flags/` response. Adds `posthogClient.getPersonProperty` as the local-state reader. Without this, the experiment would have a ~5-15% noise floor on cohort assignment for new signups. ## Verification End-to-end verified locally against the staging PostHog project (34343): - Local Studio's PostHog SDK has `$stored_person_properties: { gotrue_id: <uuid>, org_count: 1 }` after sign-in. - Both `$set` events landed server-side within ~300ms of each other, and the staging person record now shows `org_count = 1.0` with `gotrue_id` preserved. - Targeting query `person.properties.org_count == 1` works end-to-end against staging. ## Additional context Ref: [GROWTH-853](https://linear.app/supabase/issue/GROWTH-853) Targeting plan for the flag once shipped: `person.org_count == 1` plus a behavioral filter on recent `sign_up` event, at 5% rollout. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Telemetry now records and syncs the user's organization count as an analytics person property and avoids redundant identifications when unchanged. * Analytics client now merges queued identification properties made before initialization and exposes a method to read stored person properties. * **Bug Fixes** * Tracking now waits for organization-count readiness before firing certain exposure events to prevent missing data. * **Tests** * Added/updated tests to cover person-property behavior and gating logic. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45946) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
205cbe7d26 | chore(studio}: enforce import order, remove bare import specifiers (#44585) | ||
|
|
d32ccb0d17 |
fix: Send a hashed user id with every Sentry event (#39430)
* Generate and set the sentry user id for better sentry reports. * Delete unused files. * Fix a small react warning. |
||
|
|
e3e8528f72 |
feat: add client-side PostHog telemetry tracking (#37442)
Adds client-side PostHog tracking to run in parallel with server-side telemetry across studio, docs, and www. This enables session replays and resolves a race condition where page views arrive before group assignments resulting in attribution errors. Changes: - Created PostHog client wrapper with consent-aware initialization in common package - Integrated PostHog client calls into existing telemetry functions to send events to both PostHog (client) and backend (server) - Updated CSP to allow connections to PostHog endpoints - Added environment variable support for all apps - PostHog client accepts consent as a parameter and respects user preferences - Events can be distinguished in PostHog by $lib property (posthog-js vs posthog-node) - PostHog URL configured based on environment (staging/local uses ph.supabase.green) - Maintains full backward compatibility with existing telemetry system Resolves GROWTH-438 Resolves GROWTH-271 |
||
|
|
2b419c70a1 |
chore: add usercentrics for consent management (#35384)
* chore: add usercentrics for consent management * client component to make next.js happy * address feedback * move consent state to common * fix import * ensure page events are sent correctly * add feature flag provider to ui library site * fix ui lib 500 error * skip in test env --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Jordi Enric <jordi.err@gmail.com> |