Skip to content

Commit

Permalink
set mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Dec 17, 2024
1 parent f821cd4 commit 927ab8c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-sheep-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@elbwalker/utils': minor
---

set option for mapping [#483](https://github.com/elbwalker/walkerOS/issues/483)
2 changes: 1 addition & 1 deletion packages/destinations/web/piwikpro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Destinations can be used via node or directly in the browser.

Learn more about the
[destinations](https://www.elbwalker.com/docs/destinations/) in general and read
the detailled
the detailed
[Piwik PRO configuration](https://www.elbwalker.com/docs/destinations/piwikpro#configuration).

```js
Expand Down
28 changes: 15 additions & 13 deletions packages/destinations/web/piwikpro/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,29 @@ describe('Destination PiwikPro', () => {
expect(mockFn).toHaveBeenCalledTimes(0);
});

test.skip('event trackEcommerceOrder', () => {
test('event trackEcommerceOrder', () => {
const order_complete = getEvent('order complete');
elb('walker destination', destination, {
custom,
mapping: {
order: {
complete: {
name: 'trackEcommerceOrder',
data: [
'data.id',
'data.total',
{
fn: (event) => {
const total = Number(event.data?.total ?? 0);
const taxes = Number(event.data?.taxes ?? 0);
const shipping = Number(event.data?.shipping ?? 0);

return total - taxes - shipping;
data: {
set: [
'data.id',
'data.total',
{
fn: (event) => {
const total = Number(event.data?.total ?? 0);
const taxes = Number(event.data?.taxes ?? 0);
const shipping = Number(event.data?.shipping ?? 0);

return total - taxes - shipping;
},
},
},
],
],
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/destinations/web/piwikpro/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Custom, CustomEvent, Destination } from './types';
import { getMappingValue } from '@elbwalker/utils';
import { getMappingValue, isArray } from '@elbwalker/utils';

// Types
export * as DestinationPiwikPro from './types';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const destinationPiwikPro: Destination = {

const customMapping: CustomEvent = mapping.custom || {};

const parameters = Array.isArray(data) ? data : [data];
const parameters = isArray(data) ? data : [data];

func([event.event, ...parameters]);

Expand Down

0 comments on commit 927ab8c

Please sign in to comment.