Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/analytics-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Clear persisted analytics event queue entries after the delivery callback runs, including when the callback reports an error. ([#8934](https://github.com/MetaMask/core/pull/8934))

## [1.1.0]

### Added
Expand Down
16 changes: 3 additions & 13 deletions packages/analytics-controller/src/AnalyticsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ describe('AnalyticsController', () => {
expect(controller.state.eventQueue).toStrictEqual({});
});

it('keeps queued payloads when the adapter callback receives an error', async () => {
it('clears queued payloads when the adapter callback receives an error', async () => {
const mockAdapter = createMockAdapter();
const { controller } = await setupController({
state: {
Expand All @@ -1317,14 +1317,7 @@ describe('AnalyticsController', () => {
const deliveryOptions = getDeliveryOptions(mockAdapter.track);
deliveryOptions.callback?.(new Error('Segment failed'));

const [messageId] = Object.keys(controller.state.eventQueue ?? {});

expect(controller.state.eventQueue).toHaveProperty(messageId);
expect(controller.state.eventQueue?.[messageId]).toMatchObject({
type: 'track',
eventName: 'test_event',
properties: { prop: 'value' },
});
expect(controller.state.eventQueue).toStrictEqual({});
});

it('keeps queued payloads when the platform adapter throws', async () => {
Expand Down Expand Up @@ -1360,17 +1353,14 @@ describe('AnalyticsController', () => {
let adapterMutationCompleted = false;
jest
.spyOn(mockAdapter, 'track')
.mockImplementation((_eventName, properties, context, options) => {
.mockImplementation((_eventName, properties, context) => {
(
properties as { nested: { adapterNormalized?: boolean } }
).nested.adapterNormalized = true;
(
context as { page: { adapterNormalized?: boolean } }
).page.adapterNormalized = true;
adapterMutationCompleted = true;
(options as AnalyticsDeliveryOptions).callback?.(
new Error('Segment failed'),
);
});
const { controller } = await setupController({
state: {
Expand Down
1 change: 0 additions & 1 deletion packages/analytics-controller/src/AnalyticsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ export class AnalyticsController extends BaseController<
messageId: queuedEvent.messageId,
error,
});
return;
}

this.#removeQueuedEvent(queuedEvent.messageId);
Expand Down
Loading