-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Facebook Conversions] Adding Test Event Code to all mappings. (#2516)
* [Facebook CAPI] Adding Test Event Code to all mappings. * Adding corresponding unit tests.
- Loading branch information
1 parent
a2ef07c
commit 5e76015
Showing
45 changed files
with
1,000 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,6 +484,65 @@ describe('FacebookConversionsApi', () => { | |
) | ||
}) | ||
|
||
it('should send test_event_code if present in the mapping', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
const event = createTestEvent({ | ||
event: 'Product Added', | ||
userId: 'abc123', | ||
timestamp: '1631210000', | ||
properties: { | ||
action_source: 'email', | ||
currency: 'USD', | ||
value: 12.12, | ||
email: '[email protected]', | ||
traits: { | ||
city: 'Gotham', | ||
country: 'United States', | ||
last_name: 'Wayne' | ||
}, | ||
test_event_code: '2345678901' | ||
} | ||
}) | ||
|
||
const responses = await testDestination.testAction('addToCart', { | ||
event, | ||
settings: settings, | ||
mapping: { | ||
currency: { | ||
'@path': '$.properties.currency' | ||
}, | ||
value: { | ||
'@path': '$.properties.value' | ||
}, | ||
user_data: { | ||
email: { | ||
'@path': '$.properties.email' | ||
} | ||
}, | ||
action_source: { | ||
'@path': '$.properties.action_source' | ||
}, | ||
event_time: { | ||
'@path': '$.timestamp' | ||
}, | ||
custom_data: { | ||
'@path': '$.properties.traits' | ||
}, | ||
test_event_code: { | ||
'@path': '$.properties.test_event_code' | ||
} | ||
} | ||
}) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"data\\":[{\\"event_name\\":\\"AddToCart\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\"},\\"custom_data\\":{\\"city\\":\\"Gotham\\",\\"country\\":\\"United States\\",\\"last_name\\":\\"Wayne\\",\\"currency\\":\\"USD\\",\\"value\\":12.12}}],\\"test_event_code\\":\\"2345678901\\"}"` | ||
) | ||
}) | ||
|
||
it('should send app events without anon_id and madId using default mappings correctly', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,6 +536,66 @@ describe('FacebookConversionsApi', () => { | |
) | ||
}) | ||
|
||
it('should send test_event_code if present in the mapping', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
const event = createTestEvent({ | ||
event: 'Product Added', | ||
userId: 'abc123', | ||
timestamp: '1631210000', | ||
properties: { | ||
action_source: 'email', | ||
currency: 'USD', | ||
value: 12.12, | ||
email: '[email protected]', | ||
traits: { | ||
city: 'Gotham', | ||
country: 'United States', | ||
last_name: 'Wayne' | ||
}, | ||
test_event_code: '2345678901' | ||
} | ||
}) | ||
|
||
const responses = await testDestination.testAction('addToCart2', { | ||
event, | ||
settings: settingsWithTestEventCode, | ||
mapping: { | ||
__segment_internal_sync_mode: 'add', | ||
currency: { | ||
'@path': '$.properties.currency' | ||
}, | ||
value: { | ||
'@path': '$.properties.value' | ||
}, | ||
user_data: { | ||
email: { | ||
'@path': '$.properties.email' | ||
} | ||
}, | ||
action_source: { | ||
'@path': '$.properties.action_source' | ||
}, | ||
event_time: { | ||
'@path': '$.timestamp' | ||
}, | ||
custom_data: { | ||
'@path': '$.properties.traits' | ||
}, | ||
test_event_code: { | ||
'@path': '$.properties.test_event_code' | ||
} | ||
} | ||
}) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"data\\":[{\\"event_name\\":\\"AddToCart\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\"},\\"custom_data\\":{\\"city\\":\\"Gotham\\",\\"country\\":\\"United States\\",\\"last_name\\":\\"Wayne\\",\\"currency\\":\\"USD\\",\\"value\\":12.12}}],\\"test_event_code\\":\\"2345678901\\"}"` | ||
) | ||
}) | ||
|
||
it('should send app events using default mappings correctly', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,5 +227,63 @@ describe('FacebookConversionsApi', () => { | |
`"{\\"data\\":[{\\"event_name\\":\\"identify\\",\\"event_time\\":\\"2015-02-23T22:28:55.111Z\\",\\"action_source\\":\\"website\\",\\"event_id\\":\\"022bb90c-bbac-11e4-8dfc-aa07a5b093db\\",\\"user_data\\":{\\"external_id\\":[\\"df73b86ff613b9d7008c175ae3c3aa3f2c1ea1674a80cac85274d58048e44127\\"],\\"client_ip_address\\":\\"8.8.8.8\\",\\"client_user_agent\\":\\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36\\"},\\"custom_data\\":{\\"action_source\\":\\"website\\",\\"timestamp\\":\\"1633473963\\"}}],\\"test_event_code\\":\\"1234567890\\"}"` | ||
) | ||
}) | ||
|
||
it('should send test_event_code if present in the mapping', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
const event = createTestEvent({ | ||
anonymousId: '507f191e810c19729de860ea', | ||
context: { | ||
ip: '8.8.8.8', | ||
userAgent: | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36' | ||
}, | ||
messageId: '022bb90c-bbac-11e4-8dfc-aa07a5b093db', | ||
receivedAt: '2015-02-23T22:28:55.387Z', | ||
sentAt: '2015-02-23T22:28:55.111Z', | ||
timestamp: '2015-02-23T22:28:55.111Z', | ||
traits: { | ||
name: 'Peter Gibbons', | ||
email: '[email protected]', | ||
plan: 'premium', | ||
logins: 5, | ||
address: { | ||
street: '6th St', | ||
city: 'San Francisco', | ||
state: 'CA', | ||
postalCode: '94103', | ||
country: 'USA' | ||
} | ||
}, | ||
properties: { | ||
action_source: 'website', | ||
timestamp: '1633473963', | ||
test_event_code: '2345678901' | ||
}, | ||
type: 'identify', | ||
userId: '97980cfea0067', | ||
event: 'identify' | ||
}) | ||
|
||
const responses = await testDestination.testAction('custom', { | ||
event, | ||
settings: settingsWithTestEventCode, | ||
useDefaultMappings: true, | ||
mapping: { | ||
action_source: { '@path': '$.properties.action_source' }, | ||
custom_data: { '@path': '$.properties' }, | ||
test_event_code: { | ||
'@path': '$.properties.test_event_code' | ||
} | ||
} | ||
}) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"data\\":[{\\"event_name\\":\\"identify\\",\\"event_time\\":\\"2015-02-23T22:28:55.111Z\\",\\"action_source\\":\\"website\\",\\"event_id\\":\\"022bb90c-bbac-11e4-8dfc-aa07a5b093db\\",\\"user_data\\":{\\"external_id\\":[\\"df73b86ff613b9d7008c175ae3c3aa3f2c1ea1674a80cac85274d58048e44127\\"],\\"client_ip_address\\":\\"8.8.8.8\\",\\"client_user_agent\\":\\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36\\"},\\"custom_data\\":{\\"action_source\\":\\"website\\",\\"timestamp\\":\\"1633473963\\",\\"test_event_code\\":\\"2345678901\\"}}],\\"test_event_code\\":\\"2345678901\\"}"` | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,5 +266,64 @@ describe('FacebookConversionsApi', () => { | |
`"{\\"data\\":[{\\"event_name\\":\\"identify\\",\\"event_time\\":\\"2015-02-23T22:28:55.111Z\\",\\"action_source\\":\\"website\\",\\"event_id\\":\\"022bb90c-bbac-11e4-8dfc-aa07a5b093db\\",\\"user_data\\":{\\"external_id\\":[\\"df73b86ff613b9d7008c175ae3c3aa3f2c1ea1674a80cac85274d58048e44127\\"],\\"client_ip_address\\":\\"8.8.8.8\\",\\"client_user_agent\\":\\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36\\"},\\"custom_data\\":{\\"action_source\\":\\"website\\",\\"timestamp\\":\\"1633473963\\"}}],\\"test_event_code\\":\\"1234567890\\"}"` | ||
) | ||
}) | ||
|
||
it('should send test_event_code if present in the mapping', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
const event = createTestEvent({ | ||
anonymousId: '507f191e810c19729de860ea', | ||
context: { | ||
ip: '8.8.8.8', | ||
userAgent: | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36' | ||
}, | ||
messageId: '022bb90c-bbac-11e4-8dfc-aa07a5b093db', | ||
receivedAt: '2015-02-23T22:28:55.387Z', | ||
sentAt: '2015-02-23T22:28:55.111Z', | ||
timestamp: '2015-02-23T22:28:55.111Z', | ||
traits: { | ||
name: 'Peter Gibbons', | ||
email: '[email protected]', | ||
plan: 'premium', | ||
logins: 5, | ||
address: { | ||
street: '6th St', | ||
city: 'San Francisco', | ||
state: 'CA', | ||
postalCode: '94103', | ||
country: 'USA' | ||
} | ||
}, | ||
properties: { | ||
action_source: 'website', | ||
timestamp: '1633473963', | ||
test_event_code: '2345678901' | ||
}, | ||
type: 'identify', | ||
userId: '97980cfea0067', | ||
event: 'identify' | ||
}) | ||
|
||
const responses = await testDestination.testAction('custom2', { | ||
event, | ||
settings: settingsWithTestEventCode, | ||
useDefaultMappings: true, | ||
mapping: { | ||
__segment_internal_sync_mode: 'add', | ||
action_source: { '@path': '$.properties.action_source' }, | ||
custom_data: { '@path': '$.properties' }, | ||
test_event_code: { | ||
'@path': '$.properties.test_event_code' | ||
} | ||
} | ||
}) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"data\\":[{\\"event_name\\":\\"identify\\",\\"event_time\\":\\"2015-02-23T22:28:55.111Z\\",\\"action_source\\":\\"website\\",\\"event_id\\":\\"022bb90c-bbac-11e4-8dfc-aa07a5b093db\\",\\"user_data\\":{\\"external_id\\":[\\"df73b86ff613b9d7008c175ae3c3aa3f2c1ea1674a80cac85274d58048e44127\\"],\\"client_ip_address\\":\\"8.8.8.8\\",\\"client_user_agent\\":\\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36\\"},\\"custom_data\\":{\\"action_source\\":\\"website\\",\\"timestamp\\":\\"1633473963\\",\\"test_event_code\\":\\"2345678901\\"}}],\\"test_event_code\\":\\"2345678901\\"}"` | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,42 @@ describe('FacebookConversionsApi', () => { | |
) | ||
}) | ||
|
||
it('should send test_event_code if present in the mapping', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
const event = createTestEvent({ | ||
type: 'page', | ||
userId: 'abc123', | ||
timestamp: '1631210020', | ||
messageId: 'test', | ||
properties: { | ||
timestamp: 1631210000, | ||
action_source: 'email', | ||
email: '[email protected]', | ||
test_event_code: '2345678901' | ||
} | ||
}) | ||
|
||
const responses = await testDestination.testAction('pageView', { | ||
event, | ||
settings: settingsWithTestEventCode, | ||
useDefaultMappings: true, | ||
mapping: { | ||
action_source: { '@path': '$.properties.action_source' }, | ||
test_event_code: { | ||
'@path': '$.properties.test_event_code' | ||
} | ||
} | ||
}) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"data\\":[{\\"event_name\\":\\"PageView\\",\\"event_time\\":\\"1631210020\\",\\"action_source\\":\\"email\\",\\"event_source_url\\":\\"https://segment.com/academy/\\",\\"event_id\\":\\"test\\",\\"user_data\\":{\\"external_id\\":[\\"6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090\\"],\\"client_ip_address\\":\\"8.8.8.8\\",\\"client_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\\"}}],\\"test_event_code\\":\\"2345678901\\"}"` | ||
) | ||
}) | ||
|
||
it('should handle a basic event with multiple external Ids', async () => { | ||
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {}) | ||
|
||
|
Oops, something went wrong.