Skip to content

Commit

Permalink
fix: adding consent for gaoc initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Dec 18, 2023
1 parent 6b15d2c commit 7e9e872
Show file tree
Hide file tree
Showing 3 changed files with 631 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
defaultBatchRequestConfig,
getSuccessRespEvents,
checkInvalidRtTfEvents,
populateConsent,
} = require('../../util');
const {
CALL_CONVERSION,
Expand Down Expand Up @@ -59,6 +60,10 @@ 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);
}
if (conversionType !== 'store') {
// transform originalTimestamp to conversionDateTime format (yyyy-mm-dd hh:mm:ss+|-hh:mm)
// e.g 2019-10-14T11:15:18.299Z -> 2019-10-14 16:10:29+0530
Expand Down
20 changes: 20 additions & 0 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,25 @@ const parseConfigArray = (arr, key) => {
return arr.map((item) => item[key]);
};

const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED'];

const populateConsent = (properties) => {
const consent = {};

if (properties?.userDataConsent && GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.userDataConsent)) {
consent.adUserData = properties.userDataConsent;
}

if (
properties?.personalizationConsent &&
GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.personalizationConsent)
) {
consent.adPersonalization = properties.personalizationConsent;
}

return consent;
};

// ========================================================================
// EXPORTS
// ========================================================================
Expand Down Expand Up @@ -2218,4 +2237,5 @@ module.exports = {
isNewStatusCodesAccepted,
IsGzipSupported,
parseConfigArray,
populateConsent
};
Loading

0 comments on commit 7e9e872

Please sign in to comment.