diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz new file mode 100644 index 0000000000..096bebd182 Binary files /dev/null and b/.yarn/install-state.gz differ diff --git a/.yarnrc.yml b/.yarnrc.yml new file mode 100644 index 0000000000..3186f3f079 --- /dev/null +++ b/.yarnrc.yml @@ -0,0 +1 @@ +nodeLinker: node-modules diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/__snapshots__/snapshot.test.ts.snap index fa60a344cb..b8f5e78ddf 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/__snapshots__/snapshot.test.ts.snap @@ -35,6 +35,7 @@ Object { "email": "8614950525b98787b31febe07634987a801175f098b60c83bd3903bff1ec3eed", "external_id": "4fbe858b31ee34144cc3d009fd4636ef20fb342e095570d49a9898bb8d77598e", "ip_address": "4fbe858b31ee34144cc3d009fd4636ef20fb342e095570d49a9898bb8d77598e", + "phone_number": "781a379f97f79178f343a118a245e179b55a414b1b959ef25376dcb43bfe61f6", "screen_dimensions": Object { "height": -2840640572358656, "width": -2840640572358656, @@ -103,6 +104,7 @@ Object { "email": "6ad9c50c3cf54b266add9d94147959c9b024ebf821a18f6e860a01ad33a7b5cf", "external_id": "f136d03523cc17ecdfe2a4df68a819e5e98f6981316b7e50e1a8b34b018c70ae", "ip_address": "f136d03523cc17ecdfe2a4df68a819e5e98f6981316b7e50e1a8b34b018c70ae", + "phone_number": "db9c091a18bca5d3be200aa53617d73b2c6ed4fd88b2f7990f1b79bd139aef4f", "screen_dimensions": Object { "height": 2091000289820672, "width": 2091000289820672, diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/index.test.ts b/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/index.test.ts index 6391488b11..eb97ea50d7 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/__tests__/index.test.ts @@ -30,7 +30,8 @@ describe('Reddit Conversions Api', () => { { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } ], - email: 'test@test.com' + email: 'test@test.com', + phone: '1-650-555 - 1212 x450' }, context: { userAgent: 'test-user-agent', @@ -85,7 +86,8 @@ describe('Reddit Conversions Api', () => { external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', user_agent: 'test-user-agent', - uuid: 'uuid_1' + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' } } ], @@ -111,7 +113,8 @@ describe('Reddit Conversions Api', () => { { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } ], - email: '388c735eec8225c4ad7a507944dd0a975296baea383198aa87177f29af2c6f69' + email: '388c735eec8225c4ad7a507944dd0a975296baea383198aa87177f29af2c6f69', + phone: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' }, context: { userAgent: 'test-user-agent', @@ -166,7 +169,8 @@ describe('Reddit Conversions Api', () => { external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', user_agent: 'test-user-agent', - uuid: 'uuid_1' + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' } } ], @@ -195,7 +199,8 @@ describe('Reddit Conversions Api', () => { { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } ], - email: 'test@test.com' + email: 'test@test.com', + phone: '1-650-555 - 1212 x450' }, context: { userAgent: 'test-user-agent', @@ -249,7 +254,8 @@ describe('Reddit Conversions Api', () => { external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', user_agent: 'test-user-agent', - uuid: 'uuid_1' + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' } } ], @@ -281,6 +287,9 @@ describe('Reddit Conversions Api', () => { ip: '111.111.111.111', device: { advertisingId: 'advertising_id_1' + }, + traits: { + phone: '+1 (650)555-1212' } } }) @@ -327,7 +336,8 @@ describe('Reddit Conversions Api', () => { external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', user_agent: 'test-user-agent', - uuid: 'uuid_1' + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' } } ], @@ -488,5 +498,413 @@ describe('Reddit Conversions Api', () => { test_mode: false }) }) + + it('it should hash and pass standard phone number with + (ex: +1 (650)555-1212)', async () => { + const event = createTestEvent({ + timestamp: timestamp, + event: 'Lead Generated', + messageId: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + type: 'track', + userId: 'user_id_1', + properties: { + click_id: 'click_id_1', + currency: 'USD', + total: 100, + uuid: 'uuid_1', + products: [ + { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, + { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } + ], + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a' + }, + context: { + userAgent: 'test-user-agent', + ip: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + device: { + advertisingId: 'advertising_id_1' + }, + traits: { + phone: '+1 (650)555-1212' + } + } + }) + + nock('https://ads-api.reddit.com').post('/api/v2.0/conversions/events/ad_account_id_1').reply(200, {}) + const responses = await testDestination.testAction('standardEvent', { + event, + settings, + useDefaultMappings: true, + mapping: { + tracking_type: 'Lead' + } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].options.json).toMatchObject({ + events: [ + { + click_id: 'click_id_1', + event_at: '2024-01-08T13:52:50.212Z', + event_metadata: { + conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + currency: 'USD', + products: [ + { + category: 'category_1', + id: 'product_id_1', + name: 'name_1' + }, + { + category: 'category_2', + id: 'product_id_2', + name: 'name_2' + } + ], + value_decimal: 100 + }, + event_type: { + tracking_type: 'Lead' + }, + user: { + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a', + external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', + ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + user_agent: 'test-user-agent', + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' + } + } + ], + partner: 'SEGMENT', + test_mode: false + }) + }) + + it('it should hash and pass standard phone number with no + and hash to same value as with a + (ex: 1-650-555-1212)', async () => { + const event = createTestEvent({ + timestamp: timestamp, + event: 'Lead Generated', + messageId: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + type: 'track', + userId: 'user_id_1', + properties: { + click_id: 'click_id_1', + currency: 'USD', + total: 100, + uuid: 'uuid_1', + products: [ + { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, + { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } + ], + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a', + phone: '1-650-555-1212' + }, + context: { + userAgent: 'test-user-agent', + ip: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + device: { + advertisingId: 'advertising_id_1' + } + } + }) + + nock('https://ads-api.reddit.com').post('/api/v2.0/conversions/events/ad_account_id_1').reply(200, {}) + const responses = await testDestination.testAction('standardEvent', { + event, + settings, + useDefaultMappings: true, + mapping: { + tracking_type: 'Lead' + } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].options.json).toMatchObject({ + events: [ + { + click_id: 'click_id_1', + event_at: '2024-01-08T13:52:50.212Z', + event_metadata: { + conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + currency: 'USD', + products: [ + { + category: 'category_1', + id: 'product_id_1', + name: 'name_1' + }, + { + category: 'category_2', + id: 'product_id_2', + name: 'name_2' + } + ], + value_decimal: 100 + }, + event_type: { + tracking_type: 'Lead' + }, + user: { + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a', + external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', + ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + user_agent: 'test-user-agent', + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' + } + } + ], + partner: 'SEGMENT', + test_mode: false + }) + }) + + it('it should hash and pass phone number with no + and hash to same value as with a + (ex: 1-650-555-1212)', async () => { + const event = createTestEvent({ + timestamp: timestamp, + event: 'Lead Generated', + messageId: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + type: 'track', + userId: 'user_id_1', + properties: { + click_id: 'click_id_1', + currency: 'USD', + total: 100, + uuid: 'uuid_1', + products: [ + { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, + { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } + ], + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a' + }, + context: { + userAgent: 'test-user-agent', + ip: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + device: { + advertisingId: 'advertising_id_1' + }, + traits: { + phone: '1-650-555-1212' + } + } + }) + + nock('https://ads-api.reddit.com').post('/api/v2.0/conversions/events/ad_account_id_1').reply(200, {}) + const responses = await testDestination.testAction('standardEvent', { + event, + settings, + useDefaultMappings: true, + mapping: { + tracking_type: 'Lead' + } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].options.json).toMatchObject({ + events: [ + { + click_id: 'click_id_1', + event_at: '2024-01-08T13:52:50.212Z', + event_metadata: { + conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + currency: 'USD', + products: [ + { + category: 'category_1', + id: 'product_id_1', + name: 'name_1' + }, + { + category: 'category_2', + id: 'product_id_2', + name: 'name_2' + } + ], + value_decimal: 100 + }, + event_type: { + tracking_type: 'Lead' + }, + user: { + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a', + external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', + ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + user_agent: 'test-user-agent', + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' + } + } + ], + partner: 'SEGMENT', + test_mode: false + }) + }) + + it('it should hash and pass phone number with extension and malformed (1-(650)-555 - 1212 ExT 450) ', async () => { + const event = createTestEvent({ + timestamp: timestamp, + event: 'Lead Generated', + messageId: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + type: 'track', + userId: 'user_id_1', + properties: { + click_id: 'click_id_1', + currency: 'USD', + total: 100, + uuid: 'uuid_1', + products: [ + { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, + { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } + ], + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a' + }, + context: { + userAgent: 'test-user-agent', + ip: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + device: { + advertisingId: 'advertising_id_1' + }, + traits: { + phone: '1-(650)-555 - 1212 ExT 450' + } + } + }) + + nock('https://ads-api.reddit.com').post('/api/v2.0/conversions/events/ad_account_id_1').reply(200, {}) + const responses = await testDestination.testAction('standardEvent', { + event, + settings, + useDefaultMappings: true, + mapping: { + tracking_type: 'Lead' + } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].options.json).toMatchObject({ + events: [ + { + click_id: 'click_id_1', + event_at: '2024-01-08T13:52:50.212Z', + event_metadata: { + conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + currency: 'USD', + products: [ + { + category: 'category_1', + id: 'product_id_1', + name: 'name_1' + }, + { + category: 'category_2', + id: 'product_id_2', + name: 'name_2' + } + ], + value_decimal: 100 + }, + event_type: { + tracking_type: 'Lead' + }, + user: { + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a', + external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', + ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + user_agent: 'test-user-agent', + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' + } + } + ], + partner: 'SEGMENT', + test_mode: false + }) + }) + + it('it should hash and pass phone number with another extension type (1-650-555 - 1212 x450) ', async () => { + const event = createTestEvent({ + timestamp: timestamp, + event: 'Lead Generated', + messageId: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + type: 'track', + userId: 'user_id_1', + properties: { + click_id: 'click_id_1', + currency: 'USD', + total: 100, + uuid: 'uuid_1', + products: [ + { product_id: 'product_id_1', category: 'category_1', name: 'name_1' }, + { product_id: 'product_id_2', category: 'category_2', name: 'name_2' } + ], + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a' + }, + context: { + userAgent: 'test-user-agent', + ip: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + device: { + advertisingId: 'advertising_id_1' + }, + traits: { + phone: '1-650-555 - 1212 x450' + } + } + }) + + nock('https://ads-api.reddit.com').post('/api/v2.0/conversions/events/ad_account_id_1').reply(200, {}) + const responses = await testDestination.testAction('standardEvent', { + event, + settings, + useDefaultMappings: true, + mapping: { + tracking_type: 'Lead' + } + }) + + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].options.json).toMatchObject({ + events: [ + { + click_id: 'click_id_1', + event_at: '2024-01-08T13:52:50.212Z', + event_metadata: { + conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375', + currency: 'USD', + products: [ + { + category: 'category_1', + id: 'product_id_1', + name: 'name_1' + }, + { + category: 'category_2', + id: 'product_id_2', + name: 'name_2' + } + ], + value_decimal: 100 + }, + event_type: { + tracking_type: 'Lead' + }, + user: { + email: 'f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a', + external_id: '3482ae91c8ec52c06e19d618d400b3985814bf705e00947a302ec849a6575c4c', + ip_address: '5feaf188de296cd3b17f7c66fd3a2aec9b694815f2b1180631f7b52f57029777', + user_agent: 'test-user-agent', + uuid: 'uuid_1', + phone_number: '1e231c66011e7a2d867a9cfae267a6aff103cf4913640b6e71a99850fc0ffbc8' + } + } + ], + partner: 'SEGMENT', + test_mode: false + }) + }) }) }) diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/__tests__/__snapshots__/snapshot.test.ts.snap index 5101a4ecca..1b31890df1 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/__tests__/__snapshots__/snapshot.test.ts.snap @@ -35,6 +35,7 @@ Object { "email": "4a032ff520e2ddbb4f3467c73e41b1f94bda5faf9c9080ac7f0d0e83156d9c99", "external_id": "7b1d43d3d43059efd3e755045cf79aa9a554bc456f4c10d1915ccb5d79345b4a", "ip_address": "7b1d43d3d43059efd3e755045cf79aa9a554bc456f4c10d1915ccb5d79345b4a", + "phone_number": "6a43002a7e3d5a65a03938155afe5c3df3518817c33969ec4b221c0b939af821", "screen_dimensions": Object { "height": 8361377294974976, "width": 8361377294974976, diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/generated-types.ts b/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/generated-types.ts index a3e7656f2e..4c5db62be1 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/customEvent/generated-types.ts @@ -62,6 +62,10 @@ export interface Payload { * The value from the first-party Pixel '_rdt_uuid' cookie on your domain. Note that it is in the '{timestamp}.{uuid}' format. You may use the full value or just the UUID portion. */ uuid?: string + /** + * The phone number of the user in E.164 standard format. + */ + phone_number?: string } /** * A structure of data processing options to specify the processing type for the event. diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/fields.ts b/packages/destination-actions/src/destinations/reddit-conversions-api/fields.ts index d58e44315b..2304c753f7 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/fields.ts +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/fields.ts @@ -192,6 +192,11 @@ export const user: InputField = { description: "The value from the first-party Pixel '_rdt_uuid' cookie on your domain. Note that it is in the '{timestamp}.{uuid}' format. You may use the full value or just the UUID portion.", type: 'string' + }, + phone_number: { + label: 'Phone Number', + description: 'The phone number of the user in E.164 standard format.', + type: 'string' } }, default: { @@ -219,6 +224,13 @@ export const user: InputField = { then: { '@path': '$.integrations.Reddit Conversions Api.uuid' }, else: { '@path': '$.properties.uuid' } } + }, + phone_number: { + '@if': { + exists: { '@path': '$.context.traits.phone' }, + then: { '@path': '$.context.traits.phone' }, + else: { '@path': '$.properties.phone' } + } } } } diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/__tests__/__snapshots__/snapshot.test.ts.snap index 0f4f42cba5..52e9104850 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/__tests__/__snapshots__/snapshot.test.ts.snap @@ -34,6 +34,7 @@ Object { "email": "b6887231da112cb08515e502cb0eb06a342f2efb3372c2841368397664844f4e", "external_id": "7da4d4522d67f6ca1c1b0654c2d91c916a22667a5d34fa75c7cdcbe0c1b452ce", "ip_address": "7da4d4522d67f6ca1c1b0654c2d91c916a22667a5d34fa75c7cdcbe0c1b452ce", + "phone_number": "2ee39c8e2045a413583b724baadec9219db2f5e1406263c1af764d56ccdca13d", "screen_dimensions": Object { "height": 8501184792887296, "width": 8501184792887296, diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/generated-types.ts b/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/generated-types.ts index 57e6100f0e..82d3f61f89 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/standardEvent/generated-types.ts @@ -62,6 +62,10 @@ export interface Payload { * The value from the first-party Pixel '_rdt_uuid' cookie on your domain. Note that it is in the '{timestamp}.{uuid}' format. You may use the full value or just the UUID portion. */ uuid?: string + /** + * The phone number of the user in E.164 standard format. + */ + phone_number?: string } /** * A structure of data processing options to specify the processing type for the event. diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/types.ts b/packages/destination-actions/src/destinations/reddit-conversions-api/types.ts index f7588d00f2..e9a6ca9f5f 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/types.ts +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/types.ts @@ -42,6 +42,7 @@ export interface User { height?: number width?: number } + phone_number?: string } export interface StandardEventPayloadItem { diff --git a/packages/destination-actions/src/destinations/reddit-conversions-api/utils.ts b/packages/destination-actions/src/destinations/reddit-conversions-api/utils.ts index 3643dc098e..32a4c441f1 100644 --- a/packages/destination-actions/src/destinations/reddit-conversions-api/utils.ts +++ b/packages/destination-actions/src/destinations/reddit-conversions-api/utils.ts @@ -152,7 +152,8 @@ function getUser( user_agent: clean(user.user_agent), uuid: clean(user.uuid), data_processing_options: getDataProcessingOptions(dataProcessingOptions), - screen_dimensions: getScreen(screenDimensions?.height, screenDimensions?.width) + screen_dimensions: getScreen(screenDimensions?.height, screenDimensions?.width), + phone_number: smartHash(user.phone_number, cleanPhoneNumber) } } @@ -163,7 +164,41 @@ function canonicalizeEmail(value: string): string { return `${localPart.toLowerCase()}@${localPartAndDomain[1].toLowerCase()}` } -const smartHash = (value: string | undefined, cleaningFunction?: (value: string) => string): string | undefined => { +const smartHash = ( + value: string | undefined, + cleaningFunction?: (value: string) => string | undefined +): string | undefined => { if (value === undefined) return - return processHashing(value, 'sha256', 'hex', cleaningFunction) + const cleaned = cleaningFunction ? cleaningFunction(value) : value + if (cleaned === undefined) return + + return processHashingV2(cleaned, 'sha256', 'hex') +} + +function cleanPhoneNumber(phoneNumber: string): string | undefined { + if (!phoneNumber) return undefined + // Remove leading and trailing whitespace + phoneNumber = phoneNumber.trim() + + // Separate the leading "+" character, if present + const prefix = '+' + if (phoneNumber.startsWith('+')) { + phoneNumber = phoneNumber.slice(1) + } + + // Remove any potential extensions from the number + const extensions = ['ext', 'x', 'anexo', '#', 'poste', 'int'] + const lower = phoneNumber.toLowerCase() + for (const keyword of extensions) { + const index = lower.indexOf(keyword) + if (index !== -1) { + phoneNumber = phoneNumber.slice(0, index) + break + } + } + + // Add the prefix and remove all non-numeric characters + const digitsOnly = phoneNumber.replace(/\D/g, '') + + return prefix + digitsOnly }