Skip to content

Commit 9238ca5

Browse files
committed
Add ctwa_clid in user data of fb conversions apis
1 parent d80fbf0 commit 9238ca5

30 files changed

+751
-2
lines changed

packages/destination-actions/src/destinations/facebook-conversions-api/__tests__/addToCart.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,5 +904,55 @@ describe('FacebookConversionsApi', () => {
904904
`"{\\"data\\":[{\\"event_name\\":\\"AddToCart\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\",\\"external_id\\":[\\"6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090\\",\\"f0a72890897acefdb2c6c8c06134339a73cc6205833ca38dba6f9fdc94b60596\\"],\\"partner_id\\":\\"faf12efasdfasdf1edasdasdfadf=\\",\\"partner_name\\":\\"liveramp\\"},\\"custom_data\\":{\\"city\\":\\"Gotham\\",\\"country\\":\\"United States\\",\\"last_name\\":\\"Wayne\\",\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
905905
)
906906
})
907+
908+
it('should include ctwa_clid in user_data', async () => {
909+
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {})
910+
911+
const event = createTestEvent({
912+
event: 'Product Added',
913+
userId: 'abc123',
914+
timestamp: '1631210000',
915+
properties: {
916+
action_source: 'email',
917+
currency: 'USD',
918+
value: 12.12,
919+
email: 'nicholas.aguilar@segment.com',
920+
ctwa_clid: 'test_ctwa_click_id_12345'
921+
}
922+
})
923+
924+
const responses = await testDestination.testAction('addToCart', {
925+
event,
926+
settings,
927+
mapping: {
928+
currency: {
929+
'@path': '$.properties.currency'
930+
},
931+
value: {
932+
'@path': '$.properties.value'
933+
},
934+
user_data: {
935+
email: {
936+
'@path': '$.properties.email'
937+
},
938+
ctwa_clid: {
939+
'@path': '$.properties.ctwa_clid'
940+
}
941+
},
942+
action_source: {
943+
'@path': '$.properties.action_source'
944+
},
945+
event_time: {
946+
'@path': '$.timestamp'
947+
}
948+
}
949+
})
950+
951+
expect(responses.length).toBe(1)
952+
expect(responses[0].status).toBe(201)
953+
expect(responses[0].options.body).toMatchInlineSnapshot(
954+
`"{\\"data\\":[{\\"event_name\\":\\"AddToCart\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\",\\"ctwa_clid\\":\\"test_ctwa_click_id_12345\\"},\\"custom_data\\":{\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
955+
)
956+
})
907957
})
908958
})

packages/destination-actions/src/destinations/facebook-conversions-api/__tests__/addToCart2.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,5 +961,56 @@ describe('FacebookConversionsApi', () => {
961961
`"{\\"data\\":[{\\"event_name\\":\\"AddToCart\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\",\\"external_id\\":[\\"6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090\\",\\"f0a72890897acefdb2c6c8c06134339a73cc6205833ca38dba6f9fdc94b60596\\"],\\"partner_id\\":\\"faf12efasdfasdf1edasdasdfadf=\\",\\"partner_name\\":\\"liveramp\\"},\\"custom_data\\":{\\"city\\":\\"Gotham\\",\\"country\\":\\"United States\\",\\"last_name\\":\\"Wayne\\",\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
962962
)
963963
})
964+
965+
it('should include ctwa_clid in user_data', async () => {
966+
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {})
967+
968+
const event = createTestEvent({
969+
event: 'Product Added',
970+
userId: 'abc123',
971+
timestamp: '1631210000',
972+
properties: {
973+
action_source: 'email',
974+
currency: 'USD',
975+
value: 12.12,
976+
email: 'nicholas.aguilar@segment.com',
977+
ctwa_clid: 'test_ctwa_click_id_12345'
978+
}
979+
})
980+
981+
const responses = await testDestination.testAction('addToCart2', {
982+
event,
983+
settings,
984+
mapping: {
985+
__segment_internal_sync_mode: 'add',
986+
currency: {
987+
'@path': '$.properties.currency'
988+
},
989+
value: {
990+
'@path': '$.properties.value'
991+
},
992+
user_data: {
993+
email: {
994+
'@path': '$.properties.email'
995+
},
996+
ctwa_clid: {
997+
'@path': '$.properties.ctwa_clid'
998+
}
999+
},
1000+
action_source: {
1001+
'@path': '$.properties.action_source'
1002+
},
1003+
event_time: {
1004+
'@path': '$.timestamp'
1005+
}
1006+
}
1007+
})
1008+
1009+
expect(responses.length).toBe(1)
1010+
expect(responses[0].status).toBe(201)
1011+
expect(responses[0].options.body).toMatchInlineSnapshot(
1012+
`"{\\"data\\":[{\\"event_name\\":\\"AddToCart\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\",\\"ctwa_clid\\":\\"test_ctwa_click_id_12345\\"},\\"custom_data\\":{\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
1013+
)
1014+
})
9641015
})
9651016
})

