Skip to content

Commit ace1525

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 703e5b0 commit ace1525

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 } 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
@@ -31,7 +31,7 @@ import {
3131
SESSION_END,
3232
} from '@imtbl/audience-core';
3333
import { DebugLogger } from './debug';
34-
import type { PropsFor } from './events';
34+
import type { AudienceEventName, PropsFor } from './events';
3535
import type { AudienceConfig } from './types';
3636
import {
3737
LIBRARY_NAME, LIBRARY_VERSION, LOG_PREFIX, DEFAULT_CONSENT_SOURCE,
@@ -239,9 +239,11 @@ export class Audience {
239239
/**
240240
* Record a player action like a purchase, sign-up, or game launch.
241241
* Pass the event name and any properties you want to analyse later.
242+
* For the predefined event names (`sign_up`, `purchase`, etc.),
243+
* TypeScript enforces the property shape at the call site.
242244
* No-op when consent is 'none'.
243245
*/
244-
track<E extends string>(
246+
track<E extends AudienceEventName | string & {}>(
245247
event: E,
246248
...args: {} extends PropsFor<E>
247249
? [properties?: PropsFor<E>]

0 commit comments

Comments
 (0)