From ebe3a8395c55265facd3da38ea44af4f5db48d00 Mon Sep 17 00:00:00 2001 From: Nick Santaniello Date: Tue, 9 Apr 2024 13:03:20 -0700 Subject: [PATCH] Restored construct moat data file --- .../src/util/construct-moat-data.ts | 44 +++++++++++++++++++ packages/util/src/index.ts | 1 + 2 files changed, 45 insertions(+) create mode 100644 packages/components/src/util/construct-moat-data.ts diff --git a/packages/components/src/util/construct-moat-data.ts b/packages/components/src/util/construct-moat-data.ts new file mode 100644 index 00000000..fdb7d2bc --- /dev/null +++ b/packages/components/src/util/construct-moat-data.ts @@ -0,0 +1,44 @@ +type MoatData = { + moatClientLevel1: string + moatClientLevel2: string + moatClientLevel3: string + moatClientLevel4: string + moatClientSlicer1: string + moatClientSlicer2: string + zMoatPosition: string + zMoatSession?: string +} + +type Tracker = { + vendor: string + verificationParameters: any +} + +type TData = { + web?: Tracker[] +} + +export const constructMoatData = ({ tdata }: { tdata: TData }): MoatData | undefined => { + const [moatTrackerData] = tdata?.web?.filter((tracker) => tracker.vendor === 'Moat') || [] + if (moatTrackerData?.verificationParameters) { + const { + moatClientLevel1 = '_ADVERTISER_', + moatClientLevel2 = '_CAMPAIGN_', + moatClientLevel3 = '_LINE_ITEM_', + moatClientLevel4 = '_CREATIVE_', + moatClientSlicer1 = '_SITE_', + moatClientSlicer2 = '_PLACEMENT_', + zMoatPosition = '_POSITION_', + } = moatTrackerData.verificationParameters + + return { + moatClientLevel1, + moatClientLevel2, + moatClientLevel3, + moatClientLevel4, + moatClientSlicer1, + moatClientSlicer2, + zMoatPosition, + } + } +} diff --git a/packages/util/src/index.ts b/packages/util/src/index.ts index b786ccfa..20245dc3 100644 --- a/packages/util/src/index.ts +++ b/packages/util/src/index.ts @@ -1,5 +1,6 @@ export { default as bestfit, setRenditionScaleUpMaxPixels } from './bestfit' export * from './collections' +export * from './construct-moat-data' export { default as getClientRect } from './get-client-rect-from-el' export { default as getPingbackId } from './get-pingback-id' export {