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.
102 lines
3.8 KiB
TypeScript
102 lines
3.8 KiB
TypeScript
import { LOCAL_STORAGE_KEYS, safeLocalStorage } from 'common'
|
|
import { AnimatePresence, motion } from 'motion/react'
|
|
import { useEffect } from 'react'
|
|
import { Badge, Button } from 'ui'
|
|
|
|
import { BannerCard } from '../BannerCard'
|
|
import { useBannerStack } from '../BannerStackProvider'
|
|
import { isExplorerBannerExposureDue } from './BannerExplorer.utils'
|
|
import { useFeaturePreviewModal } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
let hasTrackedExposureThisPageLoad = false
|
|
|
|
export const BannerExplorer = () => {
|
|
const track = useTrack()
|
|
const { dismissBanner } = useBannerStack()
|
|
const { selectFeaturePreview } = useFeaturePreviewModal()
|
|
|
|
const [, setIsDismissed] = useLocalStorageQuery(
|
|
LOCAL_STORAGE_KEYS.EXPLORER_BANNER_DISMISSED,
|
|
false
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (hasTrackedExposureThisPageLoad) return
|
|
hasTrackedExposureThisPageLoad = true
|
|
|
|
const lastTrackedAt = safeLocalStorage.getItem(LOCAL_STORAGE_KEYS.EXPLORER_BANNER_EXPOSED_AT)
|
|
if (!isExplorerBannerExposureDue(lastTrackedAt)) return
|
|
|
|
safeLocalStorage.setItem(
|
|
LOCAL_STORAGE_KEYS.EXPLORER_BANNER_EXPOSED_AT,
|
|
new Date().toISOString()
|
|
)
|
|
track('explorer_banner_exposed')
|
|
}, [track])
|
|
|
|
return (
|
|
<BannerCard
|
|
onDismiss={() => {
|
|
setIsDismissed(true)
|
|
dismissBanner('explorer-banner')
|
|
track('explorer_banner_dismiss_button_clicked')
|
|
}}
|
|
>
|
|
<div className="flex flex-col gap-y-4">
|
|
<div className="flex flex-col gap-y-2 items-start w-full">
|
|
<Badge variant="success" className="-ml-0.5 uppercase inline-flex items-center">
|
|
Preview
|
|
</Badge>
|
|
<AnimatePresence>
|
|
<div className="border h-27 w-full rounded-t-md mt-2 bg-surface-100 py-4 px-2 pb-0">
|
|
<motion.div
|
|
initial={{ opacity: 0, top: 10 }}
|
|
animate={{ opacity: 1, top: 0 }}
|
|
transition={{ delay: 0.5, duration: 0.2, ease: 'easeOut' }}
|
|
className="w-[90%] mx-auto"
|
|
>
|
|
<p className="text-[10px]">User growth</p>
|
|
<p className="text-[9px] text-foreground-lighter">
|
|
Track how your user base is trending.
|
|
</p>
|
|
</motion.div>
|
|
<motion.div
|
|
initial={{ opacity: 0, top: 10 }}
|
|
animate={{ opacity: 1, top: 0 }}
|
|
transition={{ delay: 1, duration: 0.2, ease: 'easeOut' }}
|
|
className="w-full h-13.5 border border-b-0 mt-2 rounded-t bg-surface-200 overflow-hidden"
|
|
>
|
|
<div className="h-3 w-full border-b" />
|
|
<p className="px-2 py-1 text-[8px] font-mono tracking-tighter flex flex-col">
|
|
<span className="text-code_block-1">select</span>
|
|
<span className="pl-2">date_trunc('week', last_sign_in_at) as week,</span>
|
|
<span className="pl-2">count(distinct id) as active_users</span>
|
|
</p>
|
|
</motion.div>
|
|
</div>
|
|
</AnimatePresence>
|
|
</div>
|
|
<div className="flex flex-col gap-y-1 mb-2">
|
|
<p className="text-sm font-medium">Explorer & Notebooks</p>
|
|
<p className="text-xs text-foreground-lighter text-balance">
|
|
New unified workspace for querying data and chatting with Assistant.
|
|
</p>
|
|
</div>
|
|
<div className="flex gap-2">
|
|
<Button
|
|
size="tiny"
|
|
onClick={() => {
|
|
selectFeaturePreview(LOCAL_STORAGE_KEYS.UI_PREVIEW_EXPLORER)
|
|
track('explorer_banner_cta_button_clicked')
|
|
}}
|
|
>
|
|
Enable Explorer
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</BannerCard>
|
|
)
|
|
}
|