@segment/action-destinations 3.29.1 → 3.30.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/destinations/facebook-conversions-api/addToCart/generated-types.d.ts +37 -0
  2. package/dist/destinations/facebook-conversions-api/addToCart/generated-types.js +3 -0
  3. package/dist/destinations/facebook-conversions-api/addToCart/generated-types.js.map +1 -0
  4. package/dist/destinations/facebook-conversions-api/addToCart/index.d.ts +5 -0
  5. package/dist/destinations/facebook-conversions-api/addToCart/index.js +84 -0
  6. package/dist/destinations/facebook-conversions-api/addToCart/index.js.map +1 -0
  7. package/dist/destinations/facebook-conversions-api/constants.d.ts +4 -0
  8. package/dist/destinations/facebook-conversions-api/constants.js +485 -0
  9. package/dist/destinations/facebook-conversions-api/constants.js.map +1 -0
  10. package/dist/destinations/facebook-conversions-api/custom/generated-types.d.ts +30 -0
  11. package/dist/destinations/facebook-conversions-api/custom/generated-types.js +3 -0
  12. package/dist/destinations/facebook-conversions-api/custom/generated-types.js.map +1 -0
  13. package/dist/destinations/facebook-conversions-api/custom/index.d.ts +5 -0
  14. package/dist/destinations/facebook-conversions-api/custom/index.js +58 -0
  15. package/dist/destinations/facebook-conversions-api/custom/index.js.map +1 -0
  16. package/dist/destinations/facebook-conversions-api/fb-capi-properties.d.ts +13 -0
  17. package/dist/destinations/facebook-conversions-api/fb-capi-properties.js +100 -0
  18. package/dist/destinations/facebook-conversions-api/fb-capi-properties.js.map +1 -0
  19. package/dist/destinations/facebook-conversions-api/fb-capi-user-data.d.ts +7 -0
  20. package/dist/destinations/facebook-conversions-api/fb-capi-user-data.js +227 -0
  21. package/dist/destinations/facebook-conversions-api/fb-capi-user-data.js.map +1 -0
  22. package/dist/destinations/facebook-conversions-api/generated-types.d.ts +3 -0
  23. package/dist/destinations/facebook-conversions-api/generated-types.js +3 -0
  24. package/dist/destinations/facebook-conversions-api/generated-types.js.map +1 -0
  25. package/dist/destinations/facebook-conversions-api/index.d.ts +4 -0
  26. package/dist/destinations/facebook-conversions-api/index.js +44 -0
  27. package/dist/destinations/facebook-conversions-api/index.js.map +1 -0
  28. package/dist/destinations/facebook-conversions-api/initiateCheckout/generated-types.d.ts +37 -0
  29. package/dist/destinations/facebook-conversions-api/initiateCheckout/generated-types.js +3 -0
  30. package/dist/destinations/facebook-conversions-api/initiateCheckout/generated-types.js.map +1 -0
  31. package/dist/destinations/facebook-conversions-api/initiateCheckout/index.d.ts +5 -0
  32. package/dist/destinations/facebook-conversions-api/initiateCheckout/index.js +92 -0
  33. package/dist/destinations/facebook-conversions-api/initiateCheckout/index.js.map +1 -0
  34. package/dist/destinations/facebook-conversions-api/pageView/generated-types.d.ts +26 -0
  35. package/dist/destinations/facebook-conversions-api/pageView/generated-types.js +3 -0
  36. package/dist/destinations/facebook-conversions-api/pageView/generated-types.js.map +1 -0
  37. package/dist/destinations/facebook-conversions-api/pageView/index.d.ts +5 -0
  38. package/dist/destinations/facebook-conversions-api/pageView/index.js +43 -0
  39. package/dist/destinations/facebook-conversions-api/pageView/index.js.map +1 -0
  40. package/dist/destinations/facebook-conversions-api/purchase/generated-types.d.ts +38 -0
  41. package/dist/destinations/facebook-conversions-api/purchase/generated-types.js +3 -0
  42. package/dist/destinations/facebook-conversions-api/purchase/generated-types.js.map +1 -0
  43. package/dist/destinations/facebook-conversions-api/purchase/index.d.ts +5 -0
  44. package/dist/destinations/facebook-conversions-api/purchase/index.js +95 -0
  45. package/dist/destinations/facebook-conversions-api/purchase/index.js.map +1 -0
  46. package/dist/destinations/facebook-conversions-api/search/generated-types.d.ts +37 -0
  47. package/dist/destinations/facebook-conversions-api/search/generated-types.js +3 -0
  48. package/dist/destinations/facebook-conversions-api/search/generated-types.js.map +1 -0
  49. package/dist/destinations/facebook-conversions-api/search/index.d.ts +5 -0
  50. package/dist/destinations/facebook-conversions-api/search/index.js +91 -0
  51. package/dist/destinations/facebook-conversions-api/search/index.js.map +1 -0
  52. package/dist/destinations/facebook-conversions-api/viewContent/generated-types.d.ts +38 -0
  53. package/dist/destinations/facebook-conversions-api/viewContent/generated-types.js +3 -0
  54. package/dist/destinations/facebook-conversions-api/viewContent/generated-types.js.map +1 -0
  55. package/dist/destinations/facebook-conversions-api/viewContent/index.d.ts +5 -0
  56. package/dist/destinations/facebook-conversions-api/viewContent/index.js +85 -0
  57. package/dist/destinations/facebook-conversions-api/viewContent/index.js.map +1 -0
  58. package/dist/destinations/index.js +1 -0
  59. package/dist/destinations/index.js.map +1 -1
  60. package/dist/destinations/mixpanel/groupIdentifyUser/generated-types.d.ts +1 -1
  61. package/dist/destinations/mixpanel/groupIdentifyUser/index.d.ts +1 -1
  62. package/dist/destinations/mixpanel/groupIdentifyUser/index.js +10 -8
  63. package/dist/destinations/mixpanel/groupIdentifyUser/index.js.map +1 -1
  64. package/dist/destinations/personas-messaging-twilio/generated-types.d.ts +1 -0
  65. package/dist/destinations/personas-messaging-twilio/index.js +78 -0
  66. package/dist/destinations/personas-messaging-twilio/index.js.map +1 -1
  67. package/dist/destinations/personas-messaging-twilio/sendSms/generated-types.d.ts +1 -0
  68. package/dist/destinations/personas-messaging-twilio/sendSms/index.js +9 -0
  69. package/dist/destinations/personas-messaging-twilio/sendSms/index.js.map +1 -1
  70. package/package.json +3 -3
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const constants_1 = require("../constants");
5
+ const fb_capi_properties_1 = require("../fb-capi-properties");
6
+ const fb_capi_user_data_1 = require("../fb-capi-user-data");
7
+ const action = {
8
+ title: 'Initiate Checkout',
9
+ description: 'Send event when a user enters the checkout flow',
10
+ defaultSubscription: 'type = "track" and event = "Checkout Started"',
11
+ fields: {
12
+ action_source: { ...fb_capi_properties_1.action_source, required: true },
13
+ event_time: { ...fb_capi_properties_1.event_time, required: true },
14
+ user_data: fb_capi_user_data_1.user_data_field,
15
+ content_category: fb_capi_properties_1.content_category,
16
+ content_ids: fb_capi_properties_1.content_ids,
17
+ contents: {
18
+ ...fb_capi_properties_1.contents,
19
+ default: {
20
+ '@arrayPath': [
21
+ '$.properties.products',
22
+ {
23
+ id: {
24
+ '@path': '$.product_id'
25
+ },
26
+ quantity: {
27
+ '@path': '$.quantity'
28
+ },
29
+ item_price: {
30
+ '@path': '$.price'
31
+ }
32
+ }
33
+ ]
34
+ }
35
+ },
36
+ currency: fb_capi_properties_1.currency,
37
+ event_id: fb_capi_properties_1.event_id,
38
+ event_source_url: fb_capi_properties_1.event_source_url,
39
+ num_items: fb_capi_properties_1.num_items,
40
+ value: {
41
+ ...fb_capi_properties_1.value,
42
+ default: { '@path': '$.properties.revenue' }
43
+ }
44
+ },
45
+ perform: (request, { payload, settings }) => {
46
+ if (payload.currency && !constants_1.CURRENCY_ISO_CODES.has(payload.currency)) {
47
+ throw new actions_core_1.IntegrationError(`${payload.currency} is not a valid currency code.`, 'Misconfigured required field', 400);
48
+ }
49
+ if (!payload.user_data) {
50
+ throw new actions_core_1.IntegrationError('Must include at least one user data property', 'Misconfigured required field', 400);
51
+ }
52
+ if (payload.action_source === 'website' && payload.user_data.client_user_agent === undefined) {
53
+ throw new actions_core_1.IntegrationError('If action source is "Website" then client_user_agent must be defined', 'Misconfigured required field', 400);
54
+ }
55
+ const valid_delivery_categories = ['in_store', 'curbside', 'home_delivery'];
56
+ if (payload.contents) {
57
+ payload.contents.forEach((obj, index) => {
58
+ if (!obj.id) {
59
+ throw new actions_core_1.IntegrationError("Contents objects must include an 'id' parameter.", 'Misconfigured required field', 400);
60
+ }
61
+ if (obj.delivery_category && !valid_delivery_categories.includes(obj.delivery_category)) {
62
+ throw new actions_core_1.IntegrationError(`contents[${index}].delivery_category must be one of {in_store, home_delivery, curbside}.`, 'Misconfigured field', 400);
63
+ }
64
+ });
65
+ }
66
+ return request(`https://graph.facebook.com/v${constants_1.API_VERSION}/${settings.pixelId}/events`, {
67
+ method: 'POST',
68
+ json: {
69
+ data: [
70
+ {
71
+ event_name: 'InitiateCheckout',
72
+ event_time: payload.event_time,
73
+ action_source: payload.action_source,
74
+ event_source_url: payload.event_source_url,
75
+ event_id: payload.event_id,
76
+ user_data: fb_capi_user_data_1.hash_user_data({ user_data: payload.user_data }),
77
+ custom_data: {
78
+ currency: payload.currency,
79
+ value: payload.value,
80
+ content_ids: payload.content_ids,
81
+ contents: payload.contents,
82
+ num_items: payload.num_items,
83
+ content_category: payload.content_category
84
+ }
85
+ }
86
+ ]
87
+ }
88
+ });
89
+ }
90
+ };
91
+ exports.default = action;
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/initiateCheckout/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAG1E,4CAA8D;AAC9D,8DAW8B;AAC9B,4DAAsE;AAEtE,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,mBAAmB;IAC1B,WAAW,EAAE,iDAAiD;IAC9D,mBAAmB,EAAE,+CAA+C;IACpE,MAAM,EAAE;QACN,aAAa,EAAE,EAAE,GAAG,kCAAa,EAAE,QAAQ,EAAE,IAAI,EAAE;QACnD,UAAU,EAAE,EAAE,GAAG,+BAAU,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC7C,SAAS,EAAE,mCAAe;QAC1B,gBAAgB,EAAE,qCAAgB;QAClC,WAAW,EAAE,gCAAW;QACxB,QAAQ,EAAE;YAER,GAAG,6BAAQ;YACX,OAAO,EAAE;gBACP,YAAY,EAAE;oBACZ,uBAAuB;oBACvB;wBACE,EAAE,EAAE;4BACF,OAAO,EAAE,cAAc;yBACxB;wBACD,QAAQ,EAAE;4BACR,OAAO,EAAE,YAAY;yBACtB;wBACD,UAAU,EAAE;4BACV,OAAO,EAAE,SAAS;yBACnB;qBACF;iBACF;aACF;SACF;QACD,QAAQ,EAAE,6BAAQ;QAClB,QAAQ,EAAE,6BAAQ;QAClB,gBAA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AAqB,EACrB,GAAG,CACJ,CAAA;iBACF;YACH,CAAC,CAAC,CAAA;SACH;QAED,OAAO,OAAO,CAAC,+BAA+B,uBAAW,IAAI,QAAQ,CAAC,OAAO,SAAS,EAAE;YACtF,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ;wBACE,UAAU,EAAE,kBAAkB;wBAC9B,UAAU,EAAE,OAAO,CAAC,UAAU;wBAC9B,aAAa,EAAE,OAAO,CAAC,aAAa;wBACpC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;wBAC1C,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,SAAS,EAAE,kCAAc,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;wBAC3D,WAAW,EAAE;4BACX,QAAQ,EAAE,OAAO,CAAC,QAAQ;4BAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;4BACpB,WAAW,EAAE,OAAO,CAAC,WAAW;4BAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;4BAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;4BAC5B,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;yBAC3C;qBACF;iBACF;aACF;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,26 @@
1
+ export interface Payload {
2
+ action_source: string;
3
+ event_time: string;
4
+ user_data: {
5
+ externalId?: string;
6
+ email?: string;
7
+ phone?: string;
8
+ gender?: string;
9
+ dateOfBirth?: string;
10
+ lastName?: string;
11
+ firstName?: string;
12
+ city?: string;
13
+ state?: string;
14
+ zip?: string;
15
+ country?: string;
16
+ client_ip_address?: string;
17
+ client_user_agent?: string;
18
+ fbc?: string;
19
+ fbp?: string;
20
+ subscriptionID?: string;
21
+ leadID?: number;
22
+ fbLoginID?: number;
23
+ };
24
+ event_id?: string;
25
+ event_source_url?: string;
26
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/pageView/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ActionDefinition } from '@segment/actions-core';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ declare const action: ActionDefinition<Settings, Payload>;
5
+ export default action;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const fb_capi_properties_1 = require("../fb-capi-properties");
5
+ const fb_capi_user_data_1 = require("../fb-capi-user-data");
6
+ const constants_1 = require("../constants");
7
+ const action = {
8
+ title: 'Page View',
9
+ description: 'Send a page view event when a user lands on a page',
10
+ defaultSubscription: 'type = "page"',
11
+ fields: {
12
+ action_source: { ...fb_capi_properties_1.action_source, required: true },
13
+ event_time: { ...fb_capi_properties_1.event_time, required: true },
14
+ user_data: fb_capi_user_data_1.user_data_field,
15
+ event_id: fb_capi_properties_1.event_id,
16
+ event_source_url: fb_capi_properties_1.event_source_url
17
+ },
18
+ perform: (request, { payload, settings }) => {
19
+ if (!payload.user_data) {
20
+ throw new actions_core_1.IntegrationError('Must include at least one user data property', 'Misconfigured required field', 400);
21
+ }
22
+ if (payload.action_source === 'website' && payload.user_data.client_user_agent === undefined) {
23
+ throw new actions_core_1.IntegrationError('If action source is "Website" then client_user_agent must be defined', 'Misconfigured required field', 400);
24
+ }
25
+ return request(`https://graph.facebook.com/v${constants_1.API_VERSION}/${settings.pixelId}/events`, {
26
+ method: 'POST',
27
+ json: {
28
+ data: [
29
+ {
30
+ event_name: 'PageView',
31
+ event_time: payload.event_time,
32
+ action_source: payload.action_source,
33
+ event_source_url: payload.event_source_url,
34
+ event_id: payload.event_id,
35
+ user_data: fb_capi_user_data_1.hash_user_data({ user_data: payload.user_data })
36
+ }
37
+ ]
38
+ }
39
+ });
40
+ }
41
+ };
42
+ exports.default = action;
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/pageView/index.ts"],"names":[],"mappings":";;AAAA,wDAA2E;AAC3E,8DAA6F;AAC7F,4DAAsE;AAGtE,4CAA0C;AAC1C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,WAAW;IAClB,WAAW,EAAE,oDAAoD;IACjE,mBAAmB,EAAE,eAAe;IACpC,MAAM,EAAE;QACN,aAAa,EAAE,EAAE,GAAG,kCAAa,EAAE,QAAQ,EAAE,IAAI,EAAE;QACnD,UAAU,EAAE,EAAE,GAAG,+BAAU,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC7C,SAAS,EAAE,mCAAe;QAC1B,QAAQ,EAAE,6BAAQ;QAClB,gBAAgB,EAAE,qCAAgB;KACnC;IACD,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC1C,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YACtB,MAAM,IAAI,+BAAgB,CAAC,8CAA8C,EAAE,8BAA8B,EAAE,GAAG,CAAC,CAAA;SAChH;QAED,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,iBAAiB,KAAK,SAAS,EAAE;YAC5F,MAAM,IAAI,+BAAgB,CACxB,sEAAsE,EACtE,8BAA8B,EAC9B,GAAG,CACJ,CAAA;SACF;QACD,OAAO,OAAO,CAAC,+BAA+B,uBAAW,IAAI,QAAQ,CAAC,OAAO,SAAS,EAAE;YACtF,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ;wBACE,UAAU,EAAE,UAAU;wBACtB,UAAU,EAAE,OAAO,CAAC,UAAU;wBAC9B,aAAa,EAAE,OAAO,CAAC,aAAa;wBACpC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;wBAC1C,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,SAAS,EAAE,kCAAc,CAAC,EAAC,SAAS,EAAE,OAAO,CAAC,SAAS,EAAC,CAAC;qBAC1D;iBACF;aACF;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,38 @@
1
+ export interface Payload {
2
+ action_source: string;
3
+ currency: string;
4
+ event_time: string;
5
+ user_data: {
6
+ externalId?: string;
7
+ email?: string;
8
+ phone?: string;
9
+ gender?: string;
10
+ dateOfBirth?: string;
11
+ lastName?: string;
12
+ firstName?: string;
13
+ city?: string;
14
+ state?: string;
15
+ zip?: string;
16
+ country?: string;
17
+ client_ip_address?: string;
18
+ client_user_agent?: string;
19
+ fbc?: string;
20
+ fbp?: string;
21
+ subscriptionID?: string;
22
+ leadID?: number;
23
+ fbLoginID?: number;
24
+ };
25
+ value: number;
26
+ content_ids?: string[];
27
+ content_name?: string;
28
+ content_type?: string;
29
+ contents?: {
30
+ id?: string;
31
+ quantity?: number;
32
+ item_price?: number;
33
+ delivery_category?: string;
34
+ }[];
35
+ event_id?: string;
36
+ event_source_url?: string;
37
+ num_items?: number;
38
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/purchase/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ActionDefinition } from '@segment/actions-core';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ declare const action: ActionDefinition<Settings, Payload>;
5
+ export default action;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const constants_1 = require("../constants");
5
+ const fb_capi_properties_1 = require("../fb-capi-properties");
6
+ const fb_capi_user_data_1 = require("../fb-capi-user-data");
7
+ const action = {
8
+ title: 'Purchase',
9
+ description: 'Send event when a user completes a purchase',
10
+ defaultSubscription: 'type = "track" and event = "Order Completed"',
11
+ fields: {
12
+ action_source: { ...fb_capi_properties_1.action_source, required: true },
13
+ currency: { ...fb_capi_properties_1.currency, required: true },
14
+ event_time: { ...fb_capi_properties_1.event_time, required: true },
15
+ user_data: fb_capi_user_data_1.user_data_field,
16
+ value: {
17
+ ...fb_capi_properties_1.value,
18
+ required: true,
19
+ default: { '@path': '$.properties.revenue' }
20
+ },
21
+ content_ids: fb_capi_properties_1.content_ids,
22
+ content_name: fb_capi_properties_1.content_name,
23
+ content_type: fb_capi_properties_1.content_type,
24
+ contents: {
25
+ ...fb_capi_properties_1.contents,
26
+ default: {
27
+ '@arrayPath': [
28
+ '$.properties.products',
29
+ {
30
+ id: {
31
+ '@path': '$.product_id'
32
+ },
33
+ quantity: {
34
+ '@path': '$.quantity'
35
+ },
36
+ item_price: {
37
+ '@path': '$.price'
38
+ }
39
+ }
40
+ ]
41
+ }
42
+ },
43
+ event_id: fb_capi_properties_1.event_id,
44
+ event_source_url: fb_capi_properties_1.event_source_url,
45
+ num_items: fb_capi_properties_1.num_items
46
+ },
47
+ perform: (request, { payload, settings }) => {
48
+ if (!constants_1.CURRENCY_ISO_CODES.has(payload.currency)) {
49
+ throw new actions_core_1.IntegrationError(`${payload.currency} is not a valid currency code.`, 'Misconfigured required field', 400);
50
+ }
51
+ if (!payload.user_data) {
52
+ throw new actions_core_1.IntegrationError('Must include at least one user data property', 'Misconfigured required field', 400);
53
+ }
54
+ if (payload.action_source === 'website' && payload.user_data.client_user_agent === undefined) {
55
+ throw new actions_core_1.IntegrationError('If action source is "Website" then client_user_agent must be defined', 'Misconfigured required field', 400);
56
+ }
57
+ const valid_delivery_categories = ['in_store', 'curbside', 'home_delivery'];
58
+ if (payload.contents) {
59
+ payload.contents.forEach((obj, index) => {
60
+ if (!obj.id) {
61
+ throw new actions_core_1.IntegrationError("Contents objects must include an 'id' parameter.", 'Misconfigured required field', 400);
62
+ }
63
+ if (obj.delivery_category && !valid_delivery_categories.includes(obj.delivery_category)) {
64
+ throw new actions_core_1.IntegrationError(`contents[${index}].delivery_category must be one of {in_store, home_delivery, curbside}.`, 'Misconfigured field', 400);
65
+ }
66
+ });
67
+ }
68
+ return request(`https://graph.facebook.com/v${constants_1.API_VERSION}/${settings.pixelId}/events`, {
69
+ method: 'POST',
70
+ json: {
71
+ data: [
72
+ {
73
+ event_name: 'Purchase',
74
+ event_time: payload.event_time,
75
+ action_source: payload.action_source,
76
+ event_source_url: payload.event_source_url,
77
+ event_id: payload.event_id,
78
+ user_data: fb_capi_user_data_1.hash_user_data({ user_data: payload.user_data }),
79
+ custom_data: {
80
+ currency: payload.currency,
81
+ value: payload.value,
82
+ content_ids: payload.content_ids,
83
+ content_name: payload.content_name,
84
+ content_type: payload.content_type,
85
+ contents: payload.contents,
86
+ num_items: payload.num_items
87
+ }
88
+ }
89
+ ]
90
+ }
91
+ });
92
+ }
93
+ };
94
+ exports.default = action;
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/purchase/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAG1E,4CAA8D;AAC9D,8DAY8B;AAC9B,4DAAsE;AAEtE,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,UAAU;IACjB,WAAW,EAAE,6CAA6C;IAC1D,mBAAmB,EAAE,8CAA8C;IACnE,MAAM,EAAE;QACN,aAAa,EAAE,EAAE,GAAG,kCAAa,EAAE,QAAQ,EAAE,IAAI,EAAE;QACnD,QAAQ,EAAE,EAAE,GAAG,6BAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;QACzC,UAAU,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B;qBACF;iBACF;aACF;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,37 @@
1
+ export interface Payload {
2
+ action_source: string;
3
+ event_time: string;
4
+ user_data: {
5
+ externalId?: string;
6
+ email?: string;
7
+ phone?: string;
8
+ gender?: string;
9
+ dateOfBirth?: string;
10
+ lastName?: string;
11
+ firstName?: string;
12
+ city?: string;
13
+ state?: string;
14
+ zip?: string;
15
+ country?: string;
16
+ client_ip_address?: string;
17
+ client_user_agent?: string;
18
+ fbc?: string;
19
+ fbp?: string;
20
+ subscriptionID?: string;
21
+ leadID?: number;
22
+ fbLoginID?: number;
23
+ };
24
+ content_category?: string;
25
+ content_ids?: string[];
26
+ contents?: {
27
+ id?: string;
28
+ quantity?: number;
29
+ item_price?: number;
30
+ delivery_category?: string;
31
+ }[];
32
+ currency?: string;
33
+ event_id?: string;
34
+ event_source_url?: string;
35
+ search_string?: string;
36
+ value?: number;
37
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/search/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ActionDefinition } from '@segment/actions-core';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ declare const action: ActionDefinition<Settings, Payload>;
5
+ export default action;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const constants_1 = require("../constants");
5
+ const fb_capi_properties_1 = require("../fb-capi-properties");
6
+ const fb_capi_user_data_1 = require("../fb-capi-user-data");
7
+ const action = {
8
+ title: 'Search',
9
+ description: 'Send event when a user searches content or products',
10
+ defaultSubscription: 'type = "track" and event = "Products Searched"',
11
+ fields: {
12
+ action_source: { ...fb_capi_properties_1.action_source, required: true },
13
+ event_time: { ...fb_capi_properties_1.event_time, required: true },
14
+ user_data: fb_capi_user_data_1.user_data_field,
15
+ content_category: fb_capi_properties_1.content_category,
16
+ content_ids: fb_capi_properties_1.content_ids,
17
+ contents: {
18
+ ...fb_capi_properties_1.contents,
19
+ default: {
20
+ id: {
21
+ '@path': '$.properties.product_id'
22
+ },
23
+ quantity: {
24
+ '@path': '$.properties.quantity'
25
+ },
26
+ item_price: {
27
+ '@path': '$.properties.price'
28
+ }
29
+ }
30
+ },
31
+ currency: fb_capi_properties_1.currency,
32
+ event_id: fb_capi_properties_1.event_id,
33
+ event_source_url: fb_capi_properties_1.event_source_url,
34
+ search_string: {
35
+ label: 'Search String',
36
+ description: 'A search query made by a user. This must be a string.',
37
+ type: 'string',
38
+ default: {
39
+ '@path': '$.properties.query'
40
+ }
41
+ },
42
+ value: fb_capi_properties_1.value
43
+ },
44
+ perform: (request, { payload, settings }) => {
45
+ if (payload.currency && !constants_1.CURRENCY_ISO_CODES.has(payload.currency)) {
46
+ throw new actions_core_1.IntegrationError(`${payload.currency} is not a valid currency code.`, 'Misconfigured required field', 400);
47
+ }
48
+ if (!payload.user_data) {
49
+ throw new actions_core_1.IntegrationError('Must include at least one user data property', 'Misconfigured required field', 400);
50
+ }
51
+ if (payload.action_source === 'website' && payload.user_data.client_user_agent === undefined) {
52
+ throw new actions_core_1.IntegrationError('If action source is "Website" then client_user_agent must be defined', 'Misconfigured required field', 400);
53
+ }
54
+ const valid_delivery_categories = ['in_store', 'curbside', 'home_delivery'];
55
+ if (payload.contents) {
56
+ payload.contents.forEach((obj, index) => {
57
+ if (!obj.id) {
58
+ throw new actions_core_1.IntegrationError("Contents objects must include an 'id' parameter.", 'Misconfigured required field', 400);
59
+ }
60
+ if (obj.delivery_category && !valid_delivery_categories.includes(obj.delivery_category)) {
61
+ throw new actions_core_1.IntegrationError(`contents[${index}].delivery_category must be one of {in_store, home_delivery, curbside}.`, 'Misconfigured field', 400);
62
+ }
63
+ });
64
+ }
65
+ return request(`https://graph.facebook.com/v${constants_1.API_VERSION}/${settings.pixelId}/events`, {
66
+ method: 'POST',
67
+ json: {
68
+ data: [
69
+ {
70
+ event_name: 'Search',
71
+ event_time: payload.event_time,
72
+ action_source: payload.action_source,
73
+ event_id: payload.event_id,
74
+ event_source_url: payload.event_source_url,
75
+ user_data: fb_capi_user_data_1.hash_user_data({ user_data: payload.user_data }),
76
+ custom_data: {
77
+ currency: payload.currency,
78
+ content_ids: payload.content_ids,
79
+ contents: payload.contents,
80
+ content_category: payload.content_category,
81
+ value: payload.value,
82
+ search_string: payload.search_string
83
+ }
84
+ }
85
+ ]
86
+ }
87
+ });
88
+ }
89
+ };
90
+ exports.default = action;
91
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/search/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAG1E,4CAA8D;AAC9D,8DAU8B;AAC9B,4DAAsE;AAEtE,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,QAAQ;IACf,WAAW,EAAE,qDAAqD;IAClE,mBAAmB,EAAE,gDAAgD;IACrE,MAAM,EAAE;QACN,aAAa,EAAE,EAAE,GAAG,kCAAa,EAAE,QAAQ,EAAE,IAAI,EAAE;QACnD,UAAU,EAAE,EAAE,GAAG,+BAAU,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC7C,SAAS,EAAE,mCAAe;QAC1B,gBAAgB,EAAE,qCAAgB;QAClC,WAAW,EAAE,gCAAW;QACxB,QAAQ,EAAE;YACR,GAAG,6BAAQ;YACX,OAAO,EAAE;gBAEP,EAAE,EAAE;oBACF,OAAO,EAAE,yBAAyB;iBACnC;gBACD,QAAQ,EAAE;oBACR,OAAO,EAAE,uBAAuB;iBACjC;gBACD,UAAU,EAAE;oBACV,OAAO,EAAE,oBAAoB;iBA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AI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;oBACvF,MAAM,IAAI,+BAAgB,CACxB,YAAY,KAAK,yEAAyE,EAC1F,qBAAqB,EACrB,GAAG,CACJ,CAAA;iBACF;YACH,CAAC,CAAC,CAAA;SACH;QAED,OAAO,OAAO,CAAC,+BAA+B,uBAAW,IAAI,QAAQ,CAAC,OAAO,SAAS,EAAE;YACtF,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ;wBACE,UAAU,EAAE,QAAQ;wBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;wBAC9B,aAAa,EAAE,OAAO,CAAC,aAAa;wBACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;wBAC1C,SAAS,EAAE,kCAAc,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;wBAC3D,WAAW,EAAE;4BACX,QAAQ,EAAE,OAAO,CAAC,QAAQ;4BAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;4BAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;4BAC1B,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;4BAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;4BACpB,aAAa,EAAE,OAAO,CAAC,aAAa;yBACrC;qBACF;iBACF;aACF;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,38 @@
1
+ export interface Payload {
2
+ user_data: {
3
+ externalId?: string;
4
+ email?: string;
5
+ phone?: string;
6
+ gender?: string;
7
+ dateOfBirth?: string;
8
+ lastName?: string;
9
+ firstName?: string;
10
+ city?: string;
11
+ state?: string;
12
+ zip?: string;
13
+ country?: string;
14
+ client_ip_address?: string;
15
+ client_user_agent?: string;
16
+ fbc?: string;
17
+ fbp?: string;
18
+ subscriptionID?: string;
19
+ leadID?: number;
20
+ fbLoginID?: number;
21
+ };
22
+ event_time: string;
23
+ action_source: string;
24
+ event_id?: string;
25
+ event_source_url?: string;
26
+ content_ids?: string[];
27
+ content_category?: string;
28
+ content_name?: string;
29
+ content_type?: string;
30
+ contents?: {
31
+ id?: string;
32
+ quantity?: number;
33
+ item_price?: number;
34
+ delivery_category?: string;
35
+ }[];
36
+ currency?: string;
37
+ value?: number;
38
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/facebook-conversions-api/viewContent/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ActionDefinition } from '@segment/actions-core';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ declare const action: ActionDefinition<Settings, Payload>;
5
+ export default action;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const fb_capi_properties_1 = require("../fb-capi-properties");
5
+ const fb_capi_user_data_1 = require("../fb-capi-user-data");
6
+ const constants_1 = require("../constants");
7
+ const action = {
8
+ title: 'View Content',
9
+ description: 'Send event when a user views content or a product',
10
+ defaultSubscription: 'type = "track" and event = "Product Viewed"',
11
+ fields: {
12
+ user_data: fb_capi_user_data_1.user_data_field,
13
+ event_time: { ...fb_capi_properties_1.event_time, required: true },
14
+ action_source: { ...fb_capi_properties_1.action_source, required: true },
15
+ event_id: fb_capi_properties_1.event_id,
16
+ event_source_url: fb_capi_properties_1.event_source_url,
17
+ content_ids: { ...fb_capi_properties_1.content_ids, default: { '@path': '$.properties.product_id' } },
18
+ content_category: fb_capi_properties_1.content_category,
19
+ content_name: fb_capi_properties_1.content_name,
20
+ content_type: fb_capi_properties_1.content_type,
21
+ contents: {
22
+ ...fb_capi_properties_1.contents,
23
+ default: {
24
+ id: {
25
+ '@path': '$.properties.product_id'
26
+ },
27
+ quantity: {
28
+ '@path': '$.properties.quantity'
29
+ },
30
+ item_price: {
31
+ '@path': '$.properties.price'
32
+ }
33
+ }
34
+ },
35
+ currency: fb_capi_properties_1.currency,
36
+ value: { ...fb_capi_properties_1.value, default: { '@path': '$.properties.price' } }
37
+ },
38
+ perform: (request, { payload, settings }) => {
39
+ if (payload.currency && !constants_1.CURRENCY_ISO_CODES.has(payload.currency)) {
40
+ throw new actions_core_1.IntegrationError(`${payload.currency} is not a valid currency code.`, 'Misconfigured required field', 400);
41
+ }
42
+ if (!payload.user_data) {
43
+ throw new actions_core_1.IntegrationError('Must include at least one user data property', 'Misconfigured required field', 400);
44
+ }
45
+ if (payload.action_source === 'website' && payload.user_data.client_user_agent === undefined) {
46
+ throw new actions_core_1.IntegrationError('If action source is "Website" then client_user_agent must be defined', 'Misconfigured required field', 400);
47
+ }
48
+ const valid_delivery_categories = ['in_store', 'curbside', 'home_delivery'];
49
+ if (payload.contents) {
50
+ payload.contents.forEach((obj, index) => {
51
+ if (!obj.id) {
52
+ throw new actions_core_1.IntegrationError("Contents objects must include an 'id' parameter.", 'Misconfigured required field', 400);
53
+ }
54
+ if (obj.delivery_category && !valid_delivery_categories.includes(obj.delivery_category)) {
55
+ throw new actions_core_1.IntegrationError(`contents[${index}].delivery_category must be one of {in_store, home_delivery, curbside}.`, 'Misconfigured field', 400);
56
+ }
57
+ });
58
+ }
59
+ return request(`https://graph.facebook.com/v${constants_1.API_VERSION}/${settings.pixelId}/events`, {
60
+ method: 'POST',
61
+ json: {
62
+ data: [
63
+ {
64
+ event_name: 'ViewContent',
65
+ event_time: payload.event_time,
66
+ action_source: payload.action_source,
67
+ event_id: payload.event_id,
68
+ event_source_url: payload.event_source_url,
69
+ user_data: fb_capi_user_data_1.hash_user_data({ user_data: payload.user_data }),
70
+ custom_data: {
71
+ currency: payload.currency,
72
+ value: payload.value,
73
+ content_ids: payload.content_ids,
74
+ content_name: payload.content_name,
75
+ content_type: payload.content_type,
76
+ contents: payload.contents
77
+ }
78
+ }
79
+ ]
80
+ }
81
+ });
82
+ }
83
+ };
84
+ exports.default = action;
85
+ //# sourceMappingURL=index.js.map