mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Opting out from the Privacy Settings modal (www, docs, kb) clears no cookies, and GTM keeps running. The banner's Opt out misses `_ga_<id>`, `_dcid`, and PostHog. ## Solution - `revokeTrackingConsent()` runs from `denyAll`, and from `updateServices` unless every service is accepted. It clears `_ga`, `_ga_*`, `_gcl_*`, `FP*`, `_dcid`, `session_id`, `ph_*_posthog`, PostHog's localStorage, stale consent copies. - PostHog resets and opts out, with persistence off. The opt-out survives sign-out. A saved accept opts back in. - Every opt-out calls `POST /platform/telemetry/reset` (keepalive, errors ignored) to clear the API's HttpOnly `session_id`, `anonymous_id`, and `user_id`. Studio's own call is removed. - To stop GTM, a saved opt-out reloads the page if tracking was on, waiting at most 1s for the reset. ## Review instructions 1. `cd packages/common && npx vitest run consent-state.test.ts posthog-client.test.ts` 2. On prod: accept, open Privacy Settings, turn Marketing off, Confirm. The page reloads with cookies gone and no `collect` request. Tested: `common` (237 pass), `AnalyticsSettings` tests, CI unit tests and typecheck. No browser test (previews lack Usercentrics). ## Checklist - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { clearLocalStorage, LOCAL_STORAGE_KEYS } from 'common'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
describe('clearLocalStorage', () => {
|
|
it('preserves queue operations preferences while removing non-allowlisted keys', () => {
|
|
localStorage.clear()
|
|
|
|
localStorage.setItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_QUEUE_OPERATIONS, 'true')
|
|
localStorage.setItem('not-allowlisted', 'remove-me')
|
|
localStorage.setItem('account-recovery-reminder:user-a', 'snooze-a')
|
|
localStorage.setItem('account-recovery-reminder:user-b', 'snooze-b')
|
|
const followUpKey = LOCAL_STORAGE_KEYS.ONBOARDING_SURVEY_FOLLOW_UP('user-a', 'new-org')
|
|
localStorage.setItem(followUpKey, 'pending')
|
|
|
|
clearLocalStorage()
|
|
|
|
expect(localStorage.getItem(LOCAL_STORAGE_KEYS.UI_PREVIEW_QUEUE_OPERATIONS)).toBe('true')
|
|
expect(localStorage.getItem('not-allowlisted')).toBeNull()
|
|
expect(localStorage.getItem('account-recovery-reminder:user-a')).toBe('snooze-a')
|
|
expect(localStorage.getItem('account-recovery-reminder:user-b')).toBe('snooze-b')
|
|
expect(localStorage.getItem(followUpKey)).toBe('pending')
|
|
})
|
|
|
|
it('keeps the visitor consent records so an opt-out survives sign-out', () => {
|
|
localStorage.clear()
|
|
const consentKeys = [
|
|
'uc_settings',
|
|
'uc_user_interaction',
|
|
'ucData',
|
|
'ucString',
|
|
'__ph_opt_in_out_phc_test',
|
|
]
|
|
consentKeys.forEach((key) => localStorage.setItem(key, 'x'))
|
|
|
|
clearLocalStorage()
|
|
|
|
consentKeys.forEach((key) => expect(localStorage.getItem(key)).toBe('x'))
|
|
})
|
|
})
|