diff --git a/src/v0/destinations/google_adwords_offline_conversions/transform.js b/src/v0/destinations/google_adwords_offline_conversions/transform.js index e232a5f7d1..5ae92c57e9 100644 --- a/src/v0/destinations/google_adwords_offline_conversions/transform.js +++ b/src/v0/destinations/google_adwords_offline_conversions/transform.js @@ -10,7 +10,6 @@ const { defaultBatchRequestConfig, getSuccessRespEvents, combineBatchRequestsWithSameJobIds, - getIntegrationsObj, } = require('../../util'); const { CALL_CONVERSION, @@ -23,18 +22,11 @@ const { getStoreConversionPayload, requestBuilder, getClickConversionPayloadAndEndpoint, + getConsentsDataFromIntegrationObj, } = require('./utils'); const { finaliseConsent } = require('../../util/googleUtils'); const helper = require('./helper'); -const getConsentsDataFromIntegrationObj = (message, conversionType) => { - const integrationObj = - conversionType === 'store' - ? {} - : getIntegrationsObj(message, 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS') || {}; - return integrationObj?.consents || {}; -}; - /** * get conversions depending on the type set from dashboard * i.e click conversions or call conversions @@ -52,7 +44,7 @@ const getConversions = (message, metadata, { Config }, event, conversionType) => const { properties, timestamp, originalTimestamp } = message; const filteredCustomerId = removeHyphens(customerId); - const eventLevelConsentsData = getConsentFromIntegrationObj(message, conversionType); + const eventLevelConsentsData = getConsentsDataFromIntegrationObj(message, conversionType); if (conversionType === 'click') { // click conversion @@ -60,16 +52,21 @@ const getConversions = (message, metadata, { Config }, event, conversionType) => message, Config, filteredCustomerId, - userSentConsentValues, + eventLevelConsentsData, ); payload = convertedPayload.payload; endpoint = convertedPayload.endpoint; } else if (conversionType === 'store') { - payload = getStoreConversionPayload(message, Config, filteredCustomerId, userSentConsentValues); + payload = getStoreConversionPayload( + message, + Config, + filteredCustomerId, + eventLevelConsentsData, + ); endpoint = STORE_CONVERSION_CONFIG.replace(':customerId', filteredCustomerId); } else { // call conversions - const consentObject = finaliseConsent(userSentConsentValues, Config, consentFields); + const consentObject = finaliseConsent(eventLevelConsentsData, Config, consentFields); payload = constructPayload(message, trackCallConversionsMapping); endpoint = CALL_CONVERSION.replace(':customerId', filteredCustomerId); payload.conversions[0].consent = consentObject; diff --git a/src/v0/destinations/google_adwords_offline_conversions/utils.js b/src/v0/destinations/google_adwords_offline_conversions/utils.js index 5a3b67cec0..b5a59fefa6 100644 --- a/src/v0/destinations/google_adwords_offline_conversions/utils.js +++ b/src/v0/destinations/google_adwords_offline_conversions/utils.js @@ -17,6 +17,7 @@ const { isDefinedAndNotNull, getAuthErrCategoryFromStCode, getAccessToken, + getIntegrationsObj, } = require('../../util'); const { SEARCH_STREAM, @@ -376,6 +377,14 @@ const getClickConversionPayloadAndEndpoint = ( return { payload, endpoint }; }; +const getConsentsDataFromIntegrationObj = (message, conversionType) => { + const integrationObj = + conversionType === 'store' + ? {} + : getIntegrationsObj(message, 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS') || {}; + return integrationObj?.consents || {}; +}; + module.exports = { validateDestinationConfig, generateItemListFromProducts, @@ -386,4 +395,5 @@ module.exports = { buildAndGetAddress, getClickConversionPayloadAndEndpoint, getExisitingUserIdentifier, + getConsentsDataFromIntegrationObj, }; diff --git a/src/v0/destinations/google_adwords_offline_conversions/utils.test.js b/src/v0/destinations/google_adwords_offline_conversions/utils.test.js index b2c15883d6..f9e545e7f3 100644 --- a/src/v0/destinations/google_adwords_offline_conversions/utils.test.js +++ b/src/v0/destinations/google_adwords_offline_conversions/utils.test.js @@ -2,6 +2,7 @@ const { getClickConversionPayloadAndEndpoint, buildAndGetAddress, getExisitingUserIdentifier, + getConsentsDataFromIntegrationObj, } = require('./utils'); const getTestMessage = () => { @@ -285,3 +286,46 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => { ); }); }); + +describe('getConsentsDataFromIntegrationObj', () => { + it('should return an empty object when conversionType is "store"', () => { + const message = {}; + const conversionType = 'store'; + const result = getConsentsDataFromIntegrationObj(message, conversionType); + expect(result).toEqual({}); + }); + + it('should return an empty object when conversionType is not "store" and getIntegrationsObj returns undefined', () => { + const message = {}; + const conversionType = 'click'; + const result = getConsentsDataFromIntegrationObj(message, conversionType); + expect(result).toEqual({}); + }); + + it('should return an empty object when conversionType is not "store" and getIntegrationsObj returns null', () => { + const message = {}; + const conversionType = 'call'; + const getIntegrationsObj = jest.fn(() => null); + const result = getConsentsDataFromIntegrationObj(message, conversionType); + expect(result).toEqual({}); + }); + + it('should return the consent object when conversion type is call', () => { + const message = { + integrations: { + GOOGLE_ADWORDS_OFFLINE_CONVERSIONS: { + consents: { + adUserData: 'GRANTED', + adPersonalization: 'DENIED', + }, + }, + }, + }; + const conversionType = 'call'; + const result = getConsentsDataFromIntegrationObj(message, conversionType); + expect(result).toEqual({ + adPersonalization: 'DENIED', + adUserData: 'GRANTED', + }); + }); +}); diff --git a/src/v0/util/googleUtils/index.test.js b/src/v0/util/googleUtils/index.test.js index d9d03a9805..a0d75851b1 100644 --- a/src/v0/util/googleUtils/index.test.js +++ b/src/v0/util/googleUtils/index.test.js @@ -1,7 +1,5 @@ const { populateConsentFromConfig, finaliseConsent } = require('./index'); -const destinationAllowedConsentKeys = ['adUserData', 'adPersonalization']; - describe('unit test for populateConsentFromConfig', () => { it('should return an UNSPECIFIED object when no properties are provided', () => { const result = populateConsentFromConfig({});