Files
supabase/apps/studio/lib/posthog.ts
Pamela Chia 0208c0b242 feat(studio): send the platform marker on flag tracking calls (#53165)
I changed Studio's feature-flag tracking call to send `platform:
'studio'`, so `$feature_flag_called` events captured by the management
API carry the same app marker as Studio's other events (#53078). I held
this step back until the API's strict flag-track body schema accepted
the field in production, which it has since 2026-11-09.

**Note:** I regenerated `packages/api-types` with a full `codegen:prod`
run, so it also includes other recent production API additions. The
`verify-production-api-types` check diffs every type file against
production, so a single-type update would fail it.

## To test

Accept the cookie banner first: flag tracking only fires after consent.

Tested on the PR preview:
- [x] Sign in to the studio-staging preview, open any project page, and
find the `POST /platform/telemetry/feature-flags/track` request in
DevTools: expect the body to include `"platform":"studio"` and a 2xx
response (a 400 means the field was rejected). Observed
`{"feature_flag_name":"proBenefitWording","feature_flag_value":"variant-a","platform":"studio"}`
with a 201, and every `/platform/telemetry/feature-flags` GET returned
200.

## Linear
- fixes GROWTH-1461
2026-11-10 01:13:50 +09:00

20 lines
622 B
TypeScript

import { components } from 'api-types'
import { hasConsented } from 'common'
import { IS_PLATFORM } from './constants'
import { handleError, post } from '@/data/fetchers'
type TrackFeatureFlagVariables = components['schemas']['TelemetryFeatureFlagBody']
export async function trackFeatureFlag(body: TrackFeatureFlagVariables) {
const consent = hasConsented()
if (!consent || !IS_PLATFORM) return undefined
const { data, error } = await post(`/platform/telemetry/feature-flags/track`, {
body: { ...body, platform: 'studio' },
})
if (error) handleError(error, { reportImmediately: true })
return data
}