Skip to content

Commit

Permalink
fix: edit import for garl
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Dec 18, 2023
1 parent a6eac59 commit 3aeb0b2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
defaultBatchRequestConfig,
getSuccessRespEvents,
checkInvalidRtTfEvents,
populateConsent,
populateConsentForGoogleDestinations,
} = require('../../util');
const {
CALL_CONVERSION,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const TYPEOFLIST = Object.freeze({
userID: 'thirdPartyUserId',
mobileDeviceID: 'mobileId',
});
const ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED'];

module.exports = {
BASE_ENDPOINT,
Expand All @@ -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,
};
28 changes: 2 additions & 26 deletions src/v0/destinations/google_adwords_remarketing_lists/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
simpleProcessRouterDest,
getDestinationExternalIDInfoForRetl,
getAccessToken,
populateConsentForGoogleDestinations,
} = require('../../util');

const {
Expand All @@ -22,7 +23,6 @@ const {
attributeMapping,
hashAttributes,
TYPEOFLIST,
ALLOWED_CONSENT_STATUS,
} = require('./config');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { MappedToDestinationKey } = require('../../../constants');
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
17 changes: 14 additions & 3 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -2237,5 +2248,5 @@ module.exports = {
isNewStatusCodesAccepted,
IsGzipSupported,
parseConfigArray,
populateConsent
populateConsentForGoogleDestinations,
};

0 comments on commit 3aeb0b2

Please sign in to comment.