diff --git a/packages/destinations/node/meta/src/__tests__/index.test.ts b/packages/destinations/node/meta/src/__tests__/index.test.ts index e826fc7a..7aed13f6 100644 --- a/packages/destinations/node/meta/src/__tests__/index.test.ts +++ b/packages/destinations/node/meta/src/__tests__/index.test.ts @@ -164,6 +164,7 @@ describe('Node Destination Meta', () => { test('Mapping', async () => { event.data.total = 42; const custom: CustomEventConfig = { + currency: { default: 'EUR' }, value: 'data.total', }; @@ -173,6 +174,7 @@ describe('Node Destination Meta', () => { expect(custom_data).toEqual( expect.objectContaining({ + currency: 'EUR', value: 42, }), ); diff --git a/packages/destinations/node/meta/src/push.ts b/packages/destinations/node/meta/src/push.ts index c2353771..d22c725b 100644 --- a/packages/destinations/node/meta/src/push.ts +++ b/packages/destinations/node/meta/src/push.ts @@ -48,7 +48,7 @@ export const mapEvent = ( ): ServerEvent => { mapping; // @TODO const { data, user, source } = event; - const { value } = mapping.custom || {}; + const { currency, value } = mapping.custom || {}; let userData = new UserData(); if (user) { @@ -71,12 +71,17 @@ export const mapEvent = ( } const customData = new CustomData(); + + // Currency + const currencyParams = currency && getMappingValue(event, currency); + if (currencyParams) customData.setCurrency(String(currencyParams)); + + // Value const valueParams = value && getMappingValue(event, value); if (valueParams) customData.setValue(parseFloat(String(valueParams))); // const content = new Content().setId('product123').setQuantity(1); // @TODO // .setContents([content]) - // .setCurrency('usd') // @TODO const timestamp = Math.floor( (event.timestamp || new Date().getTime()) / 1000, diff --git a/packages/destinations/node/meta/src/types/index.ts b/packages/destinations/node/meta/src/types/index.ts index 09dff26d..32e62de7 100644 --- a/packages/destinations/node/meta/src/types/index.ts +++ b/packages/destinations/node/meta/src/types/index.ts @@ -32,5 +32,6 @@ export interface CustomConfig { export interface CustomEventConfig { // Custom destination event mapping properties + currency?: WalkerOS.MappingValue; value?: WalkerOS.MappingValue; } diff --git a/packages/types/src/walkeros.ts b/packages/types/src/walkeros.ts index f8e0fe2b..a23881a5 100644 --- a/packages/types/src/walkeros.ts +++ b/packages/types/src/walkeros.ts @@ -183,7 +183,7 @@ export interface Entity { export type MappingValue = string | MappingValueObject; export interface MappingValueObject { - key: string; + key?: string; default?: PropertyType; // consent?: string | Array; } diff --git a/packages/utils/src/core/mapping.ts b/packages/utils/src/core/mapping.ts index f23cb865..0fce6f74 100644 --- a/packages/utils/src/core/mapping.ts +++ b/packages/utils/src/core/mapping.ts @@ -2,7 +2,7 @@ import type { WalkerOS } from '@elbwalker/types'; import { castToProperty, getByStringDot } from '.'; interface MappingObject { - key: string; + key?: string; defaultValue?: WalkerOS.PropertyType; } @@ -11,14 +11,14 @@ export function getMappingValue( mapping: WalkerOS.MappingValue, ): WalkerOS.Property | undefined { const obj = getMappingObject(mapping); - const value = castToProperty( - getByStringDot(event, obj.key, obj.defaultValue), - ); - return value; + if (obj.key) + return castToProperty(getByStringDot(event, obj.key, obj.defaultValue)); + + return obj.defaultValue; } function getMappingObject(param: WalkerOS.MappingValue): MappingObject { - let key: string; + let key: string | undefined; let defaultValue: WalkerOS.PropertyType | undefined; if (typeof param == 'string') {