Skip to content

Commit

Permalink
ignore dataLayer source
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Dec 18, 2024
1 parent 9af0a6a commit 5e9a7b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
22 changes: 11 additions & 11 deletions packages/sources/walkerjs/src/__tests__/destination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,19 +713,19 @@ describe('Destination', () => {
expect(mockPushLatest).toHaveBeenCalledTimes(0);
});

test('loop prevention', () => {
elb('walker run');
destination.type = 'foo';
elb('walker destination', destination);

elb({ event: 'e a' });
elb({ event: 'e a', source: { type: 'another one' } });
expect(mockPush).toHaveBeenCalledTimes(2);
test('dataLayer source', () => {
walkerjs = Walkerjs({
dataLayer: true,
run: true,
session: false,
});
jest.resetAllMocks();

jest.clearAllMocks();
elb({ event: 'e a', source: { type: 'foo' } });
elb({ ...event, source: { type: 'dataLayer' } });
expect(mockDataLayer).toHaveBeenCalledTimes(0);

expect(mockPush).toHaveBeenCalledTimes(0);
elb({ ...event, source: { type: 'web' } });
expect(mockDataLayer).toHaveBeenCalledTimes(1);
});

test('id namings', () => {
Expand Down
7 changes: 3 additions & 4 deletions packages/sources/walkerjs/src/lib/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export function dataLayerDestination() {
};
const destination: DestinationWeb.DestinationInit = {
push: (event, config, mapping, options = {}) => {
// Do not process events from dataLayer source
if (event.source?.type === 'dataLayer') return;

const data = options.data || event;
dataLayerPush(data);
},
Expand Down Expand Up @@ -128,10 +131,6 @@ export function destinationPush(
}
}

// Prevent recursive loops between sources and destinations
if (isDefined(destination.type) && destination.type === event.source.type)
return false;

const options = { data, instance };

return !!tryCatch(() => {
Expand Down

0 comments on commit 5e9a7b7

Please sign in to comment.