Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: small edit
Browse files Browse the repository at this point in the history
shrouti1507 committed Feb 26, 2024
1 parent f23127a commit a0a6885
Showing 4 changed files with 39 additions and 55 deletions.
44 changes: 14 additions & 30 deletions src/v0/destinations/google_adwords_offline_conversions/utils.js
Original file line number Diff line number Diff line change
@@ -382,52 +382,36 @@ const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DEN
* b) https://developers.google.com/google-ads/api/reference/rpc/v15/UserData#consent
*/

const populateConsentForGoogleDestinations = (message, conversionName) => {
// Define mappings for different conversion types
const mappings = {
store: {
adUserData: 'ad_user_data',
adPersonalization: 'ad_personalization',
},
click: {
adUserData: 'adUserData',
adPersonalization: 'adPersonalization',
},
call: {
adUserData: 'adUserData',
adPersonalization: 'adPersonalization',
},
};

const currentMapping = mappings[conversionName];
if (!currentMapping) return {};

const populateConsentForGoogleDestinations = (message) => {
const integrationObj = getIntegrationsObj(message, 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS') || {};
const consents = integrationObj.consents || {};

// Define a function to process consent based on type and key
// Define a function to process consent based on type
const processConsent = (consentType) => {
if (!consents[consentType]) return 'UNSPECIFIED';
if (consents[consentType] && GOOGLE_ALLOWED_CONSENT_STATUS.includes(consents[consentType])) {
if (GOOGLE_ALLOWED_CONSENT_STATUS.includes(consents[consentType])) {
return consents[consentType];

Check warning on line 393 in src/v0/destinations/google_adwords_offline_conversions/utils.js

Codecov / codecov/patch

src/v0/destinations/google_adwords_offline_conversions/utils.js#L393

Added line #L393 was not covered by tests
}
if (consents[consentType] && !GOOGLE_ALLOWED_CONSENT_STATUS.includes(consents[consentType])) {
return 'UNKNOWN';
}
return null;
return 'UNKNOWN';

Check warning on line 395 in src/v0/destinations/google_adwords_offline_conversions/utils.js

Codecov / codecov/patch

src/v0/destinations/google_adwords_offline_conversions/utils.js#L395

Added line #L395 was not covered by tests
};

// Construct consentObj based on the current mapping
const consentObj = Object.keys(currentMapping).reduce((obj, consentType) => {
const key = currentMapping[consentType];
// Process each consent type and assign it to the key specified in the mapping
// Common consent fields to process
const consentFields = {
adUserData: 'adUserData',
adPersonalization: 'adPersonalization',
};

// Construct consentObj based on the common consent fields
const consentObj = Object.keys(consentFields).reduce((obj, consentType) => {
const key = consentFields[consentType];
// eslint-disable-next-line no-param-reassign
obj[key] = processConsent(consentType);
return obj;
}, {});

return consentObj;
};

module.exports = {
validateDestinationConfig,
generateItemListFromProducts,
Original file line number Diff line number Diff line change
@@ -276,16 +276,16 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
});

describe('populateConsentForGoogleDestinations', () => {
// Returns an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when no consents are provided
// Returns an object with adUserData and adPersonalization properties set to UNSPECIFIED when no consents are provided
it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS : store sales conversion without any mention in integrations object', () => {
const message = {};
const conversionType = 'store';

const result = populateConsentForGoogleDestinations(message, conversionType);

expect(result).toEqual({
ad_user_data: 'UNSPECIFIED',
ad_personalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
});
});

@@ -306,12 +306,12 @@ describe('populateConsentForGoogleDestinations', () => {
const result = populateConsentForGoogleDestinations(message, conversionType);

expect(result).toEqual({
ad_personalization: 'DENIED',
ad_user_data: 'GRANTED',
adPersonalization: 'DENIED',
adUserData: 'GRANTED',
});
});

// Returns an object with ad_user_data and ad_personalization properties set to the provided consents when they are valid and present in the message properties
// Returns an object with adUserData and adPersonalization properties set to the provided consents when they are valid and present in the message properties
it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS: click conversion with integration object of allowed types', () => {
const message = {
integrations: {
@@ -333,7 +333,7 @@ describe('populateConsentForGoogleDestinations', () => {
});
});

// Returns an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when the provided consents are not valid or not present in the message properties
// Returns an object with adUserData and adPersonalization properties set to UNSPECIFIED when the provided consents are not valid or not present in the message properties
it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS : click conversion with invalid consent value', () => {
const message = {
integrations: {
Original file line number Diff line number Diff line change
@@ -4126,8 +4126,8 @@ export const data = [
operations: {
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: {
@@ -4462,8 +4462,8 @@ export const data = [
operations: {
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: {
@@ -4661,8 +4661,8 @@ export const data = [
operations: {
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: {
@@ -4863,8 +4863,8 @@ export const data = [
operations: {
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: {
@@ -5027,8 +5027,8 @@ export const data = [
operations: {
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: {
@@ -5187,8 +5187,8 @@ export const data = [
operations: {
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: {
@@ -5345,8 +5345,8 @@ export const data = [
operations: {
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: {
Original file line number Diff line number Diff line change
@@ -512,8 +512,8 @@ export const data = [
{
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: { store_code: 'store code' },
@@ -533,8 +533,8 @@ export const data = [
{
create: {
consent: {
ad_personalization: 'UNSPECIFIED',
ad_user_data: 'UNSPECIFIED',
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
transaction_attribute: {
store_attribute: { store_code: 'store code2' },

0 comments on commit a0a6885

Please sign in to comment.