packages/destination-actions/src/destinations/facebook-conversions-api/__tests__/custom.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,54 @@ describe('FacebookConversionsApi', () => {
285285
`"{\\"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\\"}"`
286286
)
287287
})
288+
289+
it('should include ctwa_clid in user_data', async () => {
290+
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {})
291+
292+
const event = createTestEvent({
293+
event: 'custom_event',
294+
userId: 'abc123',
295+
timestamp: '1631210000',
296+
properties: {
297+
action_source: 'email',
298+
ctwa_clid: 'test_ctwa_click_id_12345'
299+
},
300+
context: {
301+
traits: {
302+
email: 'test@example.com'
303+
}
304+
}
305+
})
306+
307+
const responses = await testDestination.testAction('custom', {
308+
event,
309+
settings,
310+
mapping: {
311+
event_name: {
312+
'@path': '$.event'
313+
},
314+
action_source: {
315+
'@path': '$.properties.action_source'
316+
},
317+
event_time: {
318+
'@path': '$.timestamp'
319+
},
320+
user_data: {
321+
email: {
322+
'@path': '$.context.traits.email'
323+
},
324+
ctwa_clid: {
325+
'@path': '$.properties.ctwa_clid'
326+
}
327+
}
328+
}
329+
})
330+
331+
expect(responses.length).toBe(1)
332+
expect(responses[0].status).toBe(201)
333+
expect(responses[0].options.body).toMatchInlineSnapshot(
334+
`"{\\"data\\":[{\\"event_name\\":\\"custom_event\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b\\",\\"ctwa_clid\\":\\"test_ctwa_click_id_12345\\"}}]}"`
335+
)
336+
})
288337
})
289338
})

packages/destination-actions/src/destinations/facebook-conversions-api/__tests__/custom2.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,55 @@ describe('FacebookConversionsApi', () => {
325325
`"{\\"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\\"}"`
326326
)
327327
})
328+
329+
it('should include ctwa_clid in user_data', async () => {
330+
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {})
331+
332+
const event = createTestEvent({
333+
event: 'custom_event',
334+
userId: 'abc123',
335+
timestamp: '1631210000',
336+
properties: {
337+
action_source: 'email',
338+
ctwa_clid: 'test_ctwa_click_id_12345'
339+
},
340+
context: {
341+
traits: {
342+
email: 'test@example.com'
343+
}
344+
}
345+
})
346+
347+
const responses = await testDestination.testAction('custom2', {
348+
event,
349+
settings,
350+
mapping: {
351+
__segment_internal_sync_mode: 'add',
352+
event_name: {
353+
'@path': '$.event'
354+
},
355+
action_source: {
356+
'@path': '$.properties.action_source'
357+
},
358+
event_time: {
359+
'@path': '$.timestamp'
360+
},
361+
user_data: {
362+
email: {
363+
'@path': '$.context.traits.email'
364+
},
365+
ctwa_clid: {
366+
'@path': '$.properties.ctwa_clid'
367+
}
368+
}
369+
}
370+
})
371+
372+
expect(responses.length).toBe(1)
373+
expect(responses[0].status).toBe(201)
374+
expect(responses[0].options.body).toMatchInlineSnapshot(
375+
`"{\\"data\\":[{\\"event_name\\":\\"custom_event\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b\\",\\"ctwa_clid\\":\\"test_ctwa_click_id_12345\\"}}]}"`
376+
)
377+
})
328378
})
329379
})

packages/destination-actions/src/destinations/facebook-conversions-api/__tests__/initiateCheckout.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,55 @@ describe('FacebookConversionsApi', () => {
325325
`"{\\"data\\":[{\\"event_name\\":\\"InitiateCheckout\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\",\\"external_id\\":[\\"6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090\\",\\"f0a72890897acefdb2c6c8c06134339a73cc6205833ca38dba6f9fdc94b60596\\"],\\"partner_id\\":\\"faf12efasdfasdf1edasdasdfadf=\\",\\"partner_name\\":\\"liveramp\\"},\\"custom_data\\":{\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
326326
)
327327
})
328+
329+
it('should include ctwa_clid in user_data', async () => {
330+
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {})
331+
332+
const event = createTestEvent({
333+
event: 'Checkout Started',
334+
userId: 'abc123',
335+
timestamp: '1631210000',
336+
properties: {
337+
action_source: 'email',
338+
currency: 'USD',
339+
value: 12.12,
340+
email: 'test@example.com',
341+
ctwa_clid: 'test_ctwa_click_id_12345'
342+
}
343+
})
344+
345+
const responses = await testDestination.testAction('initiateCheckout', {
346+
event,
347+
settings,
348+
mapping: {
349+
currency: {
350+
'@path': '$.properties.currency'
351+
},
352+
value: {
353+
'@path': '$.properties.value'
354+
},
355+
user_data: {
356+
email: {
357+
'@path': '$.properties.email'
358+
},
359+
ctwa_clid: {
360+
'@path': '$.properties.ctwa_clid'
361+
}
362+
},
363+
action_source: {
364+
'@path': '$.properties.action_source'
365+
},
366+
event_time: {
367+
'@path': '$.timestamp'
368+
}
369+
}
370+
})
371+
372+
expect(responses.length).toBe(1)
373+
expect(responses[0].status).toBe(201)
374+
expect(responses[0].options.body).toMatchInlineSnapshot(
375+
`"{\\"data\\":[{\\"event_name\\":\\"InitiateCheckout\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b\\",\\"ctwa_clid\\":\\"test_ctwa_click_id_12345\\"},\\"custom_data\\":{\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
376+
)
377+
})
328378
})
329379
})

