@segment/analytics-browser-actions-tiktok-pixel 1.94.1-staging-108b283de.0 → 1.95.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 (75) hide show
  1. package/dist/cjs/constants.d.ts +2 -0
  2. package/dist/cjs/constants.js +6 -0
  3. package/dist/cjs/constants.js.map +1 -0
  4. package/dist/cjs/fields/common_fields.d.ts +2 -0
  5. package/dist/cjs/{common_fields.js → fields/common_fields.js} +2 -113
  6. package/dist/cjs/fields/common_fields.js.map +1 -0
  7. package/dist/cjs/identify/generated-types.d.ts +0 -17
  8. package/dist/cjs/identify/index.js +10 -20
  9. package/dist/cjs/identify/index.js.map +1 -1
  10. package/dist/cjs/reportWebEvent/fields.d.ts +2 -0
  11. package/dist/cjs/reportWebEvent/fields.js +161 -0
  12. package/dist/cjs/reportWebEvent/fields.js.map +1 -0
  13. package/dist/cjs/reportWebEvent/generated-types.d.ts +62 -11
  14. package/dist/cjs/reportWebEvent/index.js +12 -24
  15. package/dist/cjs/reportWebEvent/index.js.map +1 -1
  16. package/dist/cjs/reportWebEvent/travel_fields.d.ts +2 -0
  17. package/dist/cjs/reportWebEvent/travel_fields.js +210 -0
  18. package/dist/cjs/reportWebEvent/travel_fields.js.map +1 -0
  19. package/dist/cjs/reportWebEvent/utils.d.ts +3 -0
  20. package/dist/cjs/reportWebEvent/utils.js +101 -0
  21. package/dist/cjs/reportWebEvent/utils.js.map +1 -0
  22. package/dist/cjs/reportWebEvent/vehicle_fields.d.ts +2 -0
  23. package/dist/cjs/reportWebEvent/vehicle_fields.js +255 -0
  24. package/dist/cjs/reportWebEvent/vehicle_fields.js.map +1 -0
  25. package/dist/cjs/types.d.ts +85 -29
  26. package/dist/cjs/utils.d.ts +4 -0
  27. package/dist/cjs/utils.js +18 -0
  28. package/dist/cjs/utils.js.map +1 -0
  29. package/dist/esm/constants.d.ts +2 -0
  30. package/dist/esm/constants.js +3 -0
  31. package/dist/esm/constants.js.map +1 -0
  32. package/dist/esm/fields/common_fields.d.ts +2 -0
  33. package/dist/esm/{common_fields.js → fields/common_fields.js} +1 -112
  34. package/dist/esm/fields/common_fields.js.map +1 -0
  35. package/dist/esm/identify/generated-types.d.ts +0 -17
  36. package/dist/esm/identify/index.js +10 -20
  37. package/dist/esm/identify/index.js.map +1 -1
  38. package/dist/esm/reportWebEvent/fields.d.ts +2 -0
  39. package/dist/esm/reportWebEvent/fields.js +158 -0
  40. package/dist/esm/reportWebEvent/fields.js.map +1 -0
  41. package/dist/esm/reportWebEvent/generated-types.d.ts +62 -11
  42. package/dist/esm/reportWebEvent/index.js +12 -24
  43. package/dist/esm/reportWebEvent/index.js.map +1 -1
  44. package/dist/esm/reportWebEvent/travel_fields.d.ts +2 -0
  45. package/dist/esm/reportWebEvent/travel_fields.js +207 -0
  46. package/dist/esm/reportWebEvent/travel_fields.js.map +1 -0
  47. package/dist/esm/reportWebEvent/utils.d.ts +3 -0
  48. package/dist/esm/reportWebEvent/utils.js +98 -0
  49. package/dist/esm/reportWebEvent/utils.js.map +1 -0
  50. package/dist/esm/reportWebEvent/vehicle_fields.d.ts +2 -0
  51. package/dist/esm/reportWebEvent/vehicle_fields.js +252 -0
  52. package/dist/esm/reportWebEvent/vehicle_fields.js.map +1 -0
  53. package/dist/esm/types.d.ts +85 -29
  54. package/dist/esm/utils.d.ts +4 -0
  55. package/dist/esm/utils.js +15 -0
  56. package/dist/esm/utils.js.map +1 -0
  57. package/dist/tsconfig.tsbuildinfo +1 -1
  58. package/package.json +4 -4
  59. package/src/constants.ts +2 -0
  60. package/src/{common_fields.ts → fields/common_fields.ts} +1 -114
  61. package/src/identify/generated-types.ts +0 -65
  62. package/src/identify/index.ts +10 -20
  63. package/src/reportWebEvent/__tests__/index.test.ts +521 -23
  64. package/src/reportWebEvent/fields.ts +162 -0
  65. package/src/reportWebEvent/generated-types.ts +239 -41
  66. package/src/reportWebEvent/index.ts +14 -26
  67. package/src/reportWebEvent/travel_fields.ts +216 -0
  68. package/src/reportWebEvent/utils.ts +167 -0
  69. package/src/reportWebEvent/vehicle_fields.ts +255 -0
  70. package/src/types.ts +89 -54
  71. package/src/utils.ts +18 -0
  72. package/dist/cjs/common_fields.d.ts +0 -2
  73. package/dist/cjs/common_fields.js.map +0 -1
  74. package/dist/esm/common_fields.d.ts +0 -2
  75. package/dist/esm/common_fields.js.map +0 -1
