Skip to content

Commit

Permalink
ecommerceCartUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Feb 20, 2025
1 parent f402c6b commit 5fd846f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
11 changes: 9 additions & 2 deletions packages/destinations/web/piwikpro/examples/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ export function ecommerceProductDetailView(custom: WalkerOS.AnyObject = {}) {
];
}

export function InitiateCheckout(custom: WalkerOS.AnyObject = {}) {
export function ecommerceCartUpdate(custom: WalkerOS.AnyObject = {}) {
const event = getEvent('cart view');

return [];
return [
[
'ecommerceCartUpdate',
event.nested.filter((item) => item.type === 'product').map(getProduct),
event.data.total,
{ currencyCode: 'EUR' },
],
];
}
27 changes: 23 additions & 4 deletions packages/destinations/web/piwikpro/examples/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,32 @@ export const ecommerceProductDetailView: DestinationPiwikPro.EventConfig = {
},
};

export const InitiateCheckout: DestinationPiwikPro.EventConfig = {
name: 'InitiateCheckout',
data: {},
export const ecommerceCartUpdate: DestinationPiwikPro.EventConfig = {
name: 'ecommerceCartUpdate',
data: {
set: [
{
loop: [
'nested',
{
condition: (entity) =>
isObject(entity) && entity.type === 'product',
map: productMap,
},
],
},
'data.total',
{
map: {
currencyCode: { value: 'EUR' },
},
},
],
},
};

export const config = {
order: { complete: ecommerceOrder },
product: { add: ecommerceAddToCart, view: ecommerceProductDetailView },
cart: { view: InitiateCheckout },
cart: { view: ecommerceCartUpdate },
} satisfies Mapping.Config;
10 changes: 10 additions & 0 deletions packages/destinations/web/piwikpro/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ describe('Destination PiwikPro', () => {
elb(event);
expect(mockFn).toHaveBeenCalledWith(...events.ecommerceProductDetailView());
});

test('event ecommerceCartUpdate', () => {
const event = getEvent('cart view');
elb('walker destination', destination, {
custom,
mapping: mapping.config,
});
elb(event);
expect(mockFn).toHaveBeenCalledWith(...events.ecommerceCartUpdate());
});
});

0 comments on commit 5fd846f

Please sign in to comment.