mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem Part of FE-5266 (remove or sample noisy Studio events). `explorer_banner_exposed` is among the highest-volume Studio events because it fires once per page load. It only needs to work as the denominator for the banner's dismiss and click-through rates. Its owner signed off on capping it at once per user per week. ## Solution - Keep the existing once-per-page-load guard, then check a last-sent timestamp in localStorage (new key `EXPLORER_BANNER_EXPOSED_AT`). The event is sent only if 7 days have passed since the last one, and the timestamp is updated when it is sent. - The check lives in `BannerExplorer.utils.ts` with a unit test, following the existing `BannerFreeMicroUpgrade.utils.ts` pattern. A missing, invalid or future timestamp counts as due, so a clock change can't suppress the event indefinitely. - Update the event's doc comment: it now fires at most once per browser per week. "Per user" is approximated per browser, because the timestamp lives in localStorage. Someone using several browsers, or clearing storage, is counted more than once, and a shared browser counts as one person. If storage is unavailable, behavior falls back to once per page load. This changes what fires, so it is a standalone PR that can be reverted on its own. The dismiss and CTA events are untouched.
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { isExplorerBannerExposureDue } from './BannerExplorer.utils'
|
|
|
|
const now = '2026-12-03T12:00:00.000Z'
|
|
|
|
describe('isExplorerBannerExposureDue', () => {
|
|
it('is due when never tracked', () => {
|
|
expect(isExplorerBannerExposureDue(null, now)).toBe(true)
|
|
expect(isExplorerBannerExposureDue(undefined, now)).toBe(true)
|
|
})
|
|
|
|
it('is not due within 7 days of the last event', () => {
|
|
expect(isExplorerBannerExposureDue('2026-12-03T11:00:00.000Z', now)).toBe(false)
|
|
expect(isExplorerBannerExposureDue('2026-11-26T12:00:01.000Z', now)).toBe(false)
|
|
})
|
|
|
|
it('is due once 7 days have passed', () => {
|
|
expect(isExplorerBannerExposureDue('2026-11-26T12:00:00.000Z', now)).toBe(true)
|
|
expect(isExplorerBannerExposureDue('2026-10-01T00:00:00.000Z', now)).toBe(true)
|
|
})
|
|
|
|
it('is due for invalid or future timestamps', () => {
|
|
expect(isExplorerBannerExposureDue('not-a-date', now)).toBe(true)
|
|
expect(isExplorerBannerExposureDue('2027-01-01T00:00:00.000Z', now)).toBe(true)
|
|
})
|
|
})
|