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.
20 lines
724 B
TypeScript
20 lines
724 B
TypeScript
import dayjs from 'dayjs'
|
|
|
|
export const EXPLORER_BANNER_EXPOSURE_INTERVAL_DAYS = 7
|
|
|
|
/**
|
|
* The exposure event is sent at most once per interval per browser. A missing or unparseable
|
|
* timestamp, or one in the future (e.g. after a clock change), counts as due so the event
|
|
* can't be suppressed indefinitely.
|
|
*/
|
|
export const isExplorerBannerExposureDue = (
|
|
lastTrackedAt: string | null | undefined,
|
|
now: dayjs.ConfigType = dayjs()
|
|
) => {
|
|
if (typeof lastTrackedAt !== 'string') return true
|
|
const lastTracked = dayjs(lastTrackedAt)
|
|
if (!lastTracked.isValid()) return true
|
|
const daysSince = dayjs(now).diff(lastTracked, 'day', true)
|
|
return daysSince < 0 || daysSince >= EXPLORER_BANNER_EXPOSURE_INTERVAL_DAYS
|
|
}
|