From 3aeb0b2870af61facfa45375574ddbcc6f20933a Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Mon, 18 Dec 2023 16:22:17 +0530 Subject: [PATCH] fix: edit import for garl --- .../transform.js | 8 +++--- .../config.js | 2 -- .../transform.js | 28 ++----------------- src/v0/util/index.js | 17 +++++++++-- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/v0/destinations/google_adwords_offline_conversions/transform.js b/src/v0/destinations/google_adwords_offline_conversions/transform.js index 350f702bc4..511e21e411 100644 --- a/src/v0/destinations/google_adwords_offline_conversions/transform.js +++ b/src/v0/destinations/google_adwords_offline_conversions/transform.js @@ -10,7 +10,7 @@ const { defaultBatchRequestConfig, getSuccessRespEvents, checkInvalidRtTfEvents, - populateConsent, + populateConsentForGoogleDestinations, } = require('../../util'); const { CALL_CONVERSION, @@ -60,9 +60,9 @@ const getConversions = (message, metadata, { Config }, event, conversionType) => endpoint = CALL_CONVERSION.replace(':customerId', filteredCustomerId); } - const consentObject = populateConsent(properties); - if(Object.keys(consentObject).length > 0) { - payload.conversions[0].consent = populateConsent(properties); + const consentObject = populateConsentForGoogleDestinations(properties); + if (Object.keys(consentObject).length > 0) { + payload.conversions[0].consent = populateConsentForGoogleDestinations(properties); } if (conversionType !== 'store') { // transform originalTimestamp to conversionDateTime format (yyyy-mm-dd hh:mm:ss+|-hh:mm) diff --git a/src/v0/destinations/google_adwords_remarketing_lists/config.js b/src/v0/destinations/google_adwords_remarketing_lists/config.js index e55e7d30b6..5bf0d8a299 100644 --- a/src/v0/destinations/google_adwords_remarketing_lists/config.js +++ b/src/v0/destinations/google_adwords_remarketing_lists/config.js @@ -15,7 +15,6 @@ const TYPEOFLIST = Object.freeze({ userID: 'thirdPartyUserId', mobileDeviceID: 'mobileId', }); -const ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED']; module.exports = { BASE_ENDPOINT, @@ -24,5 +23,4 @@ module.exports = { hashAttributes, offlineDataJobsMapping: MAPPING_CONFIG[CONFIG_CATEGORIES.AUDIENCE_LIST.name], addressInfoMapping: MAPPING_CONFIG[CONFIG_CATEGORIES.ADDRESSINFO.name], - ALLOWED_CONSENT_STATUS, }; diff --git a/src/v0/destinations/google_adwords_remarketing_lists/transform.js b/src/v0/destinations/google_adwords_remarketing_lists/transform.js index de82b11156..c93e97245c 100644 --- a/src/v0/destinations/google_adwords_remarketing_lists/transform.js +++ b/src/v0/destinations/google_adwords_remarketing_lists/transform.js @@ -13,6 +13,7 @@ const { simpleProcessRouterDest, getDestinationExternalIDInfoForRetl, getAccessToken, + populateConsentForGoogleDestinations, } = require('../../util'); const { @@ -22,7 +23,6 @@ const { attributeMapping, hashAttributes, TYPEOFLIST, - ALLOWED_CONSENT_STATUS, } = require('./config'); const { JSON_MIME_TYPE } = require('../../util/constant'); const { MappedToDestinationKey } = require('../../../constants'); @@ -196,30 +196,6 @@ const createPayload = (message, destination) => { return outputPayloads; }; -/** - * Populates the consent object based on the provided properties. - * - * @param {object} properties - message.properties containing properties related to consent. - * @returns {object} - An object containing consent information. - * ref : https://developers.google.com/google-ads/api/rest/reference/rest/v15/Consent - */ -const populateConsent = (properties) => { - const consent = {}; - - if (properties?.userDataConsent && ALLOWED_CONSENT_STATUS.includes(properties.userDataConsent)) { - consent.adUserData = properties.userDataConsent; - } - - if ( - properties?.personalizationConsent && - ALLOWED_CONSENT_STATUS.includes(properties.personalizationConsent) - ) { - consent.adPersonalization = properties.personalizationConsent; - } - - return consent; -}; - const processEvent = async (metadata, message, destination) => { const response = []; if (!message.type) { @@ -241,7 +217,7 @@ const processEvent = async (metadata, message, destination) => { } Object.values(createdPayload).forEach((data) => { - const consentObj = populateConsent(message.properties); + const consentObj = populateConsentForGoogleDestinations(message.properties); response.push(responseBuilder(metadata, data, destination, message, consentObj)); }); return response; diff --git a/src/v0/util/index.js b/src/v0/util/index.js index c957192d2b..293c1ed2bd 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -2110,10 +2110,21 @@ const parseConfigArray = (arr, key) => { const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED']; -const populateConsent = (properties) => { +/** + * Populates the consent object based on the provided properties. + * + * @param {object} properties - message.properties containing properties related to consent. + * @returns {object} - An object containing consent information. + * ref : https://developers.google.com/google-ads/api/rest/reference/rest/v15/Consent + */ + +const populateConsentForGoogleDestinations = (properties) => { const consent = {}; - if (properties?.userDataConsent && GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.userDataConsent)) { + if ( + properties?.userDataConsent && + GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.userDataConsent) + ) { consent.adUserData = properties.userDataConsent; } @@ -2237,5 +2248,5 @@ module.exports = { isNewStatusCodesAccepted, IsGzipSupported, parseConfigArray, - populateConsent + populateConsentForGoogleDestinations, };