Skip to content

Commit

Permalink
static examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Feb 18, 2025
1 parent ec9d576 commit 3062c06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
24 changes: 7 additions & 17 deletions packages/destinations/web/google-ga4/examples/events.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import type { DestinationGoogleGA4 } from '../src';
import type { WalkerOS } from '@elbwalker/types';
import { getEvent } from '@elbwalker/utils';

const customDefault: DestinationGoogleGA4.Custom = {
measurementId: 'G-XXXXXX-1',
};

function useCustom(custom: DestinationGoogleGA4.Custom = customDefault) {
return {
send_to: custom.measurementId,
};
}

export function purchase(custom: DestinationGoogleGA4.Custom = customDefault) {
export function purchase(custom: WalkerOS.AnyObject = {}) {
const event = getEvent('order complete');
const product1 = event.nested[0].data;
const product2 = event.nested[1].data;
Expand All @@ -29,14 +19,13 @@ export function purchase(custom: DestinationGoogleGA4.Custom = customDefault) {
{ item_id: product1.id, item_name: product1.name, quantity: 1 },
{ item_id: product2.id, item_name: product2.name, quantity: 1 },
],
...useCustom(custom),
send_to: 'G-XXXXXX-1',
...custom,
},
];
}

export function add_to_cart(
custom: DestinationGoogleGA4.Custom = customDefault,
) {
export function add_to_cart(custom: WalkerOS.AnyObject = {}) {
const event = getEvent('product add');

return [
Expand All @@ -52,7 +41,8 @@ export function add_to_cart(
quantity: 1,
},
],
...useCustom(custom),
send_to: 'G-XXXXXX-1',
...custom,
},
];
}
10 changes: 4 additions & 6 deletions packages/destinations/web/google-ga4/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,33 +299,31 @@ describe('Destination Google GA4', () => {

test('event add_to_cart', () => {
const event = getEvent('product add');
const custom = { measurementId, include: [] };

const config: DestinationGoogleGA4.Config = {
custom,
custom: { measurementId, include: [] },
init: true,
mapping: mapping.config,
};
elb('walker destination', destination, config);

elb(event);

expect(mockFn).toHaveBeenCalledWith(...events.add_to_cart(custom));
expect(mockFn).toHaveBeenCalledWith(...events.add_to_cart());
});

test('event purchase', () => {
const event = getEvent('order complete');
const custom = { measurementId, include: [] };

const config: DestinationGoogleGA4.Config = {
custom,
custom: { measurementId, include: [] },
init: true,
mapping: mapping.config,
};
elb('walker destination', destination, config);

elb(event);
expect(mockFn).toHaveBeenCalledWith(...events.purchase(custom));
expect(mockFn).toHaveBeenCalledWith(...events.purchase());
});

test('snake case disabled', () => {
Expand Down

0 comments on commit 3062c06

Please sign in to comment.