mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem
The ad click ids we send to PostHog for first-touch attribution have no
direct tests. A typo in a param name (say `getParam('opref')`) would
silently drop that click id and CI would stay green. Also, nothing in CI
ran `packages/common` tests at all, apart from `sentry.test.ts`.
GROWTH-1326.
## Solution
- First-touch click ids are now one exported list,
`FIRST_TOUCH_CLICK_ID_KEYS`, instead of 11 hand-written `getParam`
lines. Same ids, same output.
- New `telemetry.test.ts` checks that list equals `CLICK_ID_KEYS` plus
`bfcid`, and that every id in it comes back from
`getFirstTouchAttributionProps`.
- `first-referrer-cookie.test.ts` checks `buildFirstReferrerData`
extracts every `CLICK_ID_KEYS` entry, and that `bfcid` stays out of that
pre-consent list.
- Added a `test` script to `packages/common` and a `pnpm --filter common
test` step to `library-tests.yml`, which already triggers on
`packages/common/**`.
## Review instructions
1. Check the Library checks job runs the common tests (13 files).
2. Add a made-up id to `FIRST_TOUCH_CLICK_ID_KEYS` only, then run `pnpm
--filter common test`. It fails.
## Checklist
Check all before review:
- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { CLICK_ID_KEYS } from './first-referrer-cookie'
|
|
import { FIRST_TOUCH_CLICK_ID_KEYS, getFirstTouchAttributionProps } from './page-telemetry'
|
|
import type { SharedTelemetryData } from './telemetry-first-touch-store'
|
|
|
|
const makeTelemetryData = (pageUrl: string) =>
|
|
({
|
|
page_url: pageUrl,
|
|
pathname: new URL(pageUrl).pathname,
|
|
page_title: 'Test',
|
|
session_id: 'test-session',
|
|
ph: { referrer: 'https://google.com' },
|
|
}) as SharedTelemetryData
|
|
|
|
describe('getFirstTouchAttributionProps', () => {
|
|
it('sends the cookie click ids plus bfcid', () => {
|
|
expect([...FIRST_TOUCH_CLICK_ID_KEYS].sort()).toEqual([...CLICK_ID_KEYS, 'bfcid'].sort())
|
|
})
|
|
|
|
it('sends every click id, and only the expected ones', () => {
|
|
const url = new URL('https://supabase.com/dashboard')
|
|
for (const key of FIRST_TOUCH_CLICK_ID_KEYS) url.searchParams.set(key, `${key}-value`)
|
|
url.searchParams.set('not_a_click_id', 'ignored')
|
|
|
|
const props = getFirstTouchAttributionProps(makeTelemetryData(url.href))
|
|
const clickIdProps = Object.fromEntries(
|
|
Object.entries(props).filter(([key]) => !key.startsWith('first_touch_'))
|
|
)
|
|
|
|
expect(clickIdProps).toEqual(
|
|
Object.fromEntries(FIRST_TOUCH_CLICK_ID_KEYS.map((key) => [key, `${key}-value`]))
|
|
)
|
|
})
|
|
|
|
it('drops click ids with an empty value', () => {
|
|
const props = getFirstTouchAttributionProps(
|
|
makeTelemetryData('https://supabase.com/dashboard?gclid=&fbclid=abc')
|
|
)
|
|
|
|
expect(props).not.toHaveProperty('gclid')
|
|
expect(props).toHaveProperty('fbclid', 'abc')
|
|
})
|
|
})
|