@@ -0,0 +1,162 @@
1
+ import { InputField } from '@segment/actions-core'
2
+ import { VEHICLE_FIELDS, TRAVEL_FIELDS } from '../constants'
3
+
4
+ export const track_fields: Record<string, InputField> = {
5
+ event_spec_type: {
6
+ label: 'Additional Fields',
7
+ type: 'string',
8
+ description: 'Include fields for travel or vehicle events.',
9
+ choices: [
10
+ { value: TRAVEL_FIELDS, label: 'Travel Fields' },
11
+ { value: VEHICLE_FIELDS, label: 'Vehicle Fields' }
12
+ ]
13
+ },
14
+ event: {
15
+ label: 'Event Name',
16
+ type: 'string',
17
+ required: true,
18
+ description:
19
+ 'Conversion event name. Please refer to the "Supported Web Events" section on in TikTok’s [Pixel SDK documentation](https://business-api.tiktok.com/portal/docs?id=1739585696931842) for accepted event names.'
20
+ },
21
+ event_id: {
22
+ label: 'Event ID',
23
+ type: 'string',
24
+ description: 'Any hashed ID that can identify a unique user/session.',
25
+ default: {
26
+ '@path': '$.messageId'
27
+ }
28
+ },
29
+ order_id: {
30
+ label: 'Order ID',
31
+ type: 'string',
32
+ description: 'Order ID of the transaction.',
33
+ default: {
34
+ '@path': '$.properties.order_id'
35
+ }
36
+ },
37
+ shop_id: {
38
+ label: 'Shop ID',
39
+ type: 'string',
40
+ description: 'Shop ID of the transaction.',
41
+ default: {
42
+ '@path': '$.properties.shop_id'
43
+ }
44
+ },
45
+ contents: {
46
+ label: 'Contents',
47
+ type: 'object',
48
+ multiple: true,
49
+ description: 'Related item details for the event.',
50
+ properties: {
51
+ price: {
52
+ label: 'Price',
53
+ description: 'Price of the item.',
54
+ type: 'number'
55
+ },
56
+ quantity: {
57
+ label: 'Quantity',
58
+ description: 'Number of items.',
59
+ type: 'number'
60
+ },
61
+ content_category: {
62
+ label: 'Content Category',
63
+ description: 'Category of the product item.',
64
+ type: 'string'
65
+ },
66
+ content_id: {
67
+ label: 'Content ID',
68
+ description: 'ID of the product item.',
69
+ type: 'string'
70
+ },
71
+ content_name: {
72
+ label: 'Content Name',
73
+ description: 'Name of the product item.',
74
+ type: 'string'
75
+ },
76
+ brand: {
77
+ label: 'Brand',
78
+ description: 'Brand name of the product item.',
79
+ type: 'string'
80
+ }
81
+ }
82
+ },
83
+ content_ids: {
84
+ label: 'Content IDs',
85
+ description:
86
+ "Product IDs associated with the event, such as SKUs. Do not populate this field if the 'Contents' field is populated. This field accepts a single string value or an array of string values.",
87
+ type: 'string',
88
+ multiple: true,
89
+ default: {
90
+ '@path': '$.properties.content_ids'
91
+ }
92
+ },
93
+ num_items: {
94
+ label: 'Number of Items',
95
+ type: 'number',
96
+ description: 'Number of items when checkout was initiated. Used with the InitiateCheckout event.',
97
+ default: {
98
+ '@path': '$.properties.num_items'
99
+ }
100
+ },
101
+ content_type: {
102
+ label: 'Content Type',
103
+ description:
104
+ 'Type of the product item. When the `content_id` in the `Contents` field is specified as a `sku_id`, set this field to `product`. When the `content_id` in the `Contents` field is specified as an `item_group_id`, set this field to `product_group`.',
105
+ type: 'string',
106
+ choices: [
107
+ { label: 'product', value: 'product' },
108
+ { label: 'product_group', value: 'product_group' }
109
+ ],
110
+ default: 'product'
111
+ },
112
+ currency: {
113
+ label: 'Currency',
114
+ type: 'string',
115
+ description: 'Currency for the value specified as ISO 4217 code.',
116
+ default: {
117
+ '@path': '$.properties.currency'
118
+ }
119
+ },
120
+ value: {
121
+ label: 'Value',
122
+ type: 'number',
123
+ description: 'Value of the order or items sold.',
124
+ default: {
125
+ '@if': {
126
+ exists: { '@path': '$.properties.value' },
127
+ then: { '@path': '$.properties.value' },
128
+ else: { '@path': '$.properties.revenue' }
129
+ }
130
+ }
131
+ },
132
+ description: {
133
+ label: 'Description',
134
+ type: 'string',
135
+ description: 'A string description of the web event.'
136
+ },
137
+ query: {
138
+ label: 'Query',
139
+ type: 'string',
140
+ description: 'The text string that was searched for.',
141
+ default: {
142
+ '@path': '$.properties.query'
143
+ }
144
+ },
145
+ search_string: {
146
+ label: 'Search String',
147
+ type: 'string',
148
+ description: 'The text string entered by the user for the search. Optionally used with the Search event.',
149
+ default: {
150
+ '@path': '$.properties.search_string'
151
+ },
152
+ depends_on: {
153
+ conditions: [
154
+ {
155
+ fieldKey: 'event',
156
+ operator: 'is',
157
+ value: 'Search'
158
+ }
159
+ ]
160
+ }
161
+ }
162
+ }
@@ -1,6 +1,10 @@
1
1
  // Generated file. DO NOT MODIFY IT BY HAND.
2
2
 
3
3
  export interface Payload {
4
+ /**
5
+ * Include fields for travel or vehicle events.
6
+ */
7
+ event_spec_type?: string
4
8
  /**
5
9
  * Conversion event name. Please refer to the "Supported Web Events" section on in TikTok’s [Pixel SDK documentation](https://business-api.tiktok.com/portal/docs?id=1739585696931842) for accepted event names.
6
10
  */
@@ -9,43 +13,6 @@ export interface Payload {
9
13
  * Any hashed ID that can identify a unique user/session.
10
14
  */
11
15
  event_id?: string
12
- /**
13
- * A single phone number in E.164 standard format. TikTok Pixel will hash this value before sending to TikTok. e.g. +14150000000. Segment will hash this value before sending to TikTok.
14
- */
15
- phone_number?: string[]
16
- /**
17
- * A single email address. TikTok Pixel will be hash this value before sending to TikTok.
18
- */
19
- email?: string[]
20
- /**
21
- * The first name of the customer. The name should be in lowercase without any punctuation. Special characters are allowed.
22
- */
23
- first_name?: string
24
- /**
25
- * The last name of the customer. The name should be in lowercase without any punctuation. Special characters are allowed.
26
- */
27
- last_name?: string
28
- /**
29
- * The address of the customer.
30
- */
31
- address?: {
32
- /**
33
- * The customer's city.
34
- */
35
- city?: string
36
- /**
37
- * The customer's country.
38
- */
39
- country?: string
40
- /**
41
- * The customer's Zip Code.
42
- */
43
- zip_code?: string
44
- /**
45
- * The customer's State.
46
- */
47
- state?: string
48
- }
49
16
  /**
50
17
  * Order ID of the transaction.
51
18
  */
@@ -54,10 +21,6 @@ export interface Payload {
54
21
  * Shop ID of the transaction.
55
22
  */
56
23
  shop_id?: string
57
- /**
58
- * Uniquely identifies the user who triggered the conversion event. TikTok Pixel will hash this value before sending to TikTok.
59
- */
60
- external_id?: string[]
61
24
  /**
62
25
  * Related item details for the event.
63
26
  */
@@ -87,6 +50,14 @@ export interface Payload {
87
50
  */
88
51
  brand?: string
89
52
  }[]
53
+ /**
54
+ * Product IDs associated with the event, such as SKUs. Do not populate this field if the 'Contents' field is populated. This field accepts a single string value or an array of string values.
55
+ */
56
+ content_ids?: string[]
57
+ /**
58
+ * Number of items when checkout was initiated. Used with the InitiateCheckout event.
59
+ */
60
+ num_items?: number
90
61
  /**
91
62
  * Type of the product item. When the `content_id` in the `Contents` field is specified as a `sku_id`, set this field to `product`. When the `content_id` in the `Contents` field is specified as an `item_group_id`, set this field to `product_group`.
92
63
  */
@@ -107,4 +78,231 @@ export interface Payload {
107
78
  * The text string that was searched for.
108
79
  */
109
80
  query?: string
81
+ /**
82
+ * The text string entered by the user for the search. Optionally used with the Search event.
83
+ */
84
+ search_string?: string
85
+ /**
86
+ * A single phone number in E.164 standard format. TikTok Pixel will hash this value before sending to TikTok. e.g. +14150000000. Segment will hash this value before sending to TikTok.
87
+ */
88
+ phone_number?: string[]
89
+ /**
90
+ * A single email address. TikTok Pixel will be hash this value before sending to TikTok.
91
+ */
92
+ email?: string[]
93
+ /**
94
+ * The first name of the customer. The name should be in lowercase without any punctuation. Special characters are allowed.
95
+ */
96
+ first_name?: string
97
+ /**
98
+ * The last name of the customer. The name should be in lowercase without any punctuation. Special characters are allowed.
99
+ */
100
+ last_name?: string
101
+ /**
102
+ * The address of the customer.
103
+ */
104
+ address?: {
105
+ /**
106
+ * The customer's city.
107
+ */
108
+ city?: string
109
+ /**
110
+ * The customer's country.
111
+ */
112
+ country?: string
113
+ /**
114
+ * The customer's Zip Code.
115
+ */
116
+ zip_code?: string
117
+ /**
118
+ * The customer's State.
119
+ */
120
+ state?: string
121
+ }
122
+ /**
123
+ * Uniquely identifies the user who triggered the conversion event. TikTok Pixel will hash this value before sending to TikTok.
124
+ */
125
+ external_id?: string[]
126
+ /**
127
+ * Fields related to vehicle events.
128
+ */
129
+ vehicle_fields?: {
130
+ /**
131
+ * Postal code for the vehicle location.
132
+ */
133
+ postal_code?: string
134
+ /**
135
+ * Vehicle make/brand/manufacturer.
136
+ */
137
+ make?: string
138
+ /**
139
+ * Vehicle model.
140
+ */
141
+ model?: string
142
+ /**
143
+ * Year the vehicle was laucned in yyyy format.
144
+ */
145
+ year?: number
146
+ /**
147
+ * Vehicle status.
148
+ */
149
+ state_of_vehicle?: string
150
+ /**
151
+ * Vehicle mileage (in km or miles). Zero (0) for new vehicle.
152
+ */
153
+ mileage_value?: number
154
+ /**
155
+ * Mileage unites in miles (MI) or kilometers (KM).
156
+ */
157
+ mileage_unit?: string
158
+ /**
159
+ * Vehicle exterior color.
160
+ */
161
+ exterior_color?: string
162
+ /**
163
+ * Vehicle transmission type.
164
+ */
165
+ transmission?: string
166
+ /**
167
+ * Vehicle body type.
168
+ */
169
+ body_style?: string
170
+ /**
171
+ * Vehicle fuel type.
172
+ */
173
+ fuel_type?: string
174
+ /**
175
+ * Vehicle drivetrain.
176
+ */
177
+ drivetrain?: string
178
+ /**
179
+ * Minimum preferred price of the vehicle.
180
+ */
181
+ preferred_price_range_min?: number
182
+ /**
183
+ * Maximum preferred price of the vehicle.
184
+ */
185
+ preferred_price_range_max?: number
186
+ /**
187
+ * Vehicle trim.
188
+ */
189
+ trim?: string
190
+ /**
191
+ * Vehicle identification number. Maximum characters: 17.
192
+ */
193
+ vin?: string
194
+ /**
195
+ * Vehicle interior color.
196
+ */
197
+ interior_color?: string
198
+ /**
199
+ * Vehicle drivetrain.
200
+ */
201
+ condition_of_vehicle?: string
202
+ /**
203
+ * Optional for ViewContent. Use viewcontent_type to differentiate between soft lead landing pages.
204
+ */
205
+ viewcontent_type?: string
206
+ /**
207
+ * Optional for Search. Use search_type to differentiate other user searches (such as dealer lookup) from inventory search.
208
+ */
209
+ search_type?: string
210
+ /**
211
+ * Optional for CompleteRegistration. Use registration_type to differentiate between different types of customer registration on websites.
212
+ */
213
+ registration_type?: string
214
+ }
215
+ /**
216
+ * Fields related to travel events.
217
+ */
218
+ travel_fields?: {
219
+ /**
220
+ * Hotel city location.
221
+ */
222
+ city?: string
223
+ /**
224
+ * Hotel region location.
225
+ */
226
+ region?: string
227
+ /**
228
+ * Hotel country location.
229
+ */
230
+ country?: string
231
+ /**
232
+ * Hotel check-in date.
233
+ */
234
+ checkin_date?: string
235
+ /**
236
+ * Hotel check-out date.
237
+ */
238
+ checkout_date?: string
239
+ /**
240
+ * Number of adults.
241
+ */
242
+ num_adults?: number
243
+ /**
244
+ * Number of children.
245
+ */
246
+ num_children?: number
247
+ /**
248
+ * Number of infants flying.
249
+ */
250
+ num_infants?: number
251
+ /**
252
+ * Suggested hotels. This can be a single string value or an array of string values.
253
+ */
254
+ suggested_hotels?: string[]
255
+ /**
256
+ * Date of flight departure. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD
257
+ */
258
+ departing_departure_date?: string
259
+ /**
260
+ * Date of return flight. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD
261
+ */
262
+ returning_departure_date?: string
263
+ /**
264
+ * Origin airport.
265
+ */
266
+ origin_airport?: string
267
+ /**
268
+ * Destination airport.
269
+ */
270
+ destination_airport?: string
271
+ /**
272
+ * If a client has a destination catalog, the client can associate one or more destinations in the catalog with a specific flight event. For instance, link a particular route to a nearby museum and a nearby beach, both of which are destinations in the catalog. This field accepts a single string value or an array of string values.
273
+ */
274
+ destination_ids?: string[]
275
+ /**
276
+ * The date and time for arrival at the destination of the outbound journey. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD
277
+ */
278
+ departing_arrival_date?: string
279
+ /**
280
+ * The date and time when the return journey is completed. Accepted date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD
281
+ */
282
+ returning_arrival_date?: string
283
+ /**
284
+ * Class of the flight ticket, must be: "eco", "prem", "bus", "first".
285
+ */
286
+ travel_class?: string
287
+ /**
288
+ * Represents the relative value of this potential customer to advertiser.
289
+ */
290
+ user_score?: number
291
+ /**
292
+ * The preferred number of stops the user is looking for. 0 for direct flight.
293
+ */
294
+ preferred_num_stops?: number
295
+ /**
296
+ * The start date of user's trip. Accept date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD.
297
+ */
298
+ travel_start?: string
299
+ /**
300
+ * The end date of user's trip. Accept date formats: YYYYMMDD, YYYY-MM-DD, YYYY-MM-DDThh:mmTZD, and YYYY-MM-DDThh:mm:ssTZD.
301
+ */
302
+ travel_end?: string
303
+ /**
304
+ * A list of IDs representing destination suggestions for this user. This parameter is not applicable for the Search event. This field accepts a single string value or an array of string values.
305
+ */
306
+ suggested_destinations?: string[]
307
+ }
110
308
  }
@@ -1,9 +1,13 @@
1
1
  import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
2
2
  import type { Settings } from '../generated-types'
3
3
  import type { Payload } from './generated-types'
4
- import { formatPhone, handleArrayInput, formatString, formatAddress } from '../formatter'
4
+ import { getUser } from '../utils'
5
+ import { getAllProperties } from './utils'
5
6
  import { TikTokPixel } from '../types'
6
- import { commonFields } from '../common_fields'
7
+ import { track_fields } from './fields'
8
+ import { common_fields } from '../fields/common_fields'
9
+ import { travel_fields } from './travel_fields'
10
+ import { vehicle_fields } from './vehicle_fields'
7
11
 
8
12
  const action: BrowserActionDefinition<Settings, TikTokPixel, Payload> = {
9
13
  title: 'Report Web Event',
@@ -12,36 +16,20 @@ const action: BrowserActionDefinition<Settings, TikTokPixel, Payload> = {
12
16
  platform: 'web',
13
17
  defaultSubscription: 'type = "track"',
14
18
  fields: {
15
- ...commonFields
19
+ ...track_fields,
20
+ ...common_fields,
21
+ vehicle_fields,
22
+ travel_fields
16
23
  },
17
24
  perform: (ttq, { payload, settings }) => {
18
25
  if (payload.email || payload.phone_number || payload.external_id) {
19
- ttq.identify({
20
- email: handleArrayInput(payload.email),
21
- phone_number: formatPhone(handleArrayInput(payload.phone_number)),
22
- external_id: handleArrayInput(payload.external_id),
23
- first_name: formatString(payload.first_name),
24
- last_name: formatString(payload.last_name),
25
- city: formatAddress(payload.address?.city),
26
- state: formatAddress(payload.address?.state),
27
- country: formatAddress(payload.address?.country),
28
- zip_code: formatString(payload.address?.zip_code)
29
- })
26
+ ttq.instance(settings.pixelCode).identify(getUser(payload))
30
27
  }
31
28
 
32
29
  ttq.instance(settings.pixelCode).track(
33
- payload.event,
34
- {
35
- contents: payload.contents ? payload.contents : [],
36
- content_type: payload.content_type ? payload.content_type : undefined,
37
- currency: payload.currency ? payload.currency : 'USD',
38
- value: payload.value || payload.value === 0 ? payload.value : undefined,
39
- query: payload.query ? payload.query : undefined,
40
- description: payload.description ? payload.description : undefined,
41
- order_id: payload.order_id ? payload.order_id : undefined,
42
- shop_id: payload.shop_id ? payload.shop_id : undefined
43
- },
44
- {
30
+ payload.event,
31
+ getAllProperties(payload),
32
+ {
45
33
  event_id: payload.event_id ? payload.event_id : ''
46
34
  }
47
35
  )