mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
create-pull-request/patch
9
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 |
||
|
|
e508c3c3f0 |
feat(studio): track schema visualizer usage (#53955)
## Problem The schema visualizer (`/project/[ref]/database/schemas`) sends no telemetry. We can't tell whether people use it to explore a schema or to export it, which export format they pick, or whether they edit tables from the graph. ## Solution Adds PostHog events for the visualizer's main actions: changing the schema, selecting a Find table result, copying (schema or table as SQL/Markdown, table or column name), downloading the graph as PNG or SVG, applying Auto layout, and choosing Edit table or Edit column from a node menu. Each event fires from the action's handler, so actions started from a keyboard shortcut count too. Properties are only fixed enums (`schemaType`, `content`, `format`, `action`); no schema, table, or column names are sent. Each tracked element also gets a `data-attr` for autocapture. View in Table Editor and the empty state's New table link get a `data-attr` only, because the pageview already records them. It also fixes an empty canvas after switching back to a schema that was already loaded. The graph stays mounted in that case and fitted the view only on first load, so the new schema's tables could sit off-screen until a reload. The view now fits whenever the schema on the canvas changes. Edits within the same schema still keep the current view. Studio's database pages keep the selected schema name in the `schema` URL param, and that name is chosen by the customer. Telemetry now redacts its value to `redacted` wherever it already redacts `keywords`: the event and pageview `page_url`, the query string, the referrer, first-touch data, and the URL properties posthog-js adds. This applies to every Studio event and pageview, not just this page. Params that only contain the word, such as `schemas` or `myschema`, are left alone. ## How to verify On the PR preview, open a project's Database > Schema Visualizer with PostHog debugging on (or watch the network requests to the telemetry endpoint), then: 1. Change the schema in the selector: one `database_schema_selector_updated` event with `schemaType` of `public`, `protected` (for example `auth`), or `custom`. 2. Open Find table and select a table: one `database_schema_visualizer_find_table_clicked` event. 3. Click Copy as SQL: one `database_schema_visualizer_copied` with `content: 'schema_sql'`. Copy as Markdown from the export menu sends `content: 'schema_markdown'`. 4. Download as PNG and as SVG: one `database_schema_visualizer_image_download_clicked` each, with `format` of `png` or `svg`. 5. Open Auto layout and click Apply: one `database_schema_visualizer_auto_layout_applied`. Cancel sends nothing. 6. From a table node menu, choose Copy name, Copy as SQL, and Copy as Markdown: `database_schema_visualizer_copied` with `content` of `table_name`, `table_sql`, and `table_markdown`. Column menu Copy name sends `column_name`. 7. From a table node menu choose Edit table, and from a column menu choose Edit column: `database_schema_visualizer_node_menu_clicked` with `action` of `edit_table` and `edit_column`. 8. No event carries a schema, table, or column name. 9. Switch the schema from public to auth, then back to public, with no reload: the public tables are shown and fitted on the canvas each time. Repeat auth → public → auth. 10. Edit a column from the graph and save: the view does not jump. 11. In the telemetry requests from steps 1 to 7 and in the pageview, `page_url` and `ph.search` show `schema=redacted`, never the schema name. The page itself still shows and switches the real schema. ## Checks Ran `pnpm turbo run typecheck --filter='...[origin/master]'`. Every package passed except studio, which ran out of memory beside a parallel lint run. `pnpm --filter studio run typecheck` alone then passed, and passed again after the view fix. `pnpm turbo run lint --filter='[origin/master]'` ran out of memory twice on studio's `lint:type-checks` (2 GB default heap). So I ran `eslint` and `eslint --config eslint.type-checks.config.cjs` on the changed Studio files with a larger heap: no errors, only pre-existing warnings. `vitest run components/interfaces/Database/Schemas/Schemas.utils.test.ts` passed. For the redaction, `vitest run` in `packages/common` (all 310 tests, including the new `schema` cases) and its `typecheck` passed; `common` has no lint script. `oxfmt --check` passes on all changed files. Event names and properties follow the repo's `telemetry-standards` skill. ## Checklist - [x] I have read the [contributing guidelines](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] The change is scoped to one feature - [x] Events are defined in `packages/common/telemetry-constants.ts` and added to the `TelemetryEvent` union ## Feedback for Tedd To ask Tedd for a change to this PR, reply in Tedd's session on [FE-5031](https://linear.app/supabase/issue/FE-5031/track-usage-on-the-schema-visualizer). Tedd doesn't read comments on this PR. --------- Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com> |
||
|
|
27578cdfb5 |
fix(telemetry): send search query shape instead of raw text (#53500)
Search telemetry sent whatever people typed, and search boxes are a place where people paste credentials and personal data. I replace the raw text with a description of it. #53336 added the raw `query` to `kb_search_submitted`; docs search and the command menu already sent it. **Changed:** - **I send a description of the search term**: `kb_search_submitted`, `docs_search_v2_search_submitted`, `docs_search_v2_result_clicked` and `command_menu_search_submitted` now send `queryLength` and `queryWordCount`, measured after trimming and collapsing repeated whitespace. - **Text only for keywords**: the term itself (`query`, `value`, and `search_query` on `command_menu_command_clicked`) is sent only when it is up to 4 letters-only parts of at most 16 letters each, 40 characters in total. Keys, tokens, emails, IDs, project refs and connection strings never match. Over the last 30 days that shape covers about 96% of command menu searches, 88% of docs searches and 73% of KB searches, so term-level analysis such as no-result queries keeps most of its data. - **I removed `keywords` from the auth users search event**: `auth_users_search_submitted` no longer carries it. Those terms identify customers' end users, and I confirmed nothing downstream reads them. - **The `keywords` URL parameter is redacted wherever telemetry copies a URL**: the Auth users page keeps the search term in its URL, so I replace the value with `keywords=redacted` in the page URL, query string and referrer we send, and in the posthog-js `before_send` hook for the URL properties the SDK fills in on its own (`$session_entry_url`, `$initial_current_url`, `$referrer`, `$initial_referrer`). The URL in the browser is unchanged. **Note:** a letters-only name or passphrase still matches the keyword shape, and longer questions lose their text. I opened this in place of #53435, which removed `query` from the KB event only. ## To test Tested on the PR previews (docs, kb, studio-staging), reading the request bodies sent to `/platform/telemetry/event`: - [x] Docs: open search and type `auth`, expect `docs_search_v2_search_submitted` with `query: "auth"`, `queryLength: 4` and `queryWordCount: 1`. Observed exactly that, with `hasResults: true`. - [x] Docs: type `person@example.com`, expect the same event with `queryLength: 18` and no `query`. Observed, and no telemetry body in that step contained the address. - [x] KB: search `how do I reset my database password`, expect `kb_search_submitted` with `queryLength: 35`, `queryWordCount: 7` and no `query`. Observed. - [x] KB: search `storage policies` with two spaces, expect `kb_search_submitted` with `query: "storage policies"` and `queryLength: 16`. Observed, with `queryWordCount: 2`. - [x] Studio: open the command menu and type `abcdefghijklmnopqrst`, expect `command_menu_search_submitted` with no `value`, then type `auth` and expect `value: "auth"`. Observed both, with `queryLength` 20 and 4. - [x] Studio: on Auth > Users, search `person@example.com`, expect `auth_users_search_submitted` with no `keywords`. Observed: `trigger`, `sort_column`, `sort_order`, `providers` and `filter_column` only. - [x] Studio: with `?keywords=person%40example.com` in the Auth > Users URL, reload, then trigger an event on the page, expect `page_url` and `ph.search` in the request body to carry `keywords=redacted` and the address bar to keep the real term. Observed on all three events from that page, and the address bar kept the term. - [x] Studio: from that URL, do a full page load to another project page and trigger an event, expect `ph.referrer` to carry `keywords=redacted` while `document.referrer` keeps the real term. Observed on all three events from the new page. - [x] Studio: after that session, query the staging analytics project for events from the preview host, expect no property value to carry the address or anything but `keywords=redacted`. Observed: none of the events in the test window carried the address, and the SDK's own `$set`, `$pageview` and `$pageleave` events arrived with `keywords=redacted` in `$current_url`, `$referrer` and `$initial_current_url`. The session started on a page without the parameter, so `$session_entry_url` was not exercised here; the unit test on the `before_send` hook covers it. ## Linear - fixes GROWTH-1501 |
||
|
|
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
|
||
|
|
571533482f |
refactor(growth): remove useTelemetryCookie and sb-telemetry-data cookie (#43840)
The `sb-telemetry-data` cookie and `useTelemetryCookie` hook are fully superseded by the `_sb_first_referrer` edge cookie (GROWTH-625) and the in-memory first-touch store (GROWTH-656). GROWTH-656 already removed the `useTelemetryCookie` call from `PageTelemetry` — this PR cleans up the rest. **Changes** - Delete `useTelemetryCookie.tsx` hook - Remove `clearTelemetryDataCookie` from `telemetry-utils.ts` (and its `TELEMETRY_DATA` dep) - Remove the `clearTelemetryDataCookie` call from `consent.tsx` (the cookie is never written anymore, so clearing it on deny is a no-op) - Remove `TELEMETRY_DATA` key from `LOCAL_STORAGE_KEYS` **Testing** Verified no remaining references to `useTelemetryCookie`, `sb-telemetry-data`, `TELEMETRY_DATA`, or `clearTelemetryDataCookie` in the codebase. GROWTH-646 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Removed local telemetry data collection and cookie storage functionality. * Updated consent handling to remove associated telemetry cookie cleanup operations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
1cd1ebfc7f |
chire: Sort imports in all packages, cms, design-system and ui-library apps (#41610)
Sorted all imports in all packages, `cms`, `design-system` and `ui-library` apps by running `pnpm format` on them. All changes in this PR are done by the script. |
||
|
|
de8e9f6b1b | Fix first-touch referrer for initial $pageview (#41447) | ||
|
|
97d746b665 |
fix: resolve 50% session tracking discrepancy on root route (#37853)
* fix: resolve 50% session tracking discrepancy on root route - Fixes race condition causing ~50% discrepancy in session tracking between client and server on root route - Implements event queuing to capture telemetry events before PostHog initializes - Adds session ID correlation to enable unified tracking analysis between client and server events - Uses sendBeacon API for both pageview and pageleave events to ensure reliable capture even during navigation - Adds production safeguards with try/catch blocks and memory caps to prevent API errors from breaking tracking * refactor(posthog-client): reduce max pending events and improve event handling - Decreased the maximum number of queued events from 200 to 20 - Added the use of the sendBeacon API for pending events to survive page unload - Added comments to clarify the handling of pending properties and events during posthog initialization |
||
|
|
6f1cfef213 |
clean circular deps (#34262)
* clean circular deps in telemetry * clean circular deps in command * fix commandmenu circular deps * rm deps.json * fix consent circular dep * fix TOC circular deps * fix wrong import path * fix test types * fix missing fn * undo let change * fix consent component * empty |