Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enhancement and version upgrade of google adwords offline conversion #2946

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getMappingConfig } = require('../../util');

const API_VERSION = 'v14';
const API_VERSION = 'v15';

const BASE_ENDPOINT = `https://googleads.googleapis.com/${API_VERSION}/customers/:customerId`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
getSuccessRespEvents,
checkInvalidRtTfEvents,
} = require('../../util');
const { populateConsentForGoogleDestinations } = require('../../util/googleUtils');
const {
CALL_CONVERSION,
trackCallConversionsMapping,
Expand Down Expand Up @@ -59,6 +60,10 @@ const getConversions = (message, metadata, { Config }, event, conversionType) =>
endpoint = CALL_CONVERSION.replace(':customerId', filteredCustomerId);
}

const consentObject = populateConsentForGoogleDestinations(properties);
if (Object.keys(consentObject).length > 0) {
payload.conversions[0].consent = consentObject;
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('getExisitingUserIdentifier util tests', () => {
describe('getClickConversionPayloadAndEndpoint util tests', () => {
it('getClickConversionPayloadAndEndpoint flow check when default field identifier is present', () => {
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v15/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand All @@ -187,7 +187,7 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
delete fittingPayload.traits.email;
delete fittingPayload.properties.email;
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v15/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
delete fittingPayload.traits.phone;
delete fittingPayload.properties.email;
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v15/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
},
];
let expectedOutput = {
endpoint: 'https://googleads.googleapis.com/v14/customers/9625812972:uploadClickConversions',
endpoint: 'https://googleads.googleapis.com/v15/customers/9625812972:uploadClickConversions',
payload: {
conversions: [
{
Expand Down
30 changes: 30 additions & 0 deletions src/v0/util/googleUtils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED'];

/**
* 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)
) {
consent.adUserData = properties.userDataConsent;
}

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

return consent;
};

module.exports = { populateConsentForGoogleDestinations };
50 changes: 50 additions & 0 deletions src/v0/util/googleUtils/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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', () => {
const result = populateConsentForGoogleDestinations({});
expect(result).toEqual({});
});

// 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' });
});

// 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' });
});

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

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

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

// 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', () => {
const result = populateConsentForGoogleDestinations({
adUserData: 'RANDOM',
personalizationConsent: 'RANDOM',
});
expect(result).toEqual({});
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"https://googleads.googleapis.com/v14/customers/11122233331/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v15/customers/11122233331/offlineUserDataJobs:create": {
"data": {
"resourceName": "customers/111-222-3333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_FOR_ADD_FAILURE"
},
"status": 200
},
"https://googleads.googleapis.com/v14/customers/1112223333/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v15/customers/1112223333/offlineUserDataJobs:create": {
"data": {
"resourceName": "customers/111-222-3333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID"
},
"status": 200
},
"https://googleads.googleapis.com/v14/customers/customerid/offlineUserDataJobs:create": {
"https://googleads.googleapis.com/v15/customers/customerid/offlineUserDataJobs:create": {
"status": 401,
"data": {
"error": {
Expand All @@ -21,11 +21,11 @@
}
}
},
"https://googleads.googleapis.com/v14/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:addOperations": {
"https://googleads.googleapis.com/v15/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:addOperations": {
"status": 200,
"data": {}
},
"https://googleads.googleapis.com/v14/customers/11122233331/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_FOR_ADD_FAILURE:addOperations": {
"https://googleads.googleapis.com/v15/customers/11122233331/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_FOR_ADD_FAILURE:addOperations": {
"status": 400,
"data": {
"error": {
Expand All @@ -34,7 +34,7 @@
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.ads.googleads.v14.errors.GoogleAdsFailure",
"@type": "type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure",
"errors": [
{
"errorCode": {
Expand Down Expand Up @@ -67,13 +67,13 @@
}
}
},
"https://googleads.googleapis.com/v14/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:run": {
"https://googleads.googleapis.com/v15/customers/1112223333/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID:run": {
"status": 200,
"data": {
"name": "customers/111-222-3333/operations/abcd="
}
},
"https://googleads.googleapis.com/v14/customers/customerid/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_ADD_FAILURE:addOperations": {
"https://googleads.googleapis.com/v15/customers/customerid/offlineUserDataJobs/OFFLINE_USER_DATA_JOB_ID_ADD_FAILURE:addOperations": {
"status": 400,
"data": {
"error": {
Expand All @@ -82,7 +82,7 @@
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.ads.googleads.v14.errors.GoogleAdsFailure",
"@type": "type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure",
"errors": [
{
"errorCode": {
Expand Down
Loading
Loading