Skip to content

Commit

Permalink
fix: use trim before hashing for google adwords offline conversions a…
Browse files Browse the repository at this point in the history
…nd enhanced conversions, impact, yahoo DSP, fb and fb conversions
  • Loading branch information
anantjain45823 committed May 21, 2024
1 parent 8955511 commit 3a84b8d
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/v0/destinations/facebook_offline_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const preparePayload = (facebookOfflineConversionsPayload, destination) => {
const keys = Object.keys(facebookOfflineConversionsPayload);
keys.forEach((key) => {
if (isHashRequired && HASHING_REQUIRED_KEYS.includes(key)) {
payload[key] = sha256(facebookOfflineConversionsPayload[key]);
payload[key] = sha256(facebookOfflineConversionsPayload[key].trim());
} else {
payload[key] = facebookOfflineConversionsPayload[key];
}
Expand All @@ -407,8 +407,8 @@ const preparePayload = (facebookOfflineConversionsPayload, destination) => {
? facebookOfflineConversionsPayload.name.split(' ')
: null;
if (split !== null && Array.isArray(split) && split.length === 2) {
payload.fn = isHashRequired ? sha256(split[0]) : split[0];
payload.ln = isHashRequired ? sha256(split[1]) : split[1];
payload.fn = isHashRequired ? sha256(split[0].trim()) : split[0];
payload.ln = isHashRequired ? sha256(split[1].trim()) : split[1];
}
delete payload.name;
}
Expand Down
6 changes: 3 additions & 3 deletions src/v0/destinations/fb/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function sanityCheckPayloadForTypesAndModifications(updatedEvent) {
clonedUpdatedEvent[prop] !== ''
) {
isUDSet = true;
clonedUpdatedEvent[prop] = sha256(clonedUpdatedEvent[prop].toLowerCase());
clonedUpdatedEvent[prop] = sha256(clonedUpdatedEvent[prop].trim().toLowerCase());
}
break;
case 'ud[zp]':
Expand All @@ -113,7 +113,7 @@ function sanityCheckPayloadForTypesAndModifications(updatedEvent) {
} else {
isUDSet = true;
clonedUpdatedEvent[prop] = sha256(
clonedUpdatedEvent[prop].toLowerCase() === 'female' ? 'f' : 'm',
clonedUpdatedEvent[prop].trim().toLowerCase() === 'female' ? 'f' : 'm',
);
}
}
Expand All @@ -128,7 +128,7 @@ function sanityCheckPayloadForTypesAndModifications(updatedEvent) {
if (clonedUpdatedEvent[prop] && clonedUpdatedEvent[prop] !== '') {
isUDSet = true;
clonedUpdatedEvent[prop] = sha256(
clonedUpdatedEvent[prop].toLowerCase().replace(/ /g, ''),
clonedUpdatedEvent[prop].trim().toLowerCase().replace(/ /g, ''),
);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"sourceFromGenericMap": true,
"required": false,
"metadata": {
"type": "hashToSha256"
"type": ["trim", "hashToSha256"]
}
},
{
Expand All @@ -64,7 +64,7 @@
"sourceFromGenericMap": true,
"required": false,
"metadata": {
"type": "hashToSha256"
"type": ["trim", "hashToSha256"]
}
},
{
Expand All @@ -73,7 +73,7 @@
"sourceFromGenericMap": true,
"required": false,
"metadata": {
"type": "hashToSha256"
"type": ["trim", "hashToSha256"]
}
},
{
Expand All @@ -82,7 +82,7 @@
"sourceFromGenericMap": true,
"required": false,
"metadata": {
"type": "hashToSha256"
"type": ["trim", "hashToSha256"]
}
},
{
Expand Down Expand Up @@ -127,7 +127,7 @@
"sourceKeys": ["context.traits.streetAddress", "context.traits.address"],
"required": false,
"metadata": {
"type": "hashToSha256"
"type": ["trim", "hashToSha256"]
}
}
]
18 changes: 11 additions & 7 deletions src/v0/destinations/google_adwords_offline_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,17 @@ const buildAndGetAddress = (message, hashUserIdentifier) => {
const address = constructPayload(message, trackAddStoreAddressConversionsMapping);
if (address.hashed_last_name) {
address.hashed_last_name = hashUserIdentifier
? sha256(address.hashed_last_name).toString()
? sha256(address.hashed_last_name.trim()).toString()
: address.hashed_last_name;
}
if (address.hashed_first_name) {
address.hashed_first_name = hashUserIdentifier
? sha256(address.hashed_first_name).toString()
? sha256(address.hashed_first_name.trim()).toString()
: address.hashed_first_name;
}
if (address.hashed_street_address) {
address.hashed_street_address = hashUserIdentifier
? sha256(address.hashed_street_address).toString()
? sha256(address.hashed_street_address.trim()).toString()
: address.hashed_street_address;
}
return Object.keys(address).length > 0 ? address : null;
Expand Down Expand Up @@ -269,8 +269,10 @@ const getAddConversionPayload = (message, Config) => {
const phone = getFieldValueFromMessage(message, 'phone');

const userIdentifierInfo = {
email: hashUserIdentifier && isDefinedAndNotNull(email) ? sha256(email).toString() : email,
phone: hashUserIdentifier && isDefinedAndNotNull(phone) ? sha256(phone).toString() : phone,
email:
hashUserIdentifier && isDefinedAndNotNull(email) ? sha256(email.trim()).toString() : email,
phone:
hashUserIdentifier && isDefinedAndNotNull(phone) ? sha256(phone.trim()).toString() : phone,
address: buildAndGetAddress(message, hashUserIdentifier),
};

Expand Down Expand Up @@ -363,8 +365,10 @@ const getClickConversionPayloadAndEndpoint = (
// Ref - https://developers.google.com/google-ads/api/rest/reference/rest/v11/customers/uploadClickConversions#ClickConversion

const userIdentifierInfo = {
email: hashUserIdentifier && isDefinedAndNotNull(email) ? sha256(email).toString() : email,
phone: hashUserIdentifier && isDefinedAndNotNull(phone) ? sha256(phone).toString() : phone,
email:
hashUserIdentifier && isDefinedAndNotNull(email) ? sha256(email.trim()).toString() : email,
phone:
hashUserIdentifier && isDefinedAndNotNull(phone) ? sha256(phone.trim()).toString() : phone,
};

const keyName = getExisitingUserIdentifier(userIdentifierInfo, defaultUserIdentifier);
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/impact/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const buildPageLoadPayload = (message, campaignId, impactAppId, enableEmailHashi
let payload = constructPayload(message, MAPPING_CONFIG[CONFIG_CATEGORIES.PAGELOAD.name]);
if (isDefinedAndNotNull(payload.CustomerEmail)) {
payload.CustomerEmail = enableEmailHashing
? sha1(payload?.CustomerEmail)
? sha1(payload?.CustomerEmail.trim())
: payload?.CustomerEmail;
}
payload.CampaignId = campaignId;
Expand Down Expand Up @@ -155,7 +155,7 @@ const processTrackEvent = (message, Config) => {
payload.ImpactAppId = impactAppId;
if (isDefinedAndNotNull(payload.CustomerEmail)) {
payload.CustomerEmail = enableEmailHashing
? sha1(payload?.CustomerEmail)
? sha1(payload?.CustomerEmail.trim())
: payload?.CustomerEmail;
}

Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/yahoo_dsp/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const populateIdentifiers = (audienceList, Config) => {
}
// here, hashing the data if is not hashed and pushing in the seedList array.
if (hashRequired) {
seedList.push(sha256(userTraits[audienceAttribute]));
seedList.push(sha256(userTraits[audienceAttribute].trim()));
} else {
seedList.push(userTraits[audienceAttribute]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ export const data = [
traits: {
email: '[email protected]',
birthday: '2005-01-01T23:28:56.782Z',
firstName: 'test',
firstName: ' test',
name: 'test rudderlabs',
address: {
city: 'kalkata',
Expand Down
2 changes: 1 addition & 1 deletion test/integrations/destinations/fb/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export const data = [
traits: {
email: '[email protected]',
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
firstName: 'test',
firstName: ' test',
lastName: 'last',
gender: 1234,
phone: '+91-9831311135',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ export const data = [
},
traits: {
phone: '912382193',
firstName: 'John',
firstName: ' John',
lastName: 'Gomes',
city: 'London',
state: 'UK',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const data = [
advertisingId: '44c97318-9040-4361-8bc7-4eb30f665ca8',
},
traits: {
email: '[email protected]',
email: ' [email protected]',
phone: '+1-202-555-0146',
firstName: 'John',
lastName: 'Gomes',
Expand Down
2 changes: 1 addition & 1 deletion test/integrations/destinations/impact/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const data = [
namespace: 'com.rudderlabs.javascript',
},
traits: {
email: '[email protected]',
email: ' [email protected]',
phone: '+917836362334',
userId: 'user123',
},
Expand Down
2 changes: 1 addition & 1 deletion test/integrations/destinations/yahoo_dsp/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const data = [
},
{
ipAddress: 'fdffddf',
email: '[email protected]',
email: '[email protected] ',
deviceId: 'djfdjfkdjf',
phone: '@09876543210',
firstName: 'test',
Expand Down

0 comments on commit 3a84b8d

Please sign in to comment.