Skip to content

Commit

Permalink
fix: remove redundant ids and userIdentifier when gbraid or wbraid ar…
Browse files Browse the repository at this point in the history
…e there
  • Loading branch information
ItsSudip committed Dec 2, 2024
1 parent ed9fe55 commit 019da3a
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
getClickConversionPayloadAndEndpoint,
getConsentsDataFromIntegrationObj,
getCallConversionPayload,
updateConversion,
} = require('./utils');
const helper = require('./helper');

Expand Down Expand Up @@ -48,6 +49,9 @@ const getConversions = (message, metadata, { Config }, event, conversionType) =>
filteredCustomerId,
eventLevelConsentsData,
);
convertedPayload.payload.conversions[0] = updateConversion(
convertedPayload.payload.conversions[0],
);
payload = convertedPayload.payload;
endpoint = convertedPayload.endpoint;
} else if (conversionType === 'store') {
Expand Down
30 changes: 27 additions & 3 deletions src/v0/destinations/google_adwords_offline_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,18 @@ const getClickConversionPayloadAndEndpoint = (
// userIdentifierSource
// if userIdentifierSource doesn't exist in properties
// then it is taken from the webapp config
const { gbraid, wbraid, gclid } = payload.conversions[0];
if (!properties.userIdentifierSource && UserIdentifierSource !== 'none') {
set(payload, 'conversions[0].userIdentifiers[0].userIdentifierSource', UserIdentifierSource);

// one of email or phone must be provided
if (!email && !phone) {
// one of email or phone must be provided when none of gclid, wbraid and gbraid provided
if (!email && !phone && !(gclid || wbraid || gbraid)) {
throw new InstrumentationError(`Either of email or phone is required for user identifier`);
}
}
// we are deleting userIdentifiers if any one of gclid, wbraid and gbraid is there but email or phone is not present
if ((gclid || wbraid || gbraid) && !email && !phone) {
delete payload.conversions[0].userIdentifiers;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L369 was not covered by tests
}
// either of email or phone should be passed
// defaultUserIdentifier depends on the webapp configuration
// Ref - https://developers.google.com/google-ads/api/rest/reference/rest/v11/customers/uploadClickConversions#ClickConversion
Expand Down Expand Up @@ -411,6 +415,25 @@ const getConsentsDataFromIntegrationObj = (message) => {
return integrationObj?.consents || {};
};

/**
* remove redundant ids
* @param {*} conversionCopy
*/
const updateConversion = (conversion) => {
const conversionCopy = cloneDeep(conversion);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L423 was not covered by tests
if (conversionCopy.gclid) {
delete conversionCopy.wbraid;
delete conversionCopy.gbraid;

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

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/google_adwords_offline_conversions/utils.js#L425-L426

Added lines #L425 - L426 were not covered by tests
}
if (conversionCopy.wbraid && conversionCopy.gbraid) {
throw new InstrumentationError(`You can't use both wbraid and gbraid.`);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L429 was not covered by tests
}
if (conversionCopy.wbraid || conversionCopy.gbraid) {
delete conversionCopy.userIdentifiers;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L432 was not covered by tests
}
return conversionCopy;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L434 was not covered by tests
};

module.exports = {
validateDestinationConfig,
generateItemListFromProducts,
Expand All @@ -423,4 +446,5 @@ module.exports = {
getExisitingUserIdentifier,
getConsentsDataFromIntegrationObj,
getCallConversionPayload,
updateConversion,
};
Loading

0 comments on commit 019da3a

Please sign in to comment.