Skip to content

Commit 3b16d38

Browse files
feat(audience): expose typed event surface and autocomplete (SDK-116)
- Widen track() generic constraint to `AudienceEventName | string & {}`. IntelliSense surfaces the 11 predefined event names at `sdk.track('|`. - Export `AudienceEventName` and `PropsFor<E>` from the package root. - Note predefined-event type enforcement in track()'s JSDoc. Addresses PR #2850 review feedback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e9ebc45 commit 3b16d38

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/audience/sdk/src/events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ interface EventPropsMap {
133133
link_clicked: LinkClickedProperties;
134134
}
135135

136+
export type AudienceEventName = keyof EventPropsMap;
137+
136138
/**
137139
* Event name → property type. Falls back to `Record<string, unknown>` for
138140
* unknown names. Used by `sdk.track()` to type-check property shapes at the

packages/audience/sdk/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ export { AudienceEvents } from './events';
33
export { IdentityType, canTrack, canIdentify } from '@imtbl/audience-core';
44
export type { AudienceConfig } from './types';
55
export type {
6+
AudienceEventName,
67
EmailAcquiredProperties,
78
GameLaunchProperties,
89
GamePageViewedProperties,
910
LinkClickedProperties,
1011
ProgressionProperties,
1112
ProgressionStatus,
13+
PropsFor,
1214
PurchaseProperties,
1315
ResourceFlow,
1416
ResourceProperties,

packages/audience/sdk/src/sdk.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
SESSION_END,
3030
} from '@imtbl/audience-core';
3131
import { DebugLogger } from './debug';
32-
import type { PropsFor } from './events';
32+
import type { AudienceEventName, PropsFor } from './events';
3333
import type { AudienceConfig } from './types';
3434
import {
3535
LIBRARY_NAME, LIBRARY_VERSION, LOG_PREFIX, DEFAULT_CONSENT_SOURCE,
@@ -234,9 +234,11 @@ export class Audience {
234234
/**
235235
* Record a player action like a purchase, sign-up, or game launch.
236236
* Pass the event name and any properties you want to analyse later.
237+
* For the predefined event names (`sign_up`, `purchase`, etc.),
238+
* TypeScript enforces the property shape at the call site.
237239
* No-op when consent is 'none'.
238240
*/
239-
track<E extends string>(
241+
track<E extends AudienceEventName | string & {}>(
240242
event: E,
241243
...args: {} extends PropsFor<E>
242244
? [properties?: PropsFor<E>]

0 commit comments

Comments
 (0)