From 396166187adcbcf5f7c58e80f5c304bb9ca5fe8a Mon Sep 17 00:00:00 2001 From: harsh-joshi99 <129737395+harsh-joshi99@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:04:27 +0530 Subject: [PATCH] Add Unique ID and Key Tracking in SFMC Events (#2631) --- .../contactDataExtension/index.ts | 18 +++++++++++++++++- .../dataExtension/index.ts | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/destination-actions/src/destinations/salesforce-marketing-cloud/contactDataExtension/index.ts b/packages/destination-actions/src/destinations/salesforce-marketing-cloud/contactDataExtension/index.ts index d2b965ddf2..fc6e0f2c04 100644 --- a/packages/destination-actions/src/destinations/salesforce-marketing-cloud/contactDataExtension/index.ts +++ b/packages/destination-actions/src/destinations/salesforce-marketing-cloud/contactDataExtension/index.ts @@ -33,7 +33,23 @@ const action: ActionDefinition = { perform: async (request, { settings, payload }) => { return upsertRows(request, settings.subdomain, [payload]) }, - performBatch: async (request, { settings, payload }) => { + performBatch: async (request, { settings, payload, statsContext, features }) => { + if (features && features['enable-sfmc-id-key-stats']) { + const statsClient = statsContext?.statsClient + const tags = statsContext?.tags + const setKey = new Set() + const setId = new Set() + payload.forEach((profile) => { + if (profile.id != undefined && profile.id != null) { + setId.add(profile.id) + } + if (profile.key != undefined && profile.key != null) { + setKey.add(profile.key) + } + }) + statsClient?.histogram(`sfmc_id`, setId.size, tags) + statsClient?.histogram(`sfmc_key`, setKey.size, tags) + } return upsertRows(request, settings.subdomain, payload) } } diff --git a/packages/destination-actions/src/destinations/salesforce-marketing-cloud/dataExtension/index.ts b/packages/destination-actions/src/destinations/salesforce-marketing-cloud/dataExtension/index.ts index 37128dfbce..0974b77c12 100644 --- a/packages/destination-actions/src/destinations/salesforce-marketing-cloud/dataExtension/index.ts +++ b/packages/destination-actions/src/destinations/salesforce-marketing-cloud/dataExtension/index.ts @@ -18,7 +18,23 @@ const action: ActionDefinition = { perform: async (request, { settings, payload }) => { return upsertRows(request, settings.subdomain, [payload]) }, - performBatch: async (request, { settings, payload }) => { + performBatch: async (request, { settings, payload, statsContext, features }) => { + if (features && features['enable-sfmc-id-key-stats']) { + const statsClient = statsContext?.statsClient + const tags = statsContext?.tags + const setKey = new Set() + const setId = new Set() + payload.forEach((profile) => { + if (profile.id != undefined && profile.id != null) { + setId.add(profile.id) + } + if (profile.key != undefined && profile.key != null) { + setKey.add(profile.key) + } + }) + statsClient?.histogram(`sfmc_id`, setId.size, tags) + statsClient?.histogram(`sfmc_key`, setKey.size, tags) + } return upsertRows(request, settings.subdomain, payload) } }