Skip to content

Commit 3127733

Browse files
committed
feat(launchdarkly-provider): Add tracking API
1 parent 0a87fd6 commit 3127733

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

libs/providers/launchdarkly-client/src/lib/launchdarkly-client-provider.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('LaunchDarklyClientProvider', () => {
2727
waitForInitialization: jest.fn(),
2828
on: jest.fn(),
2929
close: jest.fn(),
30+
track: jest.fn(),
3031
} as unknown as jest.Mocked<LDClient>;
3132

3233
beforeAll(() => {
@@ -376,6 +377,12 @@ describe('LaunchDarklyClientProvider', () => {
376377
});
377378
});
378379

380+
it('calls the client track method properly', async () => {
381+
ldClientMock.track = jest.fn().mockResolvedValue({});
382+
ofClient.track('event-key-123abc', { customProperty: 123 });
383+
expect(ldClientMock.track).toHaveBeenCalledWith('event-key-123abc', { customProperty: 123 });
384+
});
385+
379386
describe('onContextChange', () => {
380387
it('logs information about missing keys', async () => {
381388
ldClientMock.identify = jest.fn().mockResolvedValue({});

libs/providers/launchdarkly-client/src/lib/launchdarkly-client-provider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
OpenFeatureEventEmitter,
1212
ProviderEvents,
1313
ProviderStatus,
14+
TrackingEventDetails,
1415
} from '@openfeature/web-sdk';
1516

1617
import isEmpty from 'lodash.isempty';
@@ -153,6 +154,11 @@ export class LaunchDarklyClientProvider implements Provider {
153154
return wrongTypeResult(defaultValue);
154155
}
155156

157+
track(trackingEventName: string, _context: EvaluationContext, trackingEventDetails: TrackingEventDetails): void {
158+
// The LD Client already has the context form the identify method, so we can omit it here.
159+
this.client.track(trackingEventName, trackingEventDetails);
160+
}
161+
156162
private translateContext(context: EvaluationContext) {
157163
return translateContext(this.logger, context);
158164
}

0 commit comments

Comments
 (0)