packages/destination-actions/src/destinations/facebook-conversions-api/__tests__/initiateCheckout2.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,56 @@ describe('FacebookConversionsApi', () => {
378378
`"{\\"data\\":[{\\"event_name\\":\\"InitiateCheckout\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"eeaf810ee0e3cef3307089f22c3804f54c79eed19ef29bf70df864b43862c380\\",\\"external_id\\":[\\"6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090\\",\\"f0a72890897acefdb2c6c8c06134339a73cc6205833ca38dba6f9fdc94b60596\\"],\\"partner_id\\":\\"faf12efasdfasdf1edasdasdfadf=\\",\\"partner_name\\":\\"liveramp\\"},\\"custom_data\\":{\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
379379
)
380380
})
381+
382+
it('should include ctwa_clid in user_data', async () => {
383+
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {})
384+
385+
const event = createTestEvent({
386+
event: 'Checkout Started',
387+
userId: 'abc123',
388+
timestamp: '1631210000',
389+
properties: {
390+
action_source: 'email',
391+
currency: 'USD',
392+
value: 12.12,
393+
email: 'test@example.com',
394+
ctwa_clid: 'test_ctwa_click_id_12345'
395+
}
396+
})
397+
398+
const responses = await testDestination.testAction('initiateCheckout2', {
399+
event,
400+
settings,
401+
mapping: {
402+
__segment_internal_sync_mode: 'add',
403+
currency: {
404+
'@path': '$.properties.currency'
405+
},
406+
value: {
407+
'@path': '$.properties.value'
408+
},
409+
user_data: {
410+
email: {
411+
'@path': '$.properties.email'
412+
},
413+
ctwa_clid: {
414+
'@path': '$.properties.ctwa_clid'
415+
}
416+
},
417+
action_source: {
418+
'@path': '$.properties.action_source'
419+
},
420+
event_time: {
421+
'@path': '$.timestamp'
422+
}
423+
}
424+
})
425+
426+
expect(responses.length).toBe(1)
427+
expect(responses[0].status).toBe(201)
428+
expect(responses[0].options.body).toMatchInlineSnapshot(
429+
`"{\\"data\\":[{\\"event_name\\":\\"InitiateCheckout\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b\\",\\"ctwa_clid\\":\\"test_ctwa_click_id_12345\\"},\\"custom_data\\":{\\"currency\\":\\"USD\\",\\"value\\":12.12}}]}"`
430+
)
431+
})
381432
})
382433
})

packages/destination-actions/src/destinations/facebook-conversions-api/__tests__/pageView.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,51 @@ describe('FacebookConversionsApi', () => {
265265
`"{\\"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\\",\\"f0a72890897acefdb2c6c8c06134339a73cc6205833ca38dba6f9fdc94b60596\\"]}}]}"`
266266
)
267267
})
268+
269+
it('should include ctwa_clid in user_data', async () => {
270+
nock(`https://graph.facebook.com/v${API_VERSION}/${settings.pixelId}`).post(`/events`).reply(201, {})
271+
272+
const event = createTestEvent({
273+
type: 'page',
274+
userId: 'abc123',
275+
timestamp: '1631210000',
276+
properties: {
277+
action_source: 'email',
278+
ctwa_clid: 'test_ctwa_click_id_12345'
279+
},
280+
context: {
281+
traits: {
282+
email: 'test@example.com'
283+
}
284+
}
285+
})
286+
287+
const responses = await testDestination.testAction('pageView', {
288+
event,
289+
settings,
290+
mapping: {
291+
user_data: {
292+
email: {
293+
'@path': '$.context.traits.email'
294+
},
295+
ctwa_clid: {
296+
'@path': '$.properties.ctwa_clid'
297+
}
298+
},
299+
action_source: {
300+
'@path': '$.properties.action_source'
301+
},
302+
event_time: {
303+
'@path': '$.timestamp'
304+
}
305+
}
306+
})
307+
308+
expect(responses.length).toBe(1)
309+
expect(responses[0].status).toBe(201)
310+
expect(responses[0].options.body).toMatchInlineSnapshot(
311+
`"{\\"data\\":[{\\"event_name\\":\\"PageView\\",\\"event_time\\":\\"1631210000\\",\\"action_source\\":\\"email\\",\\"user_data\\":{\\"em\\":\\"973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b\\",\\"ctwa_clid\\":\\"test_ctwa_click_id_12345\\"}}]}"`
312+
)
313+
})
268314
})
269315
})

0 commit comments

Comments
 (0)