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 b1ce9a2 commit 9af0a6a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/destinations/web/google-ads/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ describe('destination Google Ads', () => {

w.gtag = mockFn;

Walkerjs({ pageview: false, session: false });
elb('walker run');
Walkerjs({ pageview: false, run: true, session: false });
});

afterEach(() => {});
Expand Down Expand Up @@ -107,6 +106,21 @@ describe('destination Google Ads', () => {
});
});

test('dataLayer source', () => {
elb('walker destination', destination);
destination.config.mapping = {
entity: { action: { custom: { label } } },
};
elb(event);
jest.resetAllMocks();

elb({ event, source: { type: 'dataLayer' } });
expect(mockFn).toHaveBeenCalledTimes(0);

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

test('push with value', () => {
elb('walker destination', destination);
destination.config.mapping = {
Expand Down
3 changes: 3 additions & 0 deletions packages/destinations/web/google-ads/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const destinationGoogleAds: Destination = {
},

push(event, config, mapping = {}): void {
// Do not process events from dataLayer source
if (event.source?.type === 'dataLayer') return;

const { custom = {}, fn } = config;
const customMapping = mapping.custom;

Expand Down
12 changes: 12 additions & 0 deletions packages/destinations/web/google-ga4/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ describe('Destination Google GA4', () => {
});
});

test('dataLayer source', () => {
elb('walker destination', destination);
elb(event);
jest.resetAllMocks();

elb(getEvent('entity action', { source: { type: 'dataLayer' } }));
expect(mockFn).toHaveBeenCalledTimes(0);

elb(getEvent('entity action', { source: { type: 'web' } }));
expect(mockFn).toHaveBeenCalledTimes(1);
});

test('settings', () => {
elb('walker destination', destination, {
custom: {
Expand Down
3 changes: 3 additions & 0 deletions packages/destinations/web/google-ga4/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const destinationGoogleGA4: Destination = {
},

push(event, config, mapping = {}, options = {}) {
// Do not process events from dataLayer source
if (event.source?.type === 'dataLayer') return;

const { custom, fn } = config;
const customEvent = mapping.custom || {};
if (!custom) return;
Expand Down
12 changes: 12 additions & 0 deletions packages/destinations/web/google-gtm/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ describe('destination google-tag-manager', () => {
expect(mockDataLayer).toHaveBeenLastCalledWith(event);
});

test('dataLayer source', () => {
elb('walker destination', destination);
elb(event);
jest.resetAllMocks();

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

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

test('push mapping data', () => {
elb('walker destination', destination, {
mapping: {
Expand Down
3 changes: 3 additions & 0 deletions packages/destinations/web/google-gtm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const destinationGoogleGTM: Destination = {
},

push(event, config, mapping, options = {}) {
// Do not process events from dataLayer source
if (event.source?.type === 'dataLayer') return;

const func = config.fn || (window.dataLayer as unknown[]).push;
func(options.data ?? event);
},
Expand Down

0 comments on commit 9af0a6a

Please sign in to comment.