From c1631d5c573d29cb6a880449d72ed5523dc0c97b Mon Sep 17 00:00:00 2001 From: sebashine Date: Fri, 1 Sep 2023 17:52:11 +0200 Subject: [PATCH 01/11] feat: add hashed_first_name_sha --- .../_tests_/index.test.ts | 42 +++++++++++++++++++ .../reportConversionEvent/generated-types.ts | 4 ++ .../reportConversionEvent/index.ts | 6 ++- .../snap-capi-properties.ts | 9 +++- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index 06c5f8f08a..e1bb67e108 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -2,6 +2,13 @@ import nock from 'nock' import { createTestEvent, createTestIntegration } from '@segment/actions-core' import Definition from '../index' import { Settings } from '../generated-types' +import { defaultValues } from '@segment/actions-core' + +import reportConversionEvent from '../reportConversionEvent' + +const DEFAULT_VALS = { + ...defaultValues(reportConversionEvent.fields) +} const testDestination = createTestIntegration(Definition) const timestamp = '2022-05-12T15:21:15.449Z' @@ -399,5 +406,40 @@ describe('Snap Conversions API ', () => { `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"pixel_id\\":\\"test123\\"}"` ) }) + + it('should handle event with optional parameters', async () => { + nock(conversionEventUrl).post('').reply(200, {}) + + const event = createTestEvent({ + ...testEvent, + properties: { + ...testEvent.properties, + first_name: 'John' + } + }) + + const responses = await testDestination.testAction('reportConversionEvent', { + event, + settings, + useDefaultMappings: false, + auth: { + accessToken, + refreshToken + }, + mapping: { + ...DEFAULT_VALS, + event_type: 'PURCHASE', + event_conversion_type: 'WEB', + first_name: { '@path': '$.properties.first_name' } + } + }) + + expect(responses).not.toBeNull() + expect(responses[0].status).toBe(200) + + expect(responses[0].options.body).toMatchInlineSnapshot( + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"pixel_id\\":\\"test123\\"}"` + ) + }) }) }) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts index 48b18f1173..8beeceaddf 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts @@ -105,4 +105,8 @@ export interface Payload { * The ID value stored in the landing page URL's `&ScCid=` query parameter. Using this ID improves ad measurement performance. We also encourage advertisers who are using `click_id` to pass the full url in the `page_url` field. For more details, please refer to [Sending a Click ID](#sending-a-click-id) */ click_id?: string + /** + * First name of the converted user. + */ + first_name?: string } diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts index 4585dbad11..4bc8b76304 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts @@ -30,7 +30,8 @@ import { conversionType, device_model, os_version, - click_id + click_id, + first_name } from '../snap-capi-properties' const CONVERSION_EVENT_URL = 'https://tr.snapchat.com/v2/conversion' @@ -65,7 +66,8 @@ const action: ActionDefinition = { sign_up_method: sign_up_method, os_version: os_version, device_model: device_model, - click_id: click_id + click_id: click_id, + first_name: first_name }, perform: (request, data) => { if (data.payload.currency && !CURRENCY_ISO_4217_CODES.has(data.payload.currency.toUpperCase())) { diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index e3b6476b12..96b13e3bf9 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -296,6 +296,12 @@ export const click_id: InputField = { type: 'string' } +export const first_name: InputField = { + label: 'First name', + description: 'First name of the converted user.', + type: 'string' +} + //Check to see what ids need to be passed depending on the event_conversion_type export const conversionType = (settings: Settings, event_conversion_type: String): Settings => { if (event_conversion_type === 'MOBILE_APP') { @@ -374,6 +380,7 @@ export const formatPayload = (payload: Payload): Object => { sign_up_method: payload?.sign_up_method, device_model: payload?.device_model, os_version: payload?.os_version, - click_id: payload?.click_id + click_id: payload?.click_id, + hashed_first_name_sha: hash(payload?.first_name) } } From 0fac111d831c88191a806c68ed9a4384256f5c31 Mon Sep 17 00:00:00 2001 From: sebashine Date: Fri, 1 Sep 2023 18:01:00 +0200 Subject: [PATCH 02/11] feat: add hashed_middle_name_sha --- .../snap-conversions-api/_tests_/index.test.ts | 8 +++++--- .../reportConversionEvent/generated-types.ts | 4 ++++ .../snap-conversions-api/reportConversionEvent/index.ts | 6 ++++-- .../snap-conversions-api/snap-capi-properties.ts | 9 ++++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index e1bb67e108..aa779394d2 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -414,7 +414,8 @@ describe('Snap Conversions API ', () => { ...testEvent, properties: { ...testEvent.properties, - first_name: 'John' + first_name: 'John', + middle_name: 'Middle' } }) @@ -430,7 +431,8 @@ describe('Snap Conversions API ', () => { ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', - first_name: { '@path': '$.properties.first_name' } + first_name: { '@path': '$.properties.first_name' }, + middle_name: { '@path': '$.properties.middle_name' } } }) @@ -438,7 +440,7 @@ describe('Snap Conversions API ', () => { expect(responses[0].status).toBe(200) expect(responses[0].options.body).toMatchInlineSnapshot( - `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"pixel_id\\":\\"test123\\"}"` + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"pixel_id\\":\\"test123\\"}"` ) }) }) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts index 8beeceaddf..da78fa6c4b 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts @@ -109,4 +109,8 @@ export interface Payload { * First name of the converted user. */ first_name?: string + /** + * Middle name of the converted user. + */ + middle_name?: string } diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts index 4bc8b76304..b6adee0c43 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts @@ -31,7 +31,8 @@ import { device_model, os_version, click_id, - first_name + first_name, + middle_name } from '../snap-capi-properties' const CONVERSION_EVENT_URL = 'https://tr.snapchat.com/v2/conversion' @@ -67,7 +68,8 @@ const action: ActionDefinition = { os_version: os_version, device_model: device_model, click_id: click_id, - first_name: first_name + first_name: first_name, + middle_name: middle_name }, perform: (request, data) => { if (data.payload.currency && !CURRENCY_ISO_4217_CODES.has(data.payload.currency.toUpperCase())) { diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index 96b13e3bf9..edd8e85111 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -302,6 +302,12 @@ export const first_name: InputField = { type: 'string' } +export const middle_name: InputField = { + label: 'Middle name', + description: 'Middle name of the converted user.', + type: 'string' +} + //Check to see what ids need to be passed depending on the event_conversion_type export const conversionType = (settings: Settings, event_conversion_type: String): Settings => { if (event_conversion_type === 'MOBILE_APP') { @@ -381,6 +387,7 @@ export const formatPayload = (payload: Payload): Object => { device_model: payload?.device_model, os_version: payload?.os_version, click_id: payload?.click_id, - hashed_first_name_sha: hash(payload?.first_name) + hashed_first_name_sha: hash(payload?.first_name), + hashed_middle_name_sha: hash(payload?.middle_name) } } From 2dbe36112318eeb6bcc527799756926b0c6d6169 Mon Sep 17 00:00:00 2001 From: sebashine Date: Mon, 4 Sep 2023 15:34:13 +0200 Subject: [PATCH 03/11] feat: add hashed_last_name_sha --- .../snap-conversions-api/_tests_/index.test.ts | 8 +++++--- .../reportConversionEvent/generated-types.ts | 4 ++++ .../snap-conversions-api/reportConversionEvent/index.ts | 6 ++++-- .../snap-conversions-api/snap-capi-properties.ts | 9 ++++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index aa779394d2..eda17ea6e1 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -415,7 +415,8 @@ describe('Snap Conversions API ', () => { properties: { ...testEvent.properties, first_name: 'John', - middle_name: 'Middle' + middle_name: 'Middle', + last_name: 'Doe' } }) @@ -432,7 +433,8 @@ describe('Snap Conversions API ', () => { event_type: 'PURCHASE', event_conversion_type: 'WEB', first_name: { '@path': '$.properties.first_name' }, - middle_name: { '@path': '$.properties.middle_name' } + middle_name: { '@path': '$.properties.middle_name' }, + last_name: { '@path': '$.properties.last_name' } } }) @@ -440,7 +442,7 @@ describe('Snap Conversions API ', () => { expect(responses[0].status).toBe(200) expect(responses[0].options.body).toMatchInlineSnapshot( - `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"pixel_id\\":\\"test123\\"}"` + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"hashed_last_name_sha\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"pixel_id\\":\\"test123\\"}"` ) }) }) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts index da78fa6c4b..ff3ab2d1aa 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts @@ -113,4 +113,8 @@ export interface Payload { * Middle name of the converted user. */ middle_name?: string + /** + * Last name of the converted user. + */ + last_name?: string } diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts index b6adee0c43..59e4ade861 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts @@ -32,7 +32,8 @@ import { os_version, click_id, first_name, - middle_name + middle_name, + last_name } from '../snap-capi-properties' const CONVERSION_EVENT_URL = 'https://tr.snapchat.com/v2/conversion' @@ -69,7 +70,8 @@ const action: ActionDefinition = { device_model: device_model, click_id: click_id, first_name: first_name, - middle_name: middle_name + middle_name: middle_name, + last_name: last_name }, perform: (request, data) => { if (data.payload.currency && !CURRENCY_ISO_4217_CODES.has(data.payload.currency.toUpperCase())) { diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index edd8e85111..d836d4cb1a 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -308,6 +308,12 @@ export const middle_name: InputField = { type: 'string' } +export const last_name: InputField = { + label: 'Last name', + description: 'Last name of the converted user.', + type: 'string' +} + //Check to see what ids need to be passed depending on the event_conversion_type export const conversionType = (settings: Settings, event_conversion_type: String): Settings => { if (event_conversion_type === 'MOBILE_APP') { @@ -388,6 +394,7 @@ export const formatPayload = (payload: Payload): Object => { os_version: payload?.os_version, click_id: payload?.click_id, hashed_first_name_sha: hash(payload?.first_name), - hashed_middle_name_sha: hash(payload?.middle_name) + hashed_middle_name_sha: hash(payload?.middle_name), + hashed_last_name_sha: hash(payload?.last_name) } } From fa6035ed84005531565b87aa0717738a6f423189 Mon Sep 17 00:00:00 2001 From: sebashine Date: Mon, 4 Sep 2023 15:59:31 +0200 Subject: [PATCH 04/11] feat: add hashed_city_sha hashed_state_sha hashed_zip hashed_dob_month hashed_dob_day --- .../_tests_/index.test.ts | 16 ++++++-- .../reportConversionEvent/generated-types.ts | 20 ++++++++++ .../reportConversionEvent/index.ts | 14 ++++++- .../snap-capi-properties.ts | 37 ++++++++++++++++++- 4 files changed, 81 insertions(+), 6 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index eda17ea6e1..8fbf4663e4 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -416,7 +416,12 @@ describe('Snap Conversions API ', () => { ...testEvent.properties, first_name: 'John', middle_name: 'Middle', - last_name: 'Doe' + last_name: 'Doe', + city: 'Santa Monica', + state: 'CA', + zip: '90405', + dob_month: 'January', + dob_day: '26' } }) @@ -434,7 +439,12 @@ describe('Snap Conversions API ', () => { event_conversion_type: 'WEB', first_name: { '@path': '$.properties.first_name' }, middle_name: { '@path': '$.properties.middle_name' }, - last_name: { '@path': '$.properties.last_name' } + last_name: { '@path': '$.properties.last_name' }, + city: { '@path': '$.properties.city' }, + state: { '@path': '$.properties.state' }, + zip: { '@path': '$.properties.zip' }, + dob_month: { '@path': '$.properties.dob_month' }, + dob_day: { '@path': '$.properties.dob_day' } } }) @@ -442,7 +452,7 @@ describe('Snap Conversions API ', () => { expect(responses[0].status).toBe(200) expect(responses[0].options.body).toMatchInlineSnapshot( - `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"hashed_last_name_sha\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"pixel_id\\":\\"test123\\"}"` + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"hashed_last_name_sha\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"hashed_city_sha\\":\\"ced2e77f732fbf327f53e1f9748078c778b190ed9cf376a7df469a92d2ad62d3\\",\\"hashed_state_sha\\":\\"4b650e5c4785025dee7bd65e3c5c527356717d7a1c0bfef5b4ada8ca1e9cbe17\\",\\"hashed_zip\\":\\"e222c384dd83ac669bcd1da281ffea2e60bab298f8c0673d35bc0b704e345282\\",\\"hashed_dob_month\\":\\"37082e68df858e0ba76442174128811135890ae4c2c5df8b6f31aef5885d0be7\\",\\"hashed_dob_day\\":\\"5f9c4ab08cac7457e9111a30e4664920607ea2c115a1433d7be98e97e64244ca\\",\\"pixel_id\\":\\"test123\\"}"` ) }) }) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts index ff3ab2d1aa..819fb01fa7 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts @@ -117,4 +117,24 @@ export interface Payload { * Last name of the converted user. */ last_name?: string + /** + * City associated with the conversion. + */ + city?: string + /** + * State or region associated with the conversion. + */ + state?: string + /** + * Zip or postal code associated with the conversion. + */ + zip?: string + /** + * Birth month of the converted user. + */ + dob_month?: string + /** + * Day of the month that the converted user was born. + */ + dob_day?: string } diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts index 59e4ade861..3a5084073d 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts @@ -33,7 +33,12 @@ import { click_id, first_name, middle_name, - last_name + last_name, + city, + state, + zip, + dob_month, + dob_day } from '../snap-capi-properties' const CONVERSION_EVENT_URL = 'https://tr.snapchat.com/v2/conversion' @@ -71,7 +76,12 @@ const action: ActionDefinition = { click_id: click_id, first_name: first_name, middle_name: middle_name, - last_name: last_name + last_name: last_name, + city: city, + state: state, + zip: zip, + dob_month: dob_month, + dob_day: dob_day }, perform: (request, data) => { if (data.payload.currency && !CURRENCY_ISO_4217_CODES.has(data.payload.currency.toUpperCase())) { diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index d836d4cb1a..2b5a9ae42d 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -314,6 +314,36 @@ export const last_name: InputField = { type: 'string' } +export const city: InputField = { + label: 'City', + description: 'City associated with the conversion.', + type: 'string' +} + +export const state: InputField = { + label: 'State', + description: 'State or region associated with the conversion.', + type: 'string' +} + +export const zip: InputField = { + label: 'Zip', + description: 'Zip or postal code associated with the conversion.', + type: 'string' +} + +export const dob_month: InputField = { + label: 'Birthday Month', + description: 'Birth month of the converted user.', + type: 'string' +} + +export const dob_day: InputField = { + label: 'Day of the Birthday', + description: 'Day of the month that the converted user was born.', + type: 'string' +} + //Check to see what ids need to be passed depending on the event_conversion_type export const conversionType = (settings: Settings, event_conversion_type: String): Settings => { if (event_conversion_type === 'MOBILE_APP') { @@ -395,6 +425,11 @@ export const formatPayload = (payload: Payload): Object => { click_id: payload?.click_id, hashed_first_name_sha: hash(payload?.first_name), hashed_middle_name_sha: hash(payload?.middle_name), - hashed_last_name_sha: hash(payload?.last_name) + hashed_last_name_sha: hash(payload?.last_name), + hashed_city_sha: hash(payload?.city), + hashed_state_sha: hash(payload?.state), + hashed_zip: hash(payload?.zip), + hashed_dob_month: hash(payload?.dob_month), + hashed_dob_day: hash(payload?.dob_day) } } From 02d267c577f771a424f9d2d7b61e14cf2903dcd4 Mon Sep 17 00:00:00 2001 From: sebashine Date: Mon, 4 Sep 2023 16:03:35 +0200 Subject: [PATCH 05/11] fix: lowercase idfv --- .../destinations/snap-conversions-api/_tests_/index.test.ts | 4 +++- .../snap-conversions-api/snap-capi-properties.ts | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index 8fbf4663e4..0834444f1b 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -414,6 +414,7 @@ describe('Snap Conversions API ', () => { ...testEvent, properties: { ...testEvent.properties, + idfv: 'C305F2DB-56FC-404F-B6C1-BC52E0B680D8', first_name: 'John', middle_name: 'Middle', last_name: 'Doe', @@ -437,6 +438,7 @@ describe('Snap Conversions API ', () => { ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', + idfv: { '@path': '$.properties.idfv' }, first_name: { '@path': '$.properties.first_name' }, middle_name: { '@path': '$.properties.middle_name' }, last_name: { '@path': '$.properties.last_name' }, @@ -452,7 +454,7 @@ describe('Snap Conversions API ', () => { expect(responses[0].status).toBe(200) expect(responses[0].options.body).toMatchInlineSnapshot( - `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"hashed_last_name_sha\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"hashed_city_sha\\":\\"ced2e77f732fbf327f53e1f9748078c778b190ed9cf376a7df469a92d2ad62d3\\",\\"hashed_state_sha\\":\\"4b650e5c4785025dee7bd65e3c5c527356717d7a1c0bfef5b4ada8ca1e9cbe17\\",\\"hashed_zip\\":\\"e222c384dd83ac669bcd1da281ffea2e60bab298f8c0673d35bc0b704e345282\\",\\"hashed_dob_month\\":\\"37082e68df858e0ba76442174128811135890ae4c2c5df8b6f31aef5885d0be7\\",\\"hashed_dob_day\\":\\"5f9c4ab08cac7457e9111a30e4664920607ea2c115a1433d7be98e97e64244ca\\",\\"pixel_id\\":\\"test123\\"}"` + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_idfv\\":\\"f18c8b858e52b0c49f7db8f813538db0ecdc513357efd62c525784a9beb617d6\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"hashed_last_name_sha\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"hashed_city_sha\\":\\"ced2e77f732fbf327f53e1f9748078c778b190ed9cf376a7df469a92d2ad62d3\\",\\"hashed_state_sha\\":\\"4b650e5c4785025dee7bd65e3c5c527356717d7a1c0bfef5b4ada8ca1e9cbe17\\",\\"hashed_zip\\":\\"e222c384dd83ac669bcd1da281ffea2e60bab298f8c0673d35bc0b704e345282\\",\\"hashed_dob_month\\":\\"37082e68df858e0ba76442174128811135890ae4c2c5df8b6f31aef5885d0be7\\",\\"hashed_dob_day\\":\\"5f9c4ab08cac7457e9111a30e4664920607ea2c115a1433d7be98e97e64244ca\\",\\"pixel_id\\":\\"test123\\"}"` ) }) }) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index 2b5a9ae42d..4121a10f19 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -396,6 +396,11 @@ export const formatPayload = (payload: Payload): Object => { payload.mobile_ad_id = payload.mobile_ad_id.toLowerCase() } + if (payload.idfv) { + //Converts all characters to lowercase + payload.idfv = payload.idfv.toLowerCase() + } + return { event_type: payload?.event_type, event_conversion_type: payload?.event_conversion_type, From ad395d16636f4a9c910f5e2958fff396059960de Mon Sep 17 00:00:00 2001 From: sebashine Date: Mon, 4 Sep 2023 16:14:24 +0200 Subject: [PATCH 06/11] feat: add country region --- .../snap-conversions-api/_tests_/index.test.ts | 10 +++++++--- .../reportConversionEvent/generated-types.ts | 8 ++++++++ .../reportConversionEvent/index.ts | 8 ++++++-- .../snap-capi-properties.ts | 18 +++++++++++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index 0834444f1b..9af74c5f3f 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -422,7 +422,9 @@ describe('Snap Conversions API ', () => { state: 'CA', zip: '90405', dob_month: 'January', - dob_day: '26' + dob_day: '26', + country: 'US', + region: 'CA' } }) @@ -446,7 +448,9 @@ describe('Snap Conversions API ', () => { state: { '@path': '$.properties.state' }, zip: { '@path': '$.properties.zip' }, dob_month: { '@path': '$.properties.dob_month' }, - dob_day: { '@path': '$.properties.dob_day' } + dob_day: { '@path': '$.properties.dob_day' }, + country: { '@path': '$.properties.country' }, + region: { '@path': '$.properties.region' } } }) @@ -454,7 +458,7 @@ describe('Snap Conversions API ', () => { expect(responses[0].status).toBe(200) expect(responses[0].options.body).toMatchInlineSnapshot( - `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_idfv\\":\\"f18c8b858e52b0c49f7db8f813538db0ecdc513357efd62c525784a9beb617d6\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"hashed_last_name_sha\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"hashed_city_sha\\":\\"ced2e77f732fbf327f53e1f9748078c778b190ed9cf376a7df469a92d2ad62d3\\",\\"hashed_state_sha\\":\\"4b650e5c4785025dee7bd65e3c5c527356717d7a1c0bfef5b4ada8ca1e9cbe17\\",\\"hashed_zip\\":\\"e222c384dd83ac669bcd1da281ffea2e60bab298f8c0673d35bc0b704e345282\\",\\"hashed_dob_month\\":\\"37082e68df858e0ba76442174128811135890ae4c2c5df8b6f31aef5885d0be7\\",\\"hashed_dob_day\\":\\"5f9c4ab08cac7457e9111a30e4664920607ea2c115a1433d7be98e97e64244ca\\",\\"pixel_id\\":\\"test123\\"}"` + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"hashed_email\\":\\"cc779c04191c2e736d89e45c11339c8382832bcaf70383f7df94e3d08ba7a6d9\\",\\"hashed_idfv\\":\\"f18c8b858e52b0c49f7db8f813538db0ecdc513357efd62c525784a9beb617d6\\",\\"hashed_phone_number\\":\\"dc008fda46e2e64002cf2f82a4906236282d431c4f75e5b60bfe79fc48546383\\",\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"price\\":15,\\"currency\\":\\"USD\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"hashed_first_name_sha\\":\\"a8cfcd74832004951b4408cdb0a5dbcd8c7e52d43f7fe244bf720582e05241da\\",\\"hashed_middle_name_sha\\":\\"d93006ec2e4339d770a7afd068c1f1e789a52df12f595e529fd0f302fc1e5ec7\\",\\"hashed_last_name_sha\\":\\"fd53ef835b15485572a6e82cf470dcb41fd218ae5751ab7531c956a2a6bcd3c7\\",\\"hashed_city_sha\\":\\"ced2e77f732fbf327f53e1f9748078c778b190ed9cf376a7df469a92d2ad62d3\\",\\"hashed_state_sha\\":\\"4b650e5c4785025dee7bd65e3c5c527356717d7a1c0bfef5b4ada8ca1e9cbe17\\",\\"hashed_zip\\":\\"e222c384dd83ac669bcd1da281ffea2e60bab298f8c0673d35bc0b704e345282\\",\\"hashed_dob_month\\":\\"37082e68df858e0ba76442174128811135890ae4c2c5df8b6f31aef5885d0be7\\",\\"hashed_dob_day\\":\\"5f9c4ab08cac7457e9111a30e4664920607ea2c115a1433d7be98e97e64244ca\\",\\"country\\":\\"US\\",\\"region\\":\\"CA\\",\\"pixel_id\\":\\"test123\\"}"` ) }) }) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts index 819fb01fa7..ab5d6909a3 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts @@ -137,4 +137,12 @@ export interface Payload { * Day of the month that the converted user was born. */ dob_day?: string + /** + * Country associated with the conversion. Must be provided as a two letter [ISO 3166 alpha-2 country code](https://www.iso.org/obp/ui/#search). + */ + country?: string + /** + * State or region associated with the conversion. If the country is US, provide a two letter State code (`CA`, `WA`), otherwise provide the full region name. + */ + region?: string } diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts index 3a5084073d..e93c80b646 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts @@ -38,7 +38,9 @@ import { state, zip, dob_month, - dob_day + dob_day, + country, + region } from '../snap-capi-properties' const CONVERSION_EVENT_URL = 'https://tr.snapchat.com/v2/conversion' @@ -81,7 +83,9 @@ const action: ActionDefinition = { state: state, zip: zip, dob_month: dob_month, - dob_day: dob_day + dob_day: dob_day, + country: country, + region: region }, perform: (request, data) => { if (data.payload.currency && !CURRENCY_ISO_4217_CODES.has(data.payload.currency.toUpperCase())) { diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index 4121a10f19..263d057ff8 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -344,6 +344,20 @@ export const dob_day: InputField = { type: 'string' } +export const country: InputField = { + label: 'Country', + description: + 'Country associated with the conversion. Must be provided as a two letter [ISO 3166 alpha-2 country code](https://www.iso.org/obp/ui/#search).', + type: 'string' +} + +export const region: InputField = { + label: 'Region', + description: + 'State or region associated with the conversion. If the country is US, provide a two letter State code (`CA`, `WA`), otherwise provide the full region name.', + type: 'string' +} + //Check to see what ids need to be passed depending on the event_conversion_type export const conversionType = (settings: Settings, event_conversion_type: String): Settings => { if (event_conversion_type === 'MOBILE_APP') { @@ -435,6 +449,8 @@ export const formatPayload = (payload: Payload): Object => { hashed_state_sha: hash(payload?.state), hashed_zip: hash(payload?.zip), hashed_dob_month: hash(payload?.dob_month), - hashed_dob_day: hash(payload?.dob_day) + hashed_dob_day: hash(payload?.dob_day), + country: payload?.country, + region: payload?.region } } From a4af32bd1e88e490fb802130e2c9e2c7ddb49222 Mon Sep 17 00:00:00 2001 From: sebashine Date: Mon, 4 Sep 2023 16:30:45 +0200 Subject: [PATCH 07/11] feat: add validation and tests for region --- .../_tests_/index.test.ts | 140 ++++++++++++++++++ .../reportConversionEvent/index.ts | 8 + 2 files changed, 148 insertions(+) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index 9af74c5f3f..d3c5b699f7 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -200,6 +200,146 @@ describe('Snap Conversions API ', () => { ).rejects.toThrowError('Galleon is not a valid currency code.') }) + it('should fail invalid region', async () => { + nock(conversionEventUrl).post('').reply(400, {}) + + const event = createTestEvent({ + ...testEvent, + properties: { + country: 'US', + region: 'California' + } + }) + + await expect( + testDestination.testAction('reportConversionEvent', { + event, + settings, + useDefaultMappings: false, + auth: { + accessToken, + refreshToken + }, + mapping: { + ...DEFAULT_VALS, + event_type: 'PURCHASE', + event_conversion_type: 'WEB', + country: { '@path': '$.properties.country' }, + region: { '@path': '$.properties.region' } + } + }) + ).rejects.toThrowError( + 'California is not a valid region code. Given that country is US, region should be a two letter State code.' + ) + }) + + it('should handle event with valid country (and no region)', async () => { + nock(conversionEventUrl).post('').reply(200, {}) + + const event = createTestEvent({ + ...testEvent, + properties: { + country: 'US' + } + }) + + const responses = await testDestination.testAction('reportConversionEvent', { + event, + settings, + useDefaultMappings: false, + auth: { + accessToken, + refreshToken + }, + mapping: { + ...DEFAULT_VALS, + event_type: 'PURCHASE', + event_conversion_type: 'WEB', + country: { '@path': '$.properties.country' }, + region: { '@path': '$.properties.region' } + } + }) + + expect(responses).not.toBeNull() + expect(responses[0].status).toBe(200) + + expect(responses[0].options.body).toMatchInlineSnapshot( + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"country\\":\\"US\\",\\"pixel_id\\":\\"test123\\"}"` + ) + }) + + it('should handle event with valid region (US)', async () => { + nock(conversionEventUrl).post('').reply(200, {}) + + const event = createTestEvent({ + ...testEvent, + properties: { + country: 'US', + region: 'CA' + } + }) + + const responses = await testDestination.testAction('reportConversionEvent', { + event, + settings, + useDefaultMappings: false, + auth: { + accessToken, + refreshToken + }, + mapping: { + ...DEFAULT_VALS, + event_type: 'PURCHASE', + event_conversion_type: 'WEB', + country: { '@path': '$.properties.country' }, + region: { '@path': '$.properties.region' } + } + }) + + expect(responses).not.toBeNull() + expect(responses[0].status).toBe(200) + + expect(responses[0].options.body).toMatchInlineSnapshot( + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"country\\":\\"US\\",\\"region\\":\\"CA\\",\\"pixel_id\\":\\"test123\\"}"` + ) + }) + + it('should handle event with valid region (non-US)', async () => { + nock(conversionEventUrl).post('').reply(200, {}) + + const event = createTestEvent({ + ...testEvent, + properties: { + country: 'FR', + region: 'Hauts-de-France' + } + }) + + const responses = await testDestination.testAction('reportConversionEvent', { + event, + settings, + useDefaultMappings: false, + auth: { + accessToken, + refreshToken + }, + mapping: { + ...DEFAULT_VALS, + event_type: 'PURCHASE', + event_conversion_type: 'WEB', + country: { '@path': '$.properties.country' }, + region: { '@path': '$.properties.region' } + } + }) + + expect(responses).not.toBeNull() + expect(responses[0].status).toBe(200) + + expect(responses[0].options.body).toMatchInlineSnapshot( + `"{\\"integration\\":\\"segment\\",\\"event_type\\":\\"PURCHASE\\",\\"event_conversion_type\\":\\"WEB\\",\\"timestamp\\":1652368875449,\\"user_agent\\":\\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1\\",\\"hashed_ip_address\\":\\"838c4c2573848f58e74332341a7ca6bc5cd86a8aec7d644137d53b4d597f10f5\\",\\"page_url\\":\\"https://segment.com/academy/\\",\\"country\\":\\"FR\\",\\"region\\":\\"Hauts-de-France\\",\\"pixel_id\\":\\"test123\\"}"` + ) + }) + it('should fail missing event conversion type', async () => { nock(conversionEventUrl).post('').reply(400, {}) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts index e93c80b646..44b405f88b 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts @@ -96,6 +96,14 @@ const action: ActionDefinition = { ) } + if (data.payload.country === 'US' && data.payload.region && data.payload.region.length !== 2) { + throw new IntegrationError( + `${data.payload.region} is not a valid region code. Given that country is US, region should be a two letter State code.`, + 'Misconfigured optional field', + 400 + ) + } + if ( !data.payload.email && !data.payload.phone_number && From 07a16df692d1858f81fbe8db3143e05b11ea87d7 Mon Sep 17 00:00:00 2001 From: sebashine Date: Mon, 4 Sep 2023 17:11:23 +0200 Subject: [PATCH 08/11] feat: add validation and tests for country --- .../_tests_/index.test.ts | 31 +++ .../reportConversionEvent/index.ts | 9 + .../snap-capi-properties.ts | 252 ++++++++++++++++++ 3 files changed, 292 insertions(+) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index d3c5b699f7..4bf9a879aa 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -200,6 +200,37 @@ describe('Snap Conversions API ', () => { ).rejects.toThrowError('Galleon is not a valid currency code.') }) + it('should fail invalid country', async () => { + nock(conversionEventUrl).post('').reply(400, {}) + + const event = createTestEvent({ + ...testEvent, + properties: { + country: 'United States of America' + } + }) + + await expect( + testDestination.testAction('reportConversionEvent', { + event, + settings, + useDefaultMappings: false, + auth: { + accessToken, + refreshToken + }, + mapping: { + ...DEFAULT_VALS, + event_type: 'PURCHASE', + event_conversion_type: 'WEB', + country: { '@path': '$.properties.country' } + } + }) + ).rejects.toThrowError( + 'United States of America is not a valid country code. It must be provided as a two letter ISO 3166 alpha-2 country code.' + ) + }) + it('should fail invalid region', async () => { nock(conversionEventUrl).post('').reply(400, {}) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts index 44b405f88b..a2d6bb6fc6 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/index.ts @@ -26,6 +26,7 @@ import { page_url, sign_up_method, formatPayload, + COUNTRY_ISO_3166_CODES, CURRENCY_ISO_4217_CODES, conversionType, device_model, @@ -96,6 +97,14 @@ const action: ActionDefinition = { ) } + if (data.payload.country && !COUNTRY_ISO_3166_CODES.has(data.payload.country)) { + throw new IntegrationError( + `${data.payload.country} is not a valid country code. It must be provided as a two letter ISO 3166 alpha-2 country code.`, + 'Misconfigured optional field', + 400 + ) + } + if (data.payload.country === 'US' && data.payload.region && data.payload.region.length !== 2) { throw new IntegrationError( `${data.payload.region} is not a valid region code. Given that country is US, region should be a two letter State code.`, diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index 263d057ff8..b2cf5bb67a 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -67,6 +67,258 @@ export const CURRENCY_ISO_4217_CODES = new Set([ 'XOF' ]) +export const COUNTRY_ISO_3166_CODES = new Set([ + 'AD', + 'AE', + 'AF', + 'AG', + 'AI', + 'AL', + 'AM', + 'AO', + 'AQ', + 'AR', + 'AS', + 'AT', + 'AU', + 'AW', + 'AX', + 'AZ', + 'BA', + 'BB', + 'BD', + 'BE', + 'BF', + 'BG', + 'BH', + 'BI', + 'BJ', + 'BL', + 'BM', + 'BN', + 'BO', + 'BQ', + 'BR', + 'BS', + 'BT', + 'BV', + 'BW', + 'BY', + 'BZ', + 'CA', + 'CC', + 'CD', + 'CF', + 'CG', + 'CH', + 'CI', + 'CK', + 'CL', + 'CM', + 'CN', + 'CO', + 'CR', + 'CU', + 'CV', + 'CW', + 'CX', + 'CY', + 'CZ', + 'DE', + 'DJ', + 'DK', + 'DM', + 'DO', + 'DZ', + 'EC', + 'EE', + 'EG', + 'EH', + 'ER', + 'ES', + 'ET', + 'FI', + 'FJ', + 'FK', + 'FM', + 'FO', + 'FR', + 'GA', + 'GB', + 'GD', + 'GE', + 'GF', + 'GG', + 'GH', + 'GI', + 'GL', + 'GM', + 'GN', + 'GP', + 'GQ', + 'GR', + 'GS', + 'GT', + 'GU', + 'GW', + 'GY', + 'HK', + 'HM', + 'HN', + 'HR', + 'HT', + 'HU', + 'ID', + 'IE', + 'IL', + 'IM', + 'IN', + 'IO', + 'IQ', + 'IR', + 'IS', + 'IT', + 'JE', + 'JM', + 'JO', + 'JP', + 'KE', + 'KG', + 'KH', + 'KI', + 'KM', + 'KN', + 'KP', + 'KR', + 'KW', + 'KY', + 'KZ', + 'LA', + 'LB', + 'LC', + 'LI', + 'LK', + 'LR', + 'LS', + 'LT', + 'LU', + 'LV', + 'LY', + 'MA', + 'MC', + 'MD', + 'ME', + 'MF', + 'MG', + 'MH', + 'MK', + 'ML', + 'MM', + 'MN', + 'MO', + 'MP', + 'MQ', + 'MR', + 'MS', + 'MT', + 'MU', + 'MV', + 'MW', + 'MX', + 'MY', + 'MZ', + 'NA', + 'NC', + 'NE', + 'NF', + 'NG', + 'NI', + 'NL', + 'NO', + 'NP', + 'NR', + 'NU', + 'NZ', + 'OM', + 'PA', + 'PE', + 'PF', + 'PG', + 'PH', + 'PK', + 'PL', + 'PM', + 'PN', + 'PR', + 'PS', + 'PT', + 'PW', + 'PY', + 'QA', + 'RE', + 'RO', + 'RS', + 'RU', + 'RW', + 'SA', + 'SB', + 'SC', + 'SD', + 'SE', + 'SG', + 'SH', + 'SI', + 'SJ', + 'SK', + 'SL', + 'SM', + 'SN', + 'SO', + 'SR', + 'SS', + 'ST', + 'SV', + 'SX', + 'SY', + 'SZ', + 'TC', + 'TD', + 'TF', + 'TG', + 'TH', + 'TJ', + 'TK', + 'TL', + 'TM', + 'TN', + 'TO', + 'TR', + 'TT', + 'TV', + 'TW', + 'TZ', + 'UA', + 'UG', + 'UM', + 'US', + 'UY', + 'UZ', + 'VA', + 'VC', + 'VE', + 'VG', + 'VI', + 'VN', + 'VU', + 'WF', + 'WS', + 'YE', + 'YT', + 'ZA', + 'ZM', + 'ZW' +]) + export const event_type: InputField = { label: 'Event Type', description: From 2f81842403b491a50e4b4a81724a5482d5af26bb Mon Sep 17 00:00:00 2001 From: sebashine Date: Tue, 5 Sep 2023 10:17:08 +0200 Subject: [PATCH 09/11] feat: add self-review --- .../snap-conversions-api/_tests_/index.test.ts | 4 ++-- .../reportConversionEvent/generated-types.ts | 2 +- .../snap-conversions-api/snap-capi-properties.ts | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index 4bf9a879aa..36b09d4fea 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -299,7 +299,7 @@ describe('Snap Conversions API ', () => { ) }) - it('should handle event with valid region (US)', async () => { + it('should handle event with valid region (related to the US)', async () => { nock(conversionEventUrl).post('').reply(200, {}) const event = createTestEvent({ @@ -335,7 +335,7 @@ describe('Snap Conversions API ', () => { ) }) - it('should handle event with valid region (non-US)', async () => { + it('should handle event with valid region (non-related to the US)', async () => { nock(conversionEventUrl).post('').reply(200, {}) const event = createTestEvent({ diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts index ab5d6909a3..e585b7b1c3 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/generated-types.ts @@ -142,7 +142,7 @@ export interface Payload { */ country?: string /** - * State or region associated with the conversion. If the country is US, provide a two letter State code (`CA`, `WA`), otherwise provide the full region name. + * State or region associated with the conversion. If the country is `US`, provide a two letter State code (`CA`, `WA`), otherwise provide the full region name. */ region?: string } diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index b2cf5bb67a..712644d694 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -585,13 +585,13 @@ export const zip: InputField = { } export const dob_month: InputField = { - label: 'Birthday Month', + label: 'Birth Month', description: 'Birth month of the converted user.', type: 'string' } export const dob_day: InputField = { - label: 'Day of the Birthday', + label: 'Birth Day', description: 'Day of the month that the converted user was born.', type: 'string' } @@ -606,7 +606,7 @@ export const country: InputField = { export const region: InputField = { label: 'Region', description: - 'State or region associated with the conversion. If the country is US, provide a two letter State code (`CA`, `WA`), otherwise provide the full region name.', + 'State or region associated with the conversion. If the country is `US`, provide a two letter State code (`CA`, `WA`), otherwise provide the full region name.', type: 'string' } @@ -646,7 +646,7 @@ export const hash = (value: string | undefined): string | undefined => { const isHashedEmail = (email: string): boolean => new RegExp(/[0-9abcdef]{64}/gi).test(email) export const formatPayload = (payload: Payload): Object => { - //Normalize fields based on Snapchat Data Hygiene https://marketingapi.snapchat.com/docs/conversion.html#auth-requirements + //Normalize fields based on Snapchat Data Hygiene https://marketingapi.snapchat.com/docs/conversion.html#data-hygiene if (payload.email) { //Removes all leading and trailing whitespace and converts all characters to lowercase. payload.email = payload.email.replace(/\s/g, '').toLowerCase() From dd56b568c34934aca6178ce43f4af923f9196972 Mon Sep 17 00:00:00 2001 From: sebashine Date: Fri, 8 Sep 2023 17:32:34 +0200 Subject: [PATCH 10/11] feat: include feedback regarding default rules --- .../snap-capi-properties.ts | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts index 712644d694..cb63980c48 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/snap-capi-properties.ts @@ -551,37 +551,79 @@ export const click_id: InputField = { export const first_name: InputField = { label: 'First name', description: 'First name of the converted user.', - type: 'string' + type: 'string', + default: { + '@if': { + exists: { '@path': '$.context.traits.first_name' }, + then: { '@path': '$.context.traits.first_name' }, + else: { '@path': '$.properties.first_name' } + } + } } export const middle_name: InputField = { label: 'Middle name', description: 'Middle name of the converted user.', - type: 'string' + type: 'string', + default: { + '@if': { + exists: { '@path': '$.context.traits.middle_name' }, + then: { '@path': '$.context.traits.middle_name' }, + else: { '@path': '$.properties.middle_name' } + } + } } export const last_name: InputField = { label: 'Last name', description: 'Last name of the converted user.', - type: 'string' + type: 'string', + default: { + '@if': { + exists: { '@path': '$.context.traits.last_name' }, + then: { '@path': '$.context.traits.last_name' }, + else: { '@path': '$.properties.last_name' } + } + } } export const city: InputField = { label: 'City', description: 'City associated with the conversion.', - type: 'string' + type: 'string', + default: { + '@if': { + exists: { '@path': '$.context.traits.address.city' }, + then: { '@path': '$.context.traits.address.city' }, + else: { '@path': '$.properties.address.city' } + } + } } export const state: InputField = { label: 'State', description: 'State or region associated with the conversion.', - type: 'string' + type: 'string', + default: { + '@if': { + exists: { '@path': '$.context.traits.address.state' }, + then: { '@path': '$.context.traits.address.state' }, + else: { '@path': '$.properties.address.state' } + } + } } export const zip: InputField = { label: 'Zip', description: 'Zip or postal code associated with the conversion.', - type: 'string' + type: 'string', + default: { + '@if': { + exists: { '@path': '$.context.traits.address.postalCode' }, + then: { '@path': '$.context.traits.address.postalCode' }, + else: { '@path': '$.properties.address.postalCode' } + } + } } export const dob_month: InputField = { @@ -607,7 +649,14 @@ export const region: InputField = { label: 'Region', description: 'State or region associated with the conversion. If the country is `US`, provide a two letter State code (`CA`, `WA`), otherwise provide the full region name.', - type: 'string' + type: 'string', + default: { + '@if': { + exists: { '@path': '$.context.traits.address.region' }, + then: { '@path': '$.context.traits.address.region' }, + else: { '@path': '$.properties.address.region' } + } + } } //Check to see what ids need to be passed depending on the event_conversion_type From aaad210e5d35b338e5ba290b4d33df73880fffd9 Mon Sep 17 00:00:00 2001 From: sebashine Date: Fri, 8 Sep 2023 17:48:02 +0200 Subject: [PATCH 11/11] test: use default values --- .../_tests_/index.test.ts | 86 ++++++++----------- 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts index 36b09d4fea..c60f4e204b 100644 --- a/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-conversions-api/_tests_/index.test.ts @@ -2,13 +2,6 @@ import nock from 'nock' import { createTestEvent, createTestIntegration } from '@segment/actions-core' import Definition from '../index' import { Settings } from '../generated-types' -import { defaultValues } from '@segment/actions-core' - -import reportConversionEvent from '../reportConversionEvent' - -const DEFAULT_VALS = { - ...defaultValues(reportConversionEvent.fields) -} const testDestination = createTestIntegration(Definition) const timestamp = '2022-05-12T15:21:15.449Z' @@ -206,7 +199,9 @@ describe('Snap Conversions API ', () => { const event = createTestEvent({ ...testEvent, properties: { - country: 'United States of America' + address: { + country: 'United States of America' + } } }) @@ -214,16 +209,15 @@ describe('Snap Conversions API ', () => { testDestination.testAction('reportConversionEvent', { event, settings, - useDefaultMappings: false, + useDefaultMappings: true, auth: { accessToken, refreshToken }, mapping: { - ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', - country: { '@path': '$.properties.country' } + country: { '@path': '$.properties.address.country' } } }) ).rejects.toThrowError( @@ -237,8 +231,10 @@ describe('Snap Conversions API ', () => { const event = createTestEvent({ ...testEvent, properties: { - country: 'US', - region: 'California' + address: { + country: 'US', + region: 'California' + } } }) @@ -246,17 +242,15 @@ describe('Snap Conversions API ', () => { testDestination.testAction('reportConversionEvent', { event, settings, - useDefaultMappings: false, + useDefaultMappings: true, auth: { accessToken, refreshToken }, mapping: { - ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', - country: { '@path': '$.properties.country' }, - region: { '@path': '$.properties.region' } + country: { '@path': '$.properties.address.country' } } }) ).rejects.toThrowError( @@ -270,24 +264,24 @@ describe('Snap Conversions API ', () => { const event = createTestEvent({ ...testEvent, properties: { - country: 'US' + address: { + country: 'US' + } } }) const responses = await testDestination.testAction('reportConversionEvent', { event, settings, - useDefaultMappings: false, + useDefaultMappings: true, auth: { accessToken, refreshToken }, mapping: { - ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', - country: { '@path': '$.properties.country' }, - region: { '@path': '$.properties.region' } + country: { '@path': '$.properties.address.country' } } }) @@ -305,25 +299,25 @@ describe('Snap Conversions API ', () => { const event = createTestEvent({ ...testEvent, properties: { - country: 'US', - region: 'CA' + address: { + country: 'US', + region: 'CA' + } } }) const responses = await testDestination.testAction('reportConversionEvent', { event, settings, - useDefaultMappings: false, + useDefaultMappings: true, auth: { accessToken, refreshToken }, mapping: { - ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', - country: { '@path': '$.properties.country' }, - region: { '@path': '$.properties.region' } + country: { '@path': '$.properties.address.country' } } }) @@ -341,25 +335,25 @@ describe('Snap Conversions API ', () => { const event = createTestEvent({ ...testEvent, properties: { - country: 'FR', - region: 'Hauts-de-France' + address: { + country: 'FR', + region: 'Hauts-de-France' + } } }) const responses = await testDestination.testAction('reportConversionEvent', { event, settings, - useDefaultMappings: false, + useDefaultMappings: true, auth: { accessToken, refreshToken }, mapping: { - ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', - country: { '@path': '$.properties.country' }, - region: { '@path': '$.properties.region' } + country: { '@path': '$.properties.address.country' } } }) @@ -589,39 +583,33 @@ describe('Snap Conversions API ', () => { first_name: 'John', middle_name: 'Middle', last_name: 'Doe', - city: 'Santa Monica', - state: 'CA', - zip: '90405', dob_month: 'January', dob_day: '26', - country: 'US', - region: 'CA' + address: { + city: 'Santa Monica', + country: 'US', + postalCode: '90405', + region: 'CA', + state: 'CA' + } } }) const responses = await testDestination.testAction('reportConversionEvent', { event, settings, - useDefaultMappings: false, + useDefaultMappings: true, auth: { accessToken, refreshToken }, mapping: { - ...DEFAULT_VALS, event_type: 'PURCHASE', event_conversion_type: 'WEB', idfv: { '@path': '$.properties.idfv' }, - first_name: { '@path': '$.properties.first_name' }, - middle_name: { '@path': '$.properties.middle_name' }, - last_name: { '@path': '$.properties.last_name' }, - city: { '@path': '$.properties.city' }, - state: { '@path': '$.properties.state' }, - zip: { '@path': '$.properties.zip' }, dob_month: { '@path': '$.properties.dob_month' }, dob_day: { '@path': '$.properties.dob_day' }, - country: { '@path': '$.properties.country' }, - region: { '@path': '$.properties.region' } + country: { '@path': '$.properties.address.country' } } })