@segment/action-destinations 3.63.2-alpha.0 → 3.65.1-alpha.0

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 (76) hide show
  1. package/dist/destinations/amplitude/index.js +10 -2
  2. package/dist/destinations/amplitude/index.js.map +1 -1
  3. package/dist/destinations/amplitude/logEvent/generated-types.d.ts +0 -8
  4. package/dist/destinations/amplitude/logEvent/index.d.ts +3 -0
  5. package/dist/destinations/amplitude/logEvent/index.js +113 -170
  6. package/dist/destinations/amplitude/logEvent/index.js.map +1 -1
  7. package/dist/destinations/amplitude/logPurchase/generated-types.d.ts +64 -0
  8. package/dist/destinations/amplitude/logPurchase/generated-types.js +3 -0
  9. package/dist/destinations/amplitude/logPurchase/generated-types.js.map +1 -0
  10. package/dist/destinations/amplitude/logPurchase/index.d.ts +5 -0
  11. package/dist/destinations/amplitude/logPurchase/index.js +93 -0
  12. package/dist/destinations/amplitude/logPurchase/index.js.map +1 -0
  13. package/dist/destinations/google-analytics-4/addPaymentInfo/generated-types.d.ts +3 -0
  14. package/dist/destinations/google-analytics-4/addPaymentInfo/index.js +3 -1
  15. package/dist/destinations/google-analytics-4/addPaymentInfo/index.js.map +1 -1
  16. package/dist/destinations/google-analytics-4/addToCart/generated-types.d.ts +3 -0
  17. package/dist/destinations/google-analytics-4/addToCart/index.js +3 -1
  18. package/dist/destinations/google-analytics-4/addToCart/index.js.map +1 -1
  19. package/dist/destinations/google-analytics-4/addToWishlist/generated-types.d.ts +3 -0
  20. package/dist/destinations/google-analytics-4/addToWishlist/index.js +3 -1
  21. package/dist/destinations/google-analytics-4/addToWishlist/index.js.map +1 -1
  22. package/dist/destinations/google-analytics-4/beginCheckout/generated-types.d.ts +3 -0
  23. package/dist/destinations/google-analytics-4/beginCheckout/index.js +3 -1
  24. package/dist/destinations/google-analytics-4/beginCheckout/index.js.map +1 -1
  25. package/dist/destinations/google-analytics-4/customEvent/generated-types.d.ts +3 -0
  26. package/dist/destinations/google-analytics-4/customEvent/index.js +3 -1
  27. package/dist/destinations/google-analytics-4/customEvent/index.js.map +1 -1
  28. package/dist/destinations/google-analytics-4/ga4-properties.d.ts +2 -0
  29. package/dist/destinations/google-analytics-4/ga4-properties.js +20 -2
  30. package/dist/destinations/google-analytics-4/ga4-properties.js.map +1 -1
  31. package/dist/destinations/google-analytics-4/generateLead/generated-types.d.ts +3 -0
  32. package/dist/destinations/google-analytics-4/generateLead/index.js +3 -1
  33. package/dist/destinations/google-analytics-4/generateLead/index.js.map +1 -1
  34. package/dist/destinations/google-analytics-4/login/generated-types.d.ts +3 -0
  35. package/dist/destinations/google-analytics-4/login/index.js +3 -1
  36. package/dist/destinations/google-analytics-4/login/index.js.map +1 -1
  37. package/dist/destinations/google-analytics-4/pageView/generated-types.d.ts +4 -0
  38. package/dist/destinations/google-analytics-4/pageView/index.js +12 -1
  39. package/dist/destinations/google-analytics-4/pageView/index.js.map +1 -1
  40. package/dist/destinations/google-analytics-4/purchase/generated-types.d.ts +3 -0
  41. package/dist/destinations/google-analytics-4/purchase/index.js +3 -1
  42. package/dist/destinations/google-analytics-4/purchase/index.js.map +1 -1
  43. package/dist/destinations/google-analytics-4/refund/generated-types.d.ts +3 -0
  44. package/dist/destinations/google-analytics-4/refund/index.js +3 -1
  45. package/dist/destinations/google-analytics-4/refund/index.js.map +1 -1
  46. package/dist/destinations/google-analytics-4/removeFromCart/generated-types.d.ts +3 -0
  47. package/dist/destinations/google-analytics-4/removeFromCart/index.js +3 -1
  48. package/dist/destinations/google-analytics-4/removeFromCart/index.js.map +1 -1
  49. package/dist/destinations/google-analytics-4/search/generated-types.d.ts +3 -0
  50. package/dist/destinations/google-analytics-4/search/index.js +3 -1
  51. package/dist/destinations/google-analytics-4/search/index.js.map +1 -1
  52. package/dist/destinations/google-analytics-4/selectItem/generated-types.d.ts +3 -0
  53. package/dist/destinations/google-analytics-4/selectItem/index.js +3 -1
  54. package/dist/destinations/google-analytics-4/selectItem/index.js.map +1 -1
  55. package/dist/destinations/google-analytics-4/selectPromotion/generated-types.d.ts +3 -0
  56. package/dist/destinations/google-analytics-4/selectPromotion/index.js +3 -1
  57. package/dist/destinations/google-analytics-4/selectPromotion/index.js.map +1 -1
  58. package/dist/destinations/google-analytics-4/signUp/generated-types.d.ts +3 -0
  59. package/dist/destinations/google-analytics-4/signUp/index.js +3 -1
  60. package/dist/destinations/google-analytics-4/signUp/index.js.map +1 -1
  61. package/dist/destinations/google-analytics-4/viewCart/generated-types.d.ts +3 -0
  62. package/dist/destinations/google-analytics-4/viewCart/index.js +3 -1
  63. package/dist/destinations/google-analytics-4/viewCart/index.js.map +1 -1
  64. package/dist/destinations/google-analytics-4/viewItem/generated-types.d.ts +3 -0
  65. package/dist/destinations/google-analytics-4/viewItem/index.js +3 -1
  66. package/dist/destinations/google-analytics-4/viewItem/index.js.map +1 -1
  67. package/dist/destinations/google-analytics-4/viewItemList/generated-types.d.ts +3 -0
  68. package/dist/destinations/google-analytics-4/viewItemList/index.js +3 -1
  69. package/dist/destinations/google-analytics-4/viewItemList/index.js.map +1 -1
  70. package/dist/destinations/google-analytics-4/viewPromotion/generated-types.d.ts +3 -0
  71. package/dist/destinations/google-analytics-4/viewPromotion/index.js +3 -1
  72. package/dist/destinations/google-analytics-4/viewPromotion/index.js.map +1 -1
  73. package/dist/destinations/talon-one/updateCustomerProfilesAttributes/generated-types.d.ts +6 -4
  74. package/dist/destinations/talon-one/updateCustomerProfilesAttributes/index.js +17 -9
  75. package/dist/destinations/talon-one/updateCustomerProfilesAttributes/index.js.map +1 -1
  76. package/package.json +2 -2
