Skip to content

Commit cbdab5d

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 e9d1004 commit cbdab5d

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
@@ -33,7 +33,7 @@ import {
3333
SESSION_END,
3434
} from '@imtbl/audience-core';
3535
import { DebugLogger } from './debug';
36-
import type { PropsFor } from './events';
36+
import type { AudienceEventName, PropsFor } from './events';
3737
import type { AudienceConfig } from './types';
3838
import {
3939
LIBRARY_NAME, LIBRARY_VERSION, LOG_PREFIX, DEFAULT_CONSENT_SOURCE,
@@ -241,9 +241,11 @@ export class Audience {
241241
/**
242242
* Record a player action like a purchase, sign-up, or game launch.
243243
* Pass the event name and any properties you want to analyse later.
244+
* For the predefined event names (`sign_up`, `purchase`, etc.),
245+
* TypeScript enforces the property shape at the call site.
244246
* No-op when consent is 'none'.
245247
*/
246-
track<E extends string>(
248+
track<E extends AudienceEventName | string & {}>(
247249
event: E,
248250
...args: {} extends PropsFor<E>
249251
? [properties?: PropsFor<E>]

0 commit comments

Comments
 (0)