Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

guard events (#28817)

Francesco Sansalvadored09a25f74239
diff --git a/apps/www/lib/telemetry.ts b/apps/www/lib/telemetry.ts
index a880edb6f5b..31f2eb90343 100644
--- a/apps/www/lib/telemetry.ts
+++ b/apps/www/lib/telemetry.ts
@@ -1,6 +1,7 @@
import { post } from '~/lib/fetchWrapper'
import { API_URL, IS_PROD, IS_PREVIEW } from 'lib/constants'
import { NextRouter } from 'next/router'
+import { LOCAL_STORAGE_KEYS } from 'common'
export interface TelemetryEvent {
category: string
@@ -14,11 +15,21 @@ export interface TelemetryProps {
language: string
}
+const noop = () => {}
+
// This event is the same as in studio/lib/telemetry.tx
// but uses different ENV variables for www
const sendEvent = (event: TelemetryEvent, gaProps: TelemetryProps, router: NextRouter) => {
- if (!IS_PROD && !IS_PREVIEW) return
+ const consent =
+ typeof window !== 'undefined'
+ ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT)
+ : null
+ const hasAcceptedConsent = consent === 'true'
+ const IS_DEV = !IS_PROD && !IS_PREVIEW
+ const blockEvent = IS_DEV || !hasAcceptedConsent
+
+ if (blockEvent) return noop
const { category, action, label, value } = event