@@ -6,16 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const actions_core_1 = require("@segment/actions-core");
7
7
  const identifyUser_1 = __importDefault(require("./identifyUser"));
8
8
  const logEvent_1 = __importDefault(require("./logEvent"));
9
+ const logPurchase_1 = __importDefault(require("./logPurchase"));
9
10
  const mapUser_1 = __importDefault(require("./mapUser"));
10
11
  const groupIdentifyUser_1 = __importDefault(require("./groupIdentifyUser"));
11
12
  const regional_endpoints_1 = require("./regional-endpoints");
12
13
  const presets = [
13
14
  {
14
15
  name: 'Track Calls',
15
- subscribe: 'type = "track"',
16
+ subscribe: 'type = "track" and event != "Order Completed"',
16
17
  partnerAction: 'logEvent',
17
18
  mapping: actions_core_1.defaultValues(logEvent_1.default.fields)
18
19
  },
20
+ {
21
+ name: 'Order Completed Calls',
22
+ subscribe: 'type = "track" and event = "Order Completed"',
23
+ partnerAction: 'logPurchase',
24
+ mapping: actions_core_1.defaultValues(logPurchase_1.default.fields)
25
+ },
19
26
  {
20
27
  name: 'Page Calls',
21
28
  subscribe: 'type = "page"',
@@ -111,7 +118,8 @@ const destination = {
111
118
  logEvent: logEvent_1.default,
112
119
  identifyUser: identifyUser_1.default,
113
120
  mapUser: mapUser_1.default,
114
- groupIdentifyUser: groupIdentifyUser_1.default
121
+ groupIdentifyUser: groupIdentifyUser_1.default,
122
+ logPurchase: logPurchase_1.default
115
123
  }
116
124
  };
117
125
  exports.default = destination;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/amplitude/index.ts"],"names":[],"mappings":";;;;;AACA,wDAAqD;AACrD,kEAAyC;AACzC,0DAAiC;AACjC,wDAA+B;AAC/B,4EAAmD;AAEnD,6DAA0D;AAG1D,MAAM,OAAO,GAAqC;IAChD;QACE,IAAI,EAAE,aAAa;QACnB,SAAS,EAAE,gBAAgB;QAC3B,aAAa,EAAE,UAAU;QACzB,OAAO,EAAE,4BAAa,CAAC,kBAAQ,CAAC,MAAM,CAAC;KACxC;IACD;QACE,IAAI,EAAE,YAAY;QAClB,SAAS,EAAE,eAAe;QAC1B,aAAa,EAAE,UAAU;QACzB,OAAO,EAAE;YACP,GAAG,4BAAa,CAAC,kBAAQ,CAAC,MAAM,CAAC;YACjC,UAAU,EAAE;gBACV,WAAW,EAAE,iBAAiB;aAC/B;SACF;KACF;IACD;QACE,IAAI,EAAE,cAAc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device_id?: string;
5
4
  event_type: string;
@@ -42,13 +41,6 @@ export interface Payload {
42
41
  event_id?: number;
43
42
  insert_id?: string;
44
43
  library?: string;
45
- products?: {
46
- price?: number;
47
- quantity?: number;
48
- revenue?: number;
49
- productId?: string;
50
- revenueType?: string;
51
- }[];
52
44
  use_batch_endpoint?: boolean;
53
45
  userAgent?: string;
54
46
  userAgentParsing?: boolean;
@@ -1,6 +1,7 @@
1
1
  import type { ActionDefinition } from '@segment/actions-core';
2
2
  import type { Settings } from '../generated-types';
3
3
  import type { Payload } from './generated-types';
4
+ import { InputField } from '@segment/actions-core';
4
5
  export interface AmplitudeEvent extends Omit<Payload, 'products' | 'trackRevenuePerProduct' | 'time' | 'session_id'> {
5
6
  library?: string;
6
7
  time?: number;
@@ -9,5 +10,7 @@ export interface AmplitudeEvent extends Omit<Payload, 'products' | 'trackRevenue
9
10
  min_id_length: number;
10
11
  };
11
12
  }
13
+ export declare function doPerform(request: Function, payload: Payload, settings: Settings, eventFunction: Function): any;
14
+ export declare const fields: Record<string, InputField>;
12
15
  declare const action: ActionDefinition<Settings, Payload>;
13
16
  export default action;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fields = exports.doPerform = void 0;
6
7
  const actions_core_1 = require("@segment/actions-core");
7
8
  const dayjs_1 = __importDefault(require("../../../lib/dayjs"));
8
9
  const event_schema_1 = require("../event-schema");
@@ -12,186 +13,128 @@ const merge_user_properties_1 = require("../merge-user-properties");
12
13
  const user_agent_1 = require("../user-agent");
13
14
  const regional_endpoints_1 = require("../regional-endpoints");
14
15
  const revenueKeys = ['revenue', 'price', 'productId', 'quantity', 'revenueType'];
15
- function getRevenueProperties(payload) {
16
- if (typeof payload.revenue !== 'number') {
17
- return {};
16
+ function getEvents(payload, properties) {
17
+ const events = [
18
+ {
19
+ ...(payload.userAgentParsing && user_agent_1.parseUserAgentProperties(payload.userAgent)),
20
+ ...actions_core_1.removeUndefined(properties),
21
+ library: 'segment'
22
+ }
23
+ ];
24
+ return events;
25
+ }
26
+ function doPerform(request, payload, settings, eventFunction) {
27
+ const { time, session_id, userAgent, userAgentParsing, utm_properties, referrer, min_id_length, library, ...rest } = actions_core_1.omit(payload, revenueKeys);
28
+ const properties = rest;
29
+ let options;
30
+ if (properties.platform) {
31
+ properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android');
32
+ }
33
+ if (library) {
34
+ if (library === 'analytics.js')
35
+ properties.platform = 'Web';
36
+ }
37
+ if (time && dayjs_1.default.utc(time).isValid()) {
38
+ properties.time = dayjs_1.default.utc(time).valueOf();
39
+ }
40
+ if (session_id && dayjs_1.default.utc(session_id).isValid()) {
41
+ properties.session_id = dayjs_1.default.utc(session_id).valueOf();
18
42
  }
19
- return {
20
- revenue: payload.revenue,
21
- revenueType: payload.revenueType ?? 'Purchase',
22
- quantity: typeof payload.quantity === 'number' ? Math.round(payload.quantity) : undefined,
23
- price: payload.price,
24
- productId: payload.productId
25
- };
43
+ if (Object.keys(payload.utm_properties ?? {}).length || payload.referrer) {
44
+ properties.user_properties = merge_user_properties_1.mergeUserProperties(utm_1.convertUTMProperties({ utm_properties }), referrer_1.convertReferrerProperty({ referrer }), actions_core_1.omit(properties.user_properties ?? {}, ['utm_properties', 'referrer']));
45
+ }
46
+ if (min_id_length && min_id_length > 0) {
47
+ options = { min_id_length };
48
+ }
49
+ const events = eventFunction(payload, properties);
50
+ const endpoint = regional_endpoints_1.getEndpointByRegion(payload.use_batch_endpoint ? 'batch' : 'httpapi', settings.endpoint);
51
+ return request(endpoint, {
52
+ method: 'post',
53
+ json: {
54
+ api_key: settings.apiKey,
55
+ events,
56
+ options
57
+ }
58
+ });
26
59
  }
27
- const action = {
28
- title: 'Log Event',
29
- description: 'Send an event to Amplitude.',
30
- defaultSubscription: 'type = "track"',
31
- fields: {
32
- trackRevenuePerProduct: {
33
- label: 'Track Revenue Per Product',
34
- description: 'When enabled, track revenue with each product within the event. When disabled, track total revenue once for the event.',
35
- type: 'boolean',
36
- default: false
37
- },
38
- ...event_schema_1.eventSchema,
39
- products: {
40
- label: 'Products',
41
- description: 'The list of products purchased.',
42
- type: 'object',
43
- multiple: true,
44
- properties: {
45
- price: {
46
- label: 'Price',
47
- type: 'number',
48
- description: 'The price of the item purchased. Required for revenue data if the revenue field is not sent. You can use negative values to indicate refunds.'
49
- },
50
- quantity: {
51
- label: 'Quantity',
52
- type: 'integer',
53
- description: 'The quantity of the item purchased. Defaults to 1 if not specified.'
54
- },
55
- revenue: {
56
- label: 'Revenue',
57
- type: 'number',
58
- description: 'Revenue = price * quantity. If you send all 3 fields of price, quantity, and revenue, then (price * quantity) will be used as the revenue value. You can use negative values to indicate refunds.'
59
- },
60
- productId: {
61
- label: 'Product ID',
62
- type: 'string',
63
- description: 'An identifier for the item purchased. You must send a price and quantity or revenue with this field.'
64
- },
65
- revenueType: {
66
- label: 'Revenue Type',
67
- type: 'string',
68
- description: 'The type of revenue for the item purchased. You must send a price and quantity or revenue with this field.'
69
- }
60
+ exports.doPerform = doPerform;
61
+ exports.fields = {
62
+ ...event_schema_1.eventSchema,
63
+ use_batch_endpoint: {
64
+ label: 'Use Batch Endpoint',
65
+ description: "If true, events are sent to Amplitude's `batch` endpoint rather than their `httpapi` events endpoint. Enabling this setting may help reduce 429s – or throttling errors – from Amplitude. More information about Amplitude's throttling is available in [their docs](https://developers.amplitude.com/docs/batch-event-upload-api#429s-in-depth).",
66
+ type: 'boolean',
67
+ default: false
68
+ },
69
+ userAgent: {
70
+ label: 'User Agent',
71
+ type: 'string',
72
+ description: 'The user agent of the device sending the event.',
73
+ default: {
74
+ '@path': '$.context.userAgent'
75
+ }
76
+ },
77
+ userAgentParsing: {
78
+ label: 'User Agent Parsing',
79
+ type: 'boolean',
80
+ description: 'Enabling this setting will set the Device manufacturer, Device Model and OS Name properties based on the user agent string provided in the userAgent field',
81
+ default: true
82
+ },
83
+ utm_properties: {
84
+ label: 'UTM Properties',
85
+ type: 'object',
86
+ description: 'UTM Tracking Properties',
87
+ properties: {
88
+ utm_source: {
89
+ label: 'UTM Source',
90
+ type: 'string'
70
91
  },
71
- default: {
72
- '@path': '$.properties.products'
73
- }
74
- },
75
- use_batch_endpoint: {
76
- label: 'Use Batch Endpoint',
77
- description: "If true, events are sent to Amplitude's `batch` endpoint rather than their `httpapi` events endpoint. Enabling this setting may help reduce 429s – or throttling errors – from Amplitude. More information about Amplitude's throttling is available in [their docs](https://developers.amplitude.com/docs/batch-event-upload-api#429s-in-depth).",
78
- type: 'boolean',
79
- default: false
80
- },
81
- userAgent: {
82
- label: 'User Agent',
83
- type: 'string',
84
- description: 'The user agent of the device sending the event.',
85
- default: {
86
- '@path': '$.context.userAgent'
87
- }
88
- },
89
- userAgentParsing: {
90
- label: 'User Agent Parsing',
91
- type: 'boolean',
92
- description: 'Enabling this setting will set the Device manufacturer, Device Model and OS Name properties based on the user agent string provided in the userAgent field',
93
- default: true
94
- },
95
- utm_properties: {
96
- label: 'UTM Properties',
97
- type: 'object',
98
- description: 'UTM Tracking Properties',
99
- properties: {
100
- utm_source: {
101
- label: 'UTM Source',
102
- type: 'string'
103
- },
104
- utm_medium: {
105
- label: 'UTM Medium',
106
- type: 'string'
107
- },
108
- utm_campaign: {
109
- label: 'UTM Campaign',
110
- type: 'string'
111
- },
112
- utm_term: {
113
- label: 'UTM Term',
114
- type: 'string'
115
- },
116
- utm_content: {
117
- label: 'UTM Content',
118
- type: 'string'
119
- }
92
+ utm_medium: {
93
+ label: 'UTM Medium',
94
+ type: 'string'
120
95
  },
121
- default: {
122
- utm_source: { '@path': '$.context.campaign.source' },
123
- utm_medium: { '@path': '$.context.campaign.medium' },
124
- utm_campaign: { '@path': '$.context.campaign.name' },
125
- utm_term: { '@path': '$.context.campaign.term' },
126
- utm_content: { '@path': '$.context.campaign.content' }
127
- }
128
- },
129
- referrer: {
130
- label: 'Referrer',
131
- type: 'string',
132
- description: 'The referrer of the web request. Sent to Amplitude as both last touch “referrer” and first touch “initial_referrer”',
133
- default: {
134
- '@path': '$.context.page.referrer'
96
+ utm_campaign: {
97
+ label: 'UTM Campaign',
98
+ type: 'string'
99
+ },
100
+ utm_term: {
101
+ label: 'UTM Term',
102
+ type: 'string'
103
+ },
104
+ utm_content: {
105
+ label: 'UTM Content',
106
+ type: 'string'
135
107
  }
136
108
  },
137
- min_id_length: {
138
- label: 'Minimum ID Length',
139
- description: 'Amplitude has a default minimum id lenght of 5 characters for user_id and device_id fields. This field allows the minimum to be overridden to allow shorter id lengths.',
140
- allowNull: true,
141
- type: 'integer'
109
+ default: {
110
+ utm_source: { '@path': '$.context.campaign.source' },
111
+ utm_medium: { '@path': '$.context.campaign.medium' },
112
+ utm_campaign: { '@path': '$.context.campaign.name' },
113
+ utm_term: { '@path': '$.context.campaign.term' },
114
+ utm_content: { '@path': '$.context.campaign.content' }
142
115
  }
143
116
  },
144
- perform: (request, { payload, settings }) => {
145
- const { products = [], trackRevenuePerProduct, time, session_id, userAgent, userAgentParsing, utm_properties, referrer, min_id_length, library, ...rest } = actions_core_1.omit(payload, revenueKeys);
146
- const properties = rest;
147
- let options;
148
- if (properties.platform) {
149
- properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android');
150
- }
151
- if (library) {
152
- if (library === 'analytics.js')
153
- properties.platform = 'Web';
154
- }
155
- if (time && dayjs_1.default.utc(time).isValid()) {
156
- properties.time = dayjs_1.default.utc(time).valueOf();
157
- }
158
- if (session_id && dayjs_1.default.utc(session_id).isValid()) {
159
- properties.session_id = dayjs_1.default.utc(session_id).valueOf();
160
- }
161
- if (Object.keys(payload.utm_properties ?? {}).length || payload.referrer) {
162
- properties.user_properties = merge_user_properties_1.mergeUserProperties(utm_1.convertUTMProperties({ utm_properties }), referrer_1.convertReferrerProperty({ referrer }), actions_core_1.omit(properties.user_properties ?? {}, ['utm_properties', 'referrer']));
117
+ referrer: {
118
+ label: 'Referrer',
119
+ type: 'string',
120
+ description: 'The referrer of the web request. Sent to Amplitude as both last touch “referrer” and first touch “initial_referrer”',
121
+ default: {
122
+ '@path': '$.context.page.referrer'
163
123
  }
164
- if (min_id_length && min_id_length > 0) {
165
- options = { min_id_length };
166
- }
167
- const events = [
168
- {
169
- ...(userAgentParsing && user_agent_1.parseUserAgentProperties(userAgent)),
170
- ...actions_core_1.removeUndefined(properties),
171
- ...(products.length && trackRevenuePerProduct ? {} : getRevenueProperties(payload)),
172
- library: 'segment'
173
- }
174
- ];
175
- for (const product of products) {
176
- events.push({
177
- ...properties,
178
- ...(trackRevenuePerProduct ? getRevenueProperties(product) : {}),
179
- event_properties: product,
180
- event_type: 'Product Purchased',
181
- insert_id: properties.insert_id ? `${properties.insert_id}-${events.length + 1}` : undefined,
182
- library: 'segment'
183
- });
184
- }
185
- const endpoint = regional_endpoints_1.getEndpointByRegion(payload.use_batch_endpoint ? 'batch' : 'httpapi', settings.endpoint);
186
- return request(endpoint, {
187
- method: 'post',
188
- json: {
189
- api_key: settings.apiKey,
190
- events,
191
- options
192
- }
193
- });
124
+ },
125
+ min_id_length: {
126
+ label: 'Minimum ID Length',
127
+ description: 'Amplitude has a default minimum id lenght of 5 characters for user_id and device_id fields. This field allows the minimum to be overridden to allow shorter id lengths.',
128
+ allowNull: true,
129
+ type: 'integer'
194
130
  }
195
131
  };
132
+ const action = {
133
+ title: 'Log Event',
134
+ description: 'Send an event to Amplitude.',
135
+ defaultSubscription: 'type = "track" and event != "Order Completed"',
136
+ fields: exports.fields,
137
+ perform: (request, { payload, settings }) => doPerform(request, payload, settings, getEvents)
138
+ };
196
139
  exports.default = action;
197
140
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/amplitude/logEvent/index.ts"],"names":[],"mappings":";;;;;AAAA,wDAA6D;AAC7D,+DAAsC;AACtC,kDAA6C;AAI7C,gCAA6C;AAC7C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;
4
+ event_type: string;
5
+ session_id?: string | number;
6
+ time?: string | number;
7
+ event_properties?: {
8
+ [k: string]: unknown;
9
+ };
10
+ user_properties?: {
11
+ [k: string]: unknown;
12
+ };
13
+ groups?: {
14
+ [k: string]: unknown;
15
+ };
16
+ app_version?: string;
17
+ platform?: string;
18
+ os_name?: string;
19
+ os_version?: string;
20
+ device_brand?: string;
21
+ device_manufacturer?: string;
22
+ device_model?: string;
23
+ carrier?: string;
24
+ country?: string;
25
+ region?: string;
26
+ city?: string;
27
+ dma?: string;
28
+ language?: string;
29
+ price?: number;
30
+ quantity?: number;
31
+ revenue?: number;
32
+ productId?: string;
33
+ revenueType?: string;
34
+ location_lat?: number;
35
+ location_lng?: number;
36
+ ip?: string;
37
+ idfa?: string;
38
+ idfv?: string;
39
+ adid?: string;
40
+ android_id?: string;
41
+ event_id?: number;
42
+ insert_id?: string;
43
+ library?: string;
44
+ use_batch_endpoint?: boolean;
45
+ userAgent?: string;
46
+ userAgentParsing?: boolean;
47
+ utm_properties?: {
48
+ utm_source?: string;
49
+ utm_medium?: string;
50
+ utm_campaign?: string;
51
+ utm_term?: string;
52
+ utm_content?: string;
53
+ };
54
+ referrer?: string;
55
+ min_id_length?: number | null;
56
+ trackRevenuePerProduct?: boolean;
57
+ products?: {
58
+ price?: number;
59
+ quantity?: number;
60
+ revenue?: number;
61
+ productId?: string;
62
+ revenueType?: string;
63
+ }[];
64
+ }
@@ -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/amplitude/logPurchase/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { 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,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const user_agent_1 = require("../user-agent");
5
+ const logEvent_1 = require("../logEvent");
6
+ const logEvent_2 = require("../logEvent");
7
+ function getRevenueProperties(payload) {
8
+ if (typeof payload.revenue !== 'number') {
9
+ return {};
10
+ }
11
+ return {
12
+ revenue: payload.revenue,
13
+ revenueType: payload.revenueType ?? 'Purchase',
14
+ quantity: typeof payload.quantity === 'number' ? Math.round(payload.quantity) : undefined,
15
+ price: payload.price,
16
+ productId: payload.productId
17
+ };
18
+ }
19
+ function getEvents(payload, properties) {
20
+ const { products = [], userAgent, userAgentParsing, trackRevenuePerProduct } = payload;
21
+ const events = [
22
+ {
23
+ ...(userAgentParsing && user_agent_1.parseUserAgentProperties(userAgent)),
24
+ ...actions_core_1.removeUndefined(properties),
25
+ ...(products?.length && trackRevenuePerProduct ? {} : getRevenueProperties(payload)),
26
+ library: 'segment'
27
+ }
28
+ ];
29
+ for (const product of products) {
30
+ events.push({
31
+ ...properties,
32
+ ...(trackRevenuePerProduct ? getRevenueProperties(product) : {}),
33
+ event_properties: product,
34
+ event_type: 'Product Purchased',
35
+ insert_id: properties.insert_id ? `${properties.insert_id}-${events.length + 1}` : undefined,
36
+ library: 'segment'
37
+ });
38
+ }
39
+ return events;
40
+ }
41
+ const action = {
42
+ title: 'Log Purchase',
43
+ description: 'Send an event to Amplitude.',
44
+ defaultSubscription: 'type = "track" and event = "Order Completed"',
45
+ fields: {
46
+ ...logEvent_2.fields,
47
+ trackRevenuePerProduct: {
48
+ label: 'Track Revenue Per Product',
49
+ description: 'When enabled, track revenue with each product within the event. When disabled, track total revenue once for the event.',
50
+ type: 'boolean',
51
+ default: false
52
+ },
53
+ products: {
54
+ label: 'Products',
55
+ description: 'The list of products purchased.',
56
+ type: 'object',
57
+ multiple: true,
58
+ properties: {
59
+ price: {
60
+ label: 'Price',
61
+ type: 'number',
62
+ description: 'The price of the item purchased. Required for revenue data if the revenue field is not sent. You can use negative values to indicate refunds.'
63
+ },
64
+ quantity: {
65
+ label: 'Quantity',
66
+ type: 'integer',
67
+ description: 'The quantity of the item purchased. Defaults to 1 if not specified.'
68
+ },
69
+ revenue: {
70
+ label: 'Revenue',
71
+ type: 'number',
72
+ description: 'Revenue = price * quantity. If you send all 3 fields of price, quantity, and revenue, then (price * quantity) will be used as the revenue value. You can use negative values to indicate refunds.'
73
+ },
74
+ productId: {
75
+ label: 'Product ID',
76
+ type: 'string',
77
+ description: 'An identifier for the item purchased. You must send a price and quantity or revenue with this field.'
78
+ },
79
+ revenueType: {
80
+ label: 'Revenue Type',
81
+ type: 'string',
82
+ description: 'The type of revenue for the item purchased. You must send a price and quantity or revenue with this field.'
83
+ }
84
+ },
85
+ default: {
86
+ '@path': '$.properties.products'
87
+ }
88
+ }
89
+ },
90
+ perform: (request, { payload, settings }) => logEvent_1.doPerform(request, payload, settings, getEvents)
91
+ };
92
+ exports.default = action;
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/amplitude/logPurchase/index.ts"],"names":[],"mappings":";;AAAA,wDAAuD;AAIvD,8CAAwD;AACxD,0CAAuD;AACvD,0CAAsD;AAUtD,SAAS,oBAAoB,CAAC,OAAqB;IACjD,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE;QACvC,OAAO,EAAE,CAAA;KACV;IAED,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,UAAU;QAC9C,QAAQ,EAAE,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;QACzF,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,SAAS,EAAE,OAAO,C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AAQ,EAAE;YACR,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,iCAAiC;YAC9C,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,KAAK,EAAE,OAAO;oBACd,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,+IAA+I;iBAClJ;gBACD,QAAQ,EAAE;oBACR,KAAK,EAAE,UAAU;oBACjB,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,qEAAqE;iBACnF;gBACD,OAAO,EAAE;oBACP,KAAK,EAAE,SAAS;oBAChB,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,mMAAmM;iBACtM;gBACD,SAAS,EAAE;oBACT,KAAK,EAAE,YAAY;oBACnB,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,sGAAsG;iBACzG;gBACD,WAAW,EAAE;oBACX,KAAK,EAAE,cAAc;oBACrB,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,4GAA4G;iBAC/G;aACF;YACD,OAAO,EAAE;gBACP,OAAO,EAAE,uBAAuB;aACjC;SACF;KACF;IACD,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,oBAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC;CAC9F,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -26,6 +26,9 @@ export interface Payload {
26
26
  price?: number;
27
27
  quantity?: number;
28
28
  }[];
29
+ user_properties?: {
30
+ [k: string]: unknown;
31
+ };
29
32
  params?: {
30
33
  [k: string]: unknown;
31
34
  };
@@ -18,6 +18,7 @@ const action = {
18
18
  ...ga4_properties_1.items_multi_products,
19
19
  required: true
20
20
  },
21
+ user_properties: ga4_properties_1.user_properties,
21
22
  params: ga4_properties_1.params
22
23
  },
23
24
  perform: (request, { payload }) => {
@@ -62,7 +63,8 @@ const action = {
62
63
  ...payload.params
63
64
  }
64
65
  }
65
- ]
66
+ ],
67
+ ...ga4_properties_1.formatUserProperties(payload.user_properties)
66
68
  }
67
69
  });
68
70
  }