Skip to content

Commit

Permalink
feat: garl consent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Feb 28, 2024
1 parent 2761786 commit 64b4645
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const processEvent = async (metadata, message, destination) => {
}

Object.values(createdPayload).forEach((data) => {
const consentObj = populateConsentForGoogleDestinations(message.properties);
const consentObj = populateConsentForGoogleDestinations(destination.Config);
response.push(responseBuilder(metadata, data, destination, message, consentObj));
});
return response;
Expand Down
28 changes: 17 additions & 11 deletions src/v0/util/googleUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DEN
* ref : https://developers.google.com/google-ads/api/rest/reference/rest/v15/Consent
*/

const populateConsentForGoogleDestinations = (properties) => {
const populateConsentForGoogleDestinations = (config) => {
const consent = {};

if (
properties?.userDataConsent &&
GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.userDataConsent)
) {
consent.adUserData = properties.userDataConsent;
if (config?.userDataConsent) {
if (GOOGLE_ALLOWED_CONSENT_STATUS.includes(config.userDataConsent)) {
consent.adUserData = config.userDataConsent;
} else {
consent.adUserData = 'UNKNOWN';
}
} else {
consent.adUserData = 'UNSPECIFIED';
}

if (
properties?.personalizationConsent &&
GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.personalizationConsent)
) {
consent.adPersonalization = properties.personalizationConsent;
if (config?.personalizationConsent) {
if (GOOGLE_ALLOWED_CONSENT_STATUS.includes(config.personalizationConsent)) {
consent.adPersonalization = config.personalizationConsent;
} else {
consent.adPersonalization = 'UNKNOWN';
}
} else {
consent.adPersonalization = 'UNSPECIFIED';
}
return consent;
};
Expand Down
48 changes: 28 additions & 20 deletions src/v0/util/googleUtils/index.test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
const { populateConsentForGoogleDestinations } = require('./index');

describe('unit test for populateConsentForGoogleDestinations', () => {
// Returns an empty object when no properties are provided.
it('should return an empty object when no properties are provided', () => {
it('should return an UNSPECIFIED object when no properties are provided', () => {
const result = populateConsentForGoogleDestinations({});
expect(result).toEqual({});
expect(result).toEqual({
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
});
});

// Sets adUserData property of consent object when userDataConsent property is provided and its value is one of the allowed consent statuses.
it('should set adUserData property of consent object when userDataConsent property is provided and its value is one of the allowed consent statuses', () => {
const properties = { userDataConsent: 'GRANTED' };
const result = populateConsentForGoogleDestinations(properties);
expect(result).toEqual({ adUserData: 'GRANTED' });
expect(result).toEqual({ adUserData: 'GRANTED', adPersonalization: 'UNSPECIFIED' });
});

// Sets adPersonalization property of consent object when personalizationConsent property is provided and its value is one of the allowed consent statuses.
it('should set adPersonalization property of consent object when personalizationConsent property is provided and its value is one of the allowed consent statuses', () => {
const properties = { personalizationConsent: 'DENIED' };
const result = populateConsentForGoogleDestinations(properties);
expect(result).toEqual({ adPersonalization: 'DENIED' });
expect(result).toEqual({ adPersonalization: 'DENIED', adUserData: 'UNSPECIFIED' });
});

// Returns an empty object when properties parameter is not provided.
it('should return an empty object when properties parameter is not provided', () => {
it('should return an UNSPECIFIED object when properties parameter is not provided', () => {
const result = populateConsentForGoogleDestinations();
expect(result).toEqual({});
expect(result).toEqual({
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
});
});

// Returns an empty object when properties parameter is null.
it('should return an empty object when properties parameter is null', () => {
it('should return an UNSPECIFIED object when properties parameter is null', () => {
const result = populateConsentForGoogleDestinations(null);
expect(result).toEqual({});
expect(result).toEqual({
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
});
});

// Returns an empty object when properties parameter is an empty object.
it('should return an empty object when properties parameter is an empty object', () => {
it('should return an UNSPECIFIED object when properties parameter is an UNSPECIFIED object', () => {
const result = populateConsentForGoogleDestinations({});
expect(result).toEqual({});
expect(result).toEqual({
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
});
});

// Returns an empty object when properties parameter is an empty object.
it('should return an empty object when properties parameter contains adUserData and adPersonalization with non-allowed values', () => {
it('should return UNKNOWN when properties parameter contains adUserData and adPersonalization with non-allowed values', () => {
const result = populateConsentForGoogleDestinations({
adUserData: 'RANDOM',
userDataConsent: 'RANDOM',
personalizationConsent: 'RANDOM',
});
expect(result).toEqual({});
expect(result).toEqual({
adPersonalization: 'UNKNOWN',
adUserData: 'UNKNOWN',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const data = [
destination: 'google_adwords_remarketing_lists',
listId: '709078448',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -101,7 +101,7 @@ export const data = [
listId: '709078448',
customerId: '7693729833',
destination: 'google_adwords_remarketing_lists',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -200,7 +200,7 @@ export const data = [
listId: '709078448',
customerId: '7693729833',
destination: 'google_adwords_remarketing_lists',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export const networkCallsData = [
data: {
job: {
type: 'CUSTOMER_MATCH_USER_LIST',
customerMatchUserListMetadata: { userList: 'customers/7693729833/userLists/709078448' },
customerMatchUserListMetadata: {
userList: 'customers/7693729833/userLists/709078448',
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
},
},
headers: {
Expand Down Expand Up @@ -86,7 +89,10 @@ export const networkCallsData = [
data: {
job: {
type: 'CUSTOMER_MATCH_USER_LIST',
customerMatchUserListMetadata: { userList: 'customers/7693729833/userLists/709078448' },
customerMatchUserListMetadata: {
userList: 'customers/7693729833/userLists/709078448',
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
},
},
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -213,7 +213,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -332,7 +332,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -1434,7 +1434,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -2829,7 +2829,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -2909,7 +2909,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -4122,7 +4122,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -5422,7 +5422,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -6799,7 +6799,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -8109,7 +8109,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -9409,7 +9409,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -10804,7 +10804,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -10884,7 +10884,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -11059,7 +11059,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -11137,7 +11137,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -11281,7 +11281,7 @@ export const data = [
params: {
listId: 'list111',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -11488,7 +11488,7 @@ export const data = [
params: {
listId: 'aud1234',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -11627,7 +11627,7 @@ export const data = [
params: {
listId: '830441345',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -11765,7 +11765,7 @@ export const data = [
params: {
listId: '830441345',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNSPECIFIED', adUserData: 'UNSPECIFIED' },
},
body: {
JSON: {
Expand Down Expand Up @@ -11836,6 +11836,8 @@ export const data = [
userSchema: ['email', 'phone', 'addressInfo'],
isHashRequired: true,
typeOfList: 'General',
userDataConsent: 'UNSPECIFIED',
personalizationConsent: 'GRANTED',
},
},
message: {
Expand All @@ -11860,8 +11862,6 @@ export const data = [
event: 'Add_Audience',
messageId: 'bd2d67ca-0c9a-4d3b-a2f8-35a3c3f75ba7',
properties: {
userDataConsent: 'UNSPECIFIED',
personalizationConsent: 'GRANTED',
listData: {
add: [
{
Expand Down Expand Up @@ -11979,6 +11979,8 @@ export const data = [
userSchema: ['email', 'phone', 'addressInfo'],
isHashRequired: true,
typeOfList: 'General',
userDataConsent: 'RANDOM',
personalizationConsent: 'RANDOM',
},
},
message: {
Expand All @@ -12003,8 +12005,6 @@ export const data = [
event: 'Add_Audience',
messageId: 'bd2d67ca-0c9a-4d3b-a2f8-35a3c3f75ba7',
properties: {
userDataConsent: 'RANDOM',
personalizationConsent: 'RANDOM',
listData: {
add: [
{
Expand Down Expand Up @@ -12048,7 +12048,7 @@ export const data = [
params: {
listId: '830441345',
customerId: '7693729833',
consent: {},
consent: { adPersonalization: 'UNKNOWN', adUserData: 'UNKNOWN' },
},
body: {
JSON: {
Expand Down
Loading

0 comments on commit 64b4645

Please sign in to comment.