-
Notifications
You must be signed in to change notification settings - Fork 275
[Facebook Conversions] Adding Test Event Code to all mappings. #2516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joe-ayoub-segment
merged 3 commits into
main
from
facebook-conversions-event-tester-in-mapping
Nov 12, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.