Skip to content

Commit

Permalink
fix: snapchat conversion introduce missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Oct 10, 2023
1 parent 4ce47ec commit 437aa9a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
41 changes: 38 additions & 3 deletions src/v0/destinations/snapchat_conversion/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,34 @@ function populateHashedValues(payload, message) {
const email = getFieldValueFromMessage(message, 'email');
const phone = getNormalizedPhoneNumber(message);
const ip = message.context?.ip || message.request_ip;

const firstName = getFieldValueFromMessage(message, 'firstName');
const lastName = getFieldValueFromMessage(message, 'lastName');
const middleName = getFieldValueFromMessage(message, 'middleName');
const city = getFieldValueFromMessage(message, 'city');
const state = getFieldValueFromMessage(message, 'state');
const zip = getFieldValueFromMessage(message, 'zip');
if (firstName) {
updatedPayload.hashed_first_name_sha = getHashedValue(
firstName.toString().toLowerCase().trim(),
);
}
if (middleName) {
updatedPayload.hashed_middle_name_sha = getHashedValue(
middleName.toString().toLowerCase().trim(),
);
}
if (lastName) {
updatedPayload.hashed_last_name_sha = getHashedValue(lastName.toString().toLowerCase().trim());
}
if (city) {
updatedPayload.hashed_city_sha = getHashedValue(city.toString().toLowerCase().trim());

Check warning on line 81 in src/v0/destinations/snapchat_conversion/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/snapchat_conversion/transform.js#L81

Added line #L81 was not covered by tests
}
if (zip) {
updatedPayload.hashed_zip = getHashedValue(zip.toString().toLowerCase().trim());

Check warning on line 84 in src/v0/destinations/snapchat_conversion/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/snapchat_conversion/transform.js#L84

Added line #L84 was not covered by tests
}
if (state) {
updatedPayload.hashed_state_sha = getHashedValue(state.toString().toLowerCase().trim());
}
if (email) {
updatedPayload.hashed_email = getHashedValue(email.toString().toLowerCase().trim());
}
Expand Down Expand Up @@ -190,10 +217,18 @@ function trackResponseBuilder(message, { Config }, mappedEvent) {
} else {
throw new InstrumentationError(`Event ${event} doesn't match with Snapchat Events!`);
}

payload.description = get(message, 'properties.description');
if (Array.isArray(message.properties?.brands)) {
payload.brands = get(message, 'properties.brands');

Check warning on line 222 in src/v0/destinations/snapchat_conversion/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/snapchat_conversion/transform.js#L222

Added line #L222 was not covered by tests
}
payload.customer_status = get(message, 'properties.customer_status');
payload.uuid_c1 = get(message, 'properties.uuid_c1');
payload.level = get(message, 'properties.level');
payload.click_id = get(message, 'properties.click_id');
payload.event_tag = get(message, 'properties.event_tag');
payload = populateHashedValues(payload, message);

payload.country = getFieldValueFromMessage(message, 'country'); // Must be provided as a two letter ISO 3166 alpha-2 country code.
payload.region = getFieldValueFromMessage(message, 'region');
payload.user_agent = message.context?.userAgent?.toString().toLowerCase();

if (
Expand Down
27 changes: 17 additions & 10 deletions test/__tests__/data/snapchat_conversion.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"description": "Test case for Prodcuts Searched event for conversion type offline",
"description": "Test case for Products Searched event for conversion type offline",
"input": {
"message": {
"messageId": "ec5481b6-a926-4d2e-b293-0b3a77c4d3be",
Expand All @@ -9,7 +9,12 @@
"context": {
"traits": {
"email": "[email protected]",
"phone": "+91 2111111 "
"phone": "+91 2111111 ",
"firstName": "john",
"middleName": "victor",
"lastName": "doe",
"city": "some_city",
"state": "some_state"
},
"app": {
"build": "1.0.0",
Expand All @@ -26,7 +31,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand All @@ -52,7 +56,9 @@
"properties": {
"query": "t-shirts",
"event_conversion_type": "web",
"number_items": 4
"number_items": 4,
"click_id": "some_click_id",
"description": "Products Searched event for conversion type offline"
},
"integrations": {
"All": true
Expand Down Expand Up @@ -88,7 +94,13 @@
"timestamp": "1650625078",
"event_conversion_type": "OFFLINE",
"pixel_id": "dummyPixelId",
"number_items": 4
"number_items": 4,
"click_id": "some_click_id",
"description": "Products Searched event for conversion type offline",
"hashed_first_name_sha": "96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a",
"hashed_last_name_sha": "799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f",
"hashed_state_sha": "6db488fc98e30afdf67a05a6da916805b02891ce58f03970c6deff79129c5f1c",
"hashed_middle_name_sha": "99bde068af2d49ed7fc8b8fa79abe13a6059e0db320bb73459fd96624bb4b33f"
},
"JSON_ARRAY": {},
"XML": {},
Expand Down Expand Up @@ -2025,7 +2037,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2227,7 +2238,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2331,7 +2341,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2403,7 +2412,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2501,7 +2509,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down

0 comments on commit 437aa9a

Please sign in to comment.