@segment/analytics-browser-actions-tiktok-pixel 1.33.0 → 1.35.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.
- package/dist/cjs/common_fields.d.ts +2 -0
- package/dist/cjs/common_fields.js +156 -0
- package/dist/cjs/common_fields.js.map +1 -0
- package/dist/cjs/generated-types.d.ts +1 -0
- package/dist/cjs/index.js +89 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/init-script.d.ts +1 -1
- package/dist/cjs/init-script.js +4 -2
- package/dist/cjs/init-script.js.map +1 -1
- package/dist/cjs/reportWebEvent/formatter.d.ts +1 -0
- package/dist/cjs/reportWebEvent/formatter.js +12 -1
- package/dist/cjs/reportWebEvent/formatter.js.map +1 -1
- package/dist/cjs/reportWebEvent/generated-types.d.ts +9 -4
- package/dist/cjs/reportWebEvent/index.js +12 -122
- package/dist/cjs/reportWebEvent/index.js.map +1 -1
- package/dist/cjs/types.d.ts +12 -7
- package/dist/esm/common_fields.d.ts +2 -0
- package/dist/esm/common_fields.js +153 -0
- package/dist/esm/common_fields.js.map +1 -0
- package/dist/esm/generated-types.d.ts +1 -0
- package/dist/esm/index.js +89 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/init-script.d.ts +1 -1
- package/dist/esm/init-script.js +4 -2
- package/dist/esm/init-script.js.map +1 -1
- package/dist/esm/reportWebEvent/formatter.d.ts +1 -0
- package/dist/esm/reportWebEvent/formatter.js +10 -0
- package/dist/esm/reportWebEvent/formatter.js.map +1 -1
- package/dist/esm/reportWebEvent/generated-types.d.ts +9 -4
- package/dist/esm/reportWebEvent/index.js +13 -123
- package/dist/esm/reportWebEvent/index.js.map +1 -1
- package/dist/esm/types.d.ts +12 -7
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/common_fields.ts +158 -0
- package/src/generated-types.ts +5 -1
- package/src/index.ts +91 -7
- package/src/init-script.ts +4 -2
- package/src/reportWebEvent/__tests__/index.test.ts +128 -6
- package/src/reportWebEvent/formatter.ts +9 -0
- package/src/reportWebEvent/generated-types.ts +30 -10
- package/src/reportWebEvent/index.ts +15 -130
- package/src/types.ts +15 -7
package/src/index.ts
CHANGED
|
@@ -19,11 +19,17 @@ const productProperties = {
|
|
|
19
19
|
quantity: {
|
|
20
20
|
'@path': '$.quantity'
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
content_category: {
|
|
23
23
|
'@path': '$.category'
|
|
24
24
|
},
|
|
25
25
|
content_id: {
|
|
26
26
|
'@path': '$.product_id'
|
|
27
|
+
},
|
|
28
|
+
content_name: {
|
|
29
|
+
'@path': '$.name'
|
|
30
|
+
},
|
|
31
|
+
brand: {
|
|
32
|
+
'@path': '$.brand'
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
|
|
@@ -57,9 +63,49 @@ export const destination: BrowserDestinationDefinition<Settings, TikTokPixel> =
|
|
|
57
63
|
slug: 'actions-tiktok-pixel',
|
|
58
64
|
mode: 'device',
|
|
59
65
|
presets: [
|
|
66
|
+
{
|
|
67
|
+
name: 'Complete Payment',
|
|
68
|
+
subscribe: 'event = "Order Completed"',
|
|
69
|
+
partnerAction: 'reportWebEvent',
|
|
70
|
+
mapping: {
|
|
71
|
+
...multiProductContents,
|
|
72
|
+
event: 'CompletePayment'
|
|
73
|
+
},
|
|
74
|
+
type: 'automatic'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'Contact',
|
|
78
|
+
subscribe: 'event = "Callback Started"',
|
|
79
|
+
partnerAction: 'reportWebEvent',
|
|
80
|
+
mapping: {
|
|
81
|
+
...defaultValues(reportWebEvent.fields),
|
|
82
|
+
event: 'Contact'
|
|
83
|
+
},
|
|
84
|
+
type: 'automatic'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'Subscribe',
|
|
88
|
+
subscribe: 'event = "Subscription Created"',
|
|
89
|
+
partnerAction: 'reportWebEvent',
|
|
90
|
+
mapping: {
|
|
91
|
+
...defaultValues(reportWebEvent.fields),
|
|
92
|
+
event: 'Subscribe'
|
|
93
|
+
},
|
|
94
|
+
type: 'automatic'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'Submit Form',
|
|
98
|
+
subscribe: 'event = "Form Submitted"',
|
|
99
|
+
partnerAction: 'reportWebEvent',
|
|
100
|
+
mapping: {
|
|
101
|
+
...defaultValues(reportWebEvent.fields),
|
|
102
|
+
event: 'SubmitForm'
|
|
103
|
+
},
|
|
104
|
+
type: 'automatic'
|
|
105
|
+
},
|
|
60
106
|
{
|
|
61
107
|
name: 'View Content',
|
|
62
|
-
subscribe: '
|
|
108
|
+
subscribe: 'event = "Product Viewed"',
|
|
63
109
|
partnerAction: 'reportWebEvent',
|
|
64
110
|
mapping: {
|
|
65
111
|
...singleProductContents,
|
|
@@ -67,6 +113,16 @@ export const destination: BrowserDestinationDefinition<Settings, TikTokPixel> =
|
|
|
67
113
|
},
|
|
68
114
|
type: 'automatic'
|
|
69
115
|
},
|
|
116
|
+
{
|
|
117
|
+
name: 'Click Button',
|
|
118
|
+
subscribe: 'event = "Product Clicked"',
|
|
119
|
+
partnerAction: 'reportWebEvent',
|
|
120
|
+
mapping: {
|
|
121
|
+
...singleProductContents,
|
|
122
|
+
event: 'ClickButton'
|
|
123
|
+
},
|
|
124
|
+
type: 'automatic'
|
|
125
|
+
},
|
|
70
126
|
{
|
|
71
127
|
name: 'Search',
|
|
72
128
|
subscribe: 'event = "Products Searched"',
|
|
@@ -119,13 +175,33 @@ export const destination: BrowserDestinationDefinition<Settings, TikTokPixel> =
|
|
|
119
175
|
},
|
|
120
176
|
{
|
|
121
177
|
name: 'Place an Order',
|
|
122
|
-
subscribe: 'event = "Order
|
|
178
|
+
subscribe: 'event = "Order Placed"',
|
|
123
179
|
partnerAction: 'reportWebEvent',
|
|
124
180
|
mapping: {
|
|
125
181
|
...multiProductContents,
|
|
126
182
|
event: 'PlaceAnOrder'
|
|
127
183
|
},
|
|
128
184
|
type: 'automatic'
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: 'Download',
|
|
188
|
+
subscribe: 'event = "Download Link Clicked"',
|
|
189
|
+
partnerAction: 'reportWebEvent',
|
|
190
|
+
mapping: {
|
|
191
|
+
...defaultValues(reportWebEvent.fields),
|
|
192
|
+
event: 'Download'
|
|
193
|
+
},
|
|
194
|
+
type: 'automatic'
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'Complete Registration',
|
|
198
|
+
subscribe: 'event = "Signed Up"',
|
|
199
|
+
partnerAction: 'reportWebEvent',
|
|
200
|
+
mapping: {
|
|
201
|
+
...defaultValues(reportWebEvent.fields),
|
|
202
|
+
event: 'CompleteRegistration'
|
|
203
|
+
},
|
|
204
|
+
type: 'automatic'
|
|
129
205
|
}
|
|
130
206
|
],
|
|
131
207
|
settings: {
|
|
@@ -136,16 +212,24 @@ export const destination: BrowserDestinationDefinition<Settings, TikTokPixel> =
|
|
|
136
212
|
"Your TikTok Pixel ID. Please see TikTok's [Pixel documentation](https://ads.tiktok.com/marketing_api/docs?id=1739583652957185) for information on how to find this value.",
|
|
137
213
|
required: true
|
|
138
214
|
},
|
|
139
|
-
|
|
140
|
-
label: '
|
|
215
|
+
ldu: {
|
|
216
|
+
label: 'Limited Data Use',
|
|
141
217
|
type: 'boolean',
|
|
142
218
|
description:
|
|
143
|
-
'
|
|
219
|
+
'In order to help facilitate advertiser\'s compliance with the right to opt-out of sale and sharing of personal data under certain U.S. state privacy laws, TikTok offers a Limited Data Use ("LDU") feature. For more information, please refer to TikTok\'s [documentation page](https://business-api.tiktok.com/portal/docs?id=1770092377990145).'
|
|
220
|
+
},
|
|
221
|
+
useExistingPixel: {
|
|
222
|
+
// TODO: HOW TO DELETE (reusing will not include Segment Partner name)
|
|
223
|
+
label: '[Deprecated] Use Existing Pixel',
|
|
224
|
+
type: 'boolean',
|
|
225
|
+
default: false,
|
|
226
|
+
required: false,
|
|
227
|
+
description: 'Deprecated. Please do not provide any value.'
|
|
144
228
|
}
|
|
145
229
|
},
|
|
146
230
|
initialize: async ({ settings }, deps) => {
|
|
147
231
|
if (!settings.useExistingPixel) {
|
|
148
|
-
initScript(settings
|
|
232
|
+
initScript(settings)
|
|
149
233
|
}
|
|
150
234
|
await deps.resolveWhen(() => window.ttq != null, 100)
|
|
151
235
|
return window.ttq
|
package/src/init-script.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
export function initScript(
|
|
3
|
+
export function initScript(settings) {
|
|
4
4
|
!(function (w, d, t) {
|
|
5
5
|
w.TiktokAnalyticsObject = t
|
|
6
6
|
var ttq = (w[t] = w[t] || [])
|
|
@@ -44,7 +44,9 @@ export function initScript(pixelCode) {
|
|
|
44
44
|
a.parentNode.insertBefore(o, a)
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
ttq.load(pixelCode
|
|
47
|
+
ttq.load(settings.pixelCode, {
|
|
48
|
+
limited_data_use: settings.ldu ? settings.ldu : false
|
|
49
|
+
})
|
|
48
50
|
ttq.page()
|
|
49
51
|
})(window, document, 'ttq')
|
|
50
52
|
}
|
|
@@ -109,8 +109,8 @@ describe('TikTokPixel.reportWebEvent', () => {
|
|
|
109
109
|
query: 'test-query',
|
|
110
110
|
value: 10,
|
|
111
111
|
currency: 'USD',
|
|
112
|
-
phone: '+12345678900',
|
|
113
|
-
email: 'aaa@aaa.com',
|
|
112
|
+
phone: ['+12345678900'],
|
|
113
|
+
email: ['aaa@aaa.com'],
|
|
114
114
|
description: 'test-description'
|
|
115
115
|
}
|
|
116
116
|
})
|
|
@@ -221,8 +221,8 @@ describe('TikTokPixel.reportWebEvent', () => {
|
|
|
221
221
|
query: 'test-query',
|
|
222
222
|
value: 10,
|
|
223
223
|
currency: 'USD',
|
|
224
|
-
phone: '+12345678900',
|
|
225
|
-
email: 'aaa@aaa.com',
|
|
224
|
+
phone: ['+12345678900'],
|
|
225
|
+
email: ['aaa@aaa.com'],
|
|
226
226
|
description: 'test-description'
|
|
227
227
|
}
|
|
228
228
|
})
|
|
@@ -329,8 +329,8 @@ describe('TikTokPixel.reportWebEvent', () => {
|
|
|
329
329
|
query: 'test-query',
|
|
330
330
|
value: 10,
|
|
331
331
|
currency: 'USD',
|
|
332
|
-
phone: '+12345678900',
|
|
333
|
-
email: 'aaa@aaa.com',
|
|
332
|
+
phone: ['+12345678900'],
|
|
333
|
+
email: ['aaa@aaa.com'],
|
|
334
334
|
description: 'test-description'
|
|
335
335
|
}
|
|
336
336
|
})
|
|
@@ -361,4 +361,126 @@ describe('TikTokPixel.reportWebEvent', () => {
|
|
|
361
361
|
{ event_id: 'ajs-71f386523ee5dfa90c7d0fda28b6b5c6' }
|
|
362
362
|
)
|
|
363
363
|
})
|
|
364
|
+
|
|
365
|
+
test('identifiers can be passed as strings only', async () => {
|
|
366
|
+
const subscriptions: Subscription[] = [
|
|
367
|
+
{
|
|
368
|
+
partnerAction: 'reportWebEvent',
|
|
369
|
+
name: 'Place an Order',
|
|
370
|
+
enabled: true,
|
|
371
|
+
subscribe: 'event = "Order Completed"',
|
|
372
|
+
mapping: {
|
|
373
|
+
event_id: {
|
|
374
|
+
'@path': '$.messageId'
|
|
375
|
+
},
|
|
376
|
+
anonymousId: {
|
|
377
|
+
'@path': '$.anonymousId'
|
|
378
|
+
},
|
|
379
|
+
external_id: {
|
|
380
|
+
'@path': '$.userId'
|
|
381
|
+
},
|
|
382
|
+
phone_number: {
|
|
383
|
+
'@path': '$.properties.phone'
|
|
384
|
+
},
|
|
385
|
+
email: {
|
|
386
|
+
'@path': '$.properties.email'
|
|
387
|
+
},
|
|
388
|
+
groupId: {
|
|
389
|
+
'@path': '$.groupId'
|
|
390
|
+
},
|
|
391
|
+
event: 'PlaceAnOrder',
|
|
392
|
+
contents: {
|
|
393
|
+
'@arrayPath': [
|
|
394
|
+
'$.properties.products',
|
|
395
|
+
{
|
|
396
|
+
price: {
|
|
397
|
+
'@path': '$.price'
|
|
398
|
+
},
|
|
399
|
+
quantity: {
|
|
400
|
+
'@path': '$.quantity'
|
|
401
|
+
},
|
|
402
|
+
content_type: {
|
|
403
|
+
'@path': '$.category'
|
|
404
|
+
},
|
|
405
|
+
content_id: {
|
|
406
|
+
'@path': '$.product_id'
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
},
|
|
411
|
+
currency: {
|
|
412
|
+
'@path': '$.properties.currency'
|
|
413
|
+
},
|
|
414
|
+
value: {
|
|
415
|
+
'@path': '$.properties.value'
|
|
416
|
+
},
|
|
417
|
+
query: {
|
|
418
|
+
'@path': '$.properties.query'
|
|
419
|
+
},
|
|
420
|
+
description: {
|
|
421
|
+
'@path': '$.properties.description'
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
]
|
|
426
|
+
|
|
427
|
+
const context = new Context({
|
|
428
|
+
messageId: 'ajs-71f386523ee5dfa90c7d0fda28b6b5c6',
|
|
429
|
+
type: 'track',
|
|
430
|
+
anonymousId: 'anonymousId',
|
|
431
|
+
userId: 'userId',
|
|
432
|
+
event: 'Order Completed',
|
|
433
|
+
properties: {
|
|
434
|
+
products: [
|
|
435
|
+
{
|
|
436
|
+
product_id: '123',
|
|
437
|
+
category: 'product',
|
|
438
|
+
quantity: 1,
|
|
439
|
+
price: 1
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
product_id: '456',
|
|
443
|
+
category: 'product',
|
|
444
|
+
quantity: 2,
|
|
445
|
+
price: 2
|
|
446
|
+
}
|
|
447
|
+
],
|
|
448
|
+
query: 'test-query',
|
|
449
|
+
value: 10,
|
|
450
|
+
currency: 'USD',
|
|
451
|
+
phone: '+12345678900',
|
|
452
|
+
email: 'aaa@aaa.com',
|
|
453
|
+
description: 'test-description'
|
|
454
|
+
}
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
const [webEvent] = await TikTokDestination({
|
|
458
|
+
...settings,
|
|
459
|
+
subscriptions
|
|
460
|
+
})
|
|
461
|
+
reportWebEvent = webEvent
|
|
462
|
+
|
|
463
|
+
await reportWebEvent.load(Context.system(), {} as Analytics)
|
|
464
|
+
await reportWebEvent.track?.(context)
|
|
465
|
+
|
|
466
|
+
expect(mockTtp.identify).toHaveBeenCalledWith({
|
|
467
|
+
email: 'aaa@aaa.com',
|
|
468
|
+
phone_number: '+12345678900',
|
|
469
|
+
external_id: 'userId'
|
|
470
|
+
})
|
|
471
|
+
expect(mockTtp.track).toHaveBeenCalledWith(
|
|
472
|
+
'PlaceAnOrder',
|
|
473
|
+
{
|
|
474
|
+
contents: [
|
|
475
|
+
{ content_id: '123', content_type: 'product', price: 1, quantity: 1 },
|
|
476
|
+
{ content_id: '456', content_type: 'product', price: 2, quantity: 2 }
|
|
477
|
+
],
|
|
478
|
+
currency: 'USD',
|
|
479
|
+
description: 'test-description',
|
|
480
|
+
query: 'test-query',
|
|
481
|
+
value: 10
|
|
482
|
+
},
|
|
483
|
+
{ event_id: 'ajs-71f386523ee5dfa90c7d0fda28b6b5c6' }
|
|
484
|
+
)
|
|
485
|
+
})
|
|
364
486
|
})
|
|
@@ -16,3 +16,12 @@ export function formatPhone(phone: string | undefined): string | undefined {
|
|
|
16
16
|
formattedPhone = formattedPhone.substring(0, 15)
|
|
17
17
|
return formattedPhone
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
export function handleArrayInput(mightBeArray: string[] | string | undefined): string {
|
|
21
|
+
if(typeof mightBeArray === 'string') return mightBeArray
|
|
22
|
+
if(typeof mightBeArray === 'undefined') return ''
|
|
23
|
+
if(Array.isArray(mightBeArray)){
|
|
24
|
+
return mightBeArray.length>0 ? mightBeArray[0]: ''
|
|
25
|
+
}
|
|
26
|
+
return ''
|
|
27
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export interface Payload {
|
|
4
4
|
/**
|
|
5
|
-
* Conversion event name. Please refer to the "Supported Web Events" section on in TikTok’s [Pixel documentation](https://
|
|
5
|
+
* 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
6
|
*/
|
|
7
7
|
event: string
|
|
8
8
|
/**
|
|
@@ -10,19 +10,27 @@ export interface Payload {
|
|
|
10
10
|
*/
|
|
11
11
|
event_id?: string
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
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
14
|
*/
|
|
15
|
-
phone_number?: string
|
|
15
|
+
phone_number?: string[]
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* A single email address. TikTok Pixel will be hash this value before sending to TikTok.
|
|
18
18
|
*/
|
|
19
|
-
email?: string
|
|
19
|
+
email?: string[]
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Order ID of the transaction.
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
order_id?: string
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Shop ID of the transaction.
|
|
26
|
+
*/
|
|
27
|
+
shop_id?: string
|
|
28
|
+
/**
|
|
29
|
+
* Uniquely identifies the user who triggered the conversion event. TikTok Pixel will hash this value before sending to TikTok.
|
|
30
|
+
*/
|
|
31
|
+
external_id?: string[]
|
|
32
|
+
/**
|
|
33
|
+
* Related item details for the event.
|
|
26
34
|
*/
|
|
27
35
|
contents?: {
|
|
28
36
|
/**
|
|
@@ -34,14 +42,26 @@ export interface Payload {
|
|
|
34
42
|
*/
|
|
35
43
|
quantity?: number
|
|
36
44
|
/**
|
|
37
|
-
*
|
|
45
|
+
* Category of the product item.
|
|
38
46
|
*/
|
|
39
|
-
|
|
47
|
+
content_category?: string
|
|
40
48
|
/**
|
|
41
49
|
* ID of the product item.
|
|
42
50
|
*/
|
|
43
51
|
content_id?: string
|
|
52
|
+
/**
|
|
53
|
+
* Name of the product item.
|
|
54
|
+
*/
|
|
55
|
+
content_name?: string
|
|
56
|
+
/**
|
|
57
|
+
* Brand name of the product item.
|
|
58
|
+
*/
|
|
59
|
+
brand?: string
|
|
44
60
|
}[]
|
|
61
|
+
/**
|
|
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`.
|
|
63
|
+
*/
|
|
64
|
+
content_type?: string
|
|
45
65
|
/**
|
|
46
66
|
* Currency for the value specified as ISO 4217 code.
|
|
47
67
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
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 } from './formatter'
|
|
4
|
+
import { formatPhone, handleArrayInput } from './formatter'
|
|
5
5
|
import { TikTokPixel } from '../types'
|
|
6
|
+
import { commonFields } from '../common_fields'
|
|
6
7
|
|
|
7
8
|
const action: BrowserActionDefinition<Settings, TikTokPixel, Payload> = {
|
|
8
9
|
title: 'Report Web Event',
|
|
@@ -11,133 +12,14 @@ const action: BrowserActionDefinition<Settings, TikTokPixel, Payload> = {
|
|
|
11
12
|
platform: 'web',
|
|
12
13
|
defaultSubscription: 'type = "track"',
|
|
13
14
|
fields: {
|
|
14
|
-
|
|
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 documentation](https://ads.tiktok.com/marketing_api/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
|
-
// PII Fields - These fields must be hashed using SHA 256 and encoded as websafe-base64.
|
|
30
|
-
phone_number: {
|
|
31
|
-
label: 'Phone Number',
|
|
32
|
-
description:
|
|
33
|
-
'Phone number of the user who triggered the conversion event, in E.164 standard format, e.g. +14150000000. Segment will hash this value before sending to TikTok.',
|
|
34
|
-
type: 'string',
|
|
35
|
-
default: {
|
|
36
|
-
'@if': {
|
|
37
|
-
exists: { '@path': '$.properties.phone' },
|
|
38
|
-
then: { '@path': '$.properties.phone' },
|
|
39
|
-
else: { '@path': '$.traits.phone' }
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
email: {
|
|
44
|
-
label: 'Email',
|
|
45
|
-
description:
|
|
46
|
-
'Email address of the user who triggered the conversion event. Segment will hash this value before sending to TikTok.',
|
|
47
|
-
type: 'string',
|
|
48
|
-
format: 'email',
|
|
49
|
-
default: {
|
|
50
|
-
'@if': {
|
|
51
|
-
exists: { '@path': '$.properties.email' },
|
|
52
|
-
then: { '@path': '$.properties.email' },
|
|
53
|
-
else: { '@path': '$.traits.email' }
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
external_id: {
|
|
58
|
-
label: 'External ID',
|
|
59
|
-
description:
|
|
60
|
-
'Uniquely identifies the user who triggered the conversion event. Segment will hash this value before sending to TikTok.',
|
|
61
|
-
type: 'string',
|
|
62
|
-
default: {
|
|
63
|
-
'@if': {
|
|
64
|
-
exists: { '@path': '$.userId' },
|
|
65
|
-
then: { '@path': '$.userId' },
|
|
66
|
-
else: { '@path': '$.anonymousId' }
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
contents: {
|
|
71
|
-
label: 'Contents',
|
|
72
|
-
type: 'object',
|
|
73
|
-
multiple: true,
|
|
74
|
-
description: 'Related items in a web event.',
|
|
75
|
-
properties: {
|
|
76
|
-
price: {
|
|
77
|
-
label: 'Price',
|
|
78
|
-
description: 'Price of the item.',
|
|
79
|
-
type: 'number'
|
|
80
|
-
},
|
|
81
|
-
quantity: {
|
|
82
|
-
label: 'Quantity',
|
|
83
|
-
description: 'Number of items.',
|
|
84
|
-
type: 'number'
|
|
85
|
-
},
|
|
86
|
-
content_type: {
|
|
87
|
-
label: 'Content Type',
|
|
88
|
-
description: 'Type of the product item.',
|
|
89
|
-
type: 'string'
|
|
90
|
-
},
|
|
91
|
-
content_id: {
|
|
92
|
-
label: 'Content ID',
|
|
93
|
-
description: 'ID of the product item.',
|
|
94
|
-
type: 'string'
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
currency: {
|
|
99
|
-
label: 'Currency',
|
|
100
|
-
type: 'string',
|
|
101
|
-
description: 'Currency for the value specified as ISO 4217 code.',
|
|
102
|
-
default: {
|
|
103
|
-
'@path': '$.properties.currency'
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
value: {
|
|
107
|
-
label: 'Value',
|
|
108
|
-
type: 'number',
|
|
109
|
-
description: 'Value of the order or items sold.',
|
|
110
|
-
default: {
|
|
111
|
-
'@if': {
|
|
112
|
-
exists: { '@path': '$.properties.value' },
|
|
113
|
-
then: { '@path': '$.properties.value' },
|
|
114
|
-
else: { '@path': '$.properties.revenue' }
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
description: {
|
|
119
|
-
label: 'Description',
|
|
120
|
-
type: 'string',
|
|
121
|
-
description: 'A string description of the web event.',
|
|
122
|
-
default: {
|
|
123
|
-
'@path': '$.properties.description'
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
query: {
|
|
127
|
-
label: 'Query',
|
|
128
|
-
type: 'string',
|
|
129
|
-
description: 'The text string that was searched for.',
|
|
130
|
-
default: {
|
|
131
|
-
'@path': '$.properties.query'
|
|
132
|
-
}
|
|
133
|
-
}
|
|
15
|
+
...commonFields
|
|
134
16
|
},
|
|
135
17
|
perform: (ttq, { payload }) => {
|
|
136
|
-
if (payload.email || payload.phone_number) {
|
|
18
|
+
if (payload.email || payload.phone_number || payload.external_id) {
|
|
137
19
|
ttq.identify({
|
|
138
|
-
email: payload.email,
|
|
139
|
-
phone_number: formatPhone(payload.phone_number),
|
|
140
|
-
external_id: payload.external_id
|
|
20
|
+
email: handleArrayInput(payload.email),
|
|
21
|
+
phone_number: formatPhone(handleArrayInput(payload.phone_number)),
|
|
22
|
+
external_id: handleArrayInput(payload.external_id)
|
|
141
23
|
})
|
|
142
24
|
}
|
|
143
25
|
|
|
@@ -145,13 +27,16 @@ const action: BrowserActionDefinition<Settings, TikTokPixel, Payload> = {
|
|
|
145
27
|
payload.event,
|
|
146
28
|
{
|
|
147
29
|
contents: payload.contents ? payload.contents : [],
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
query: payload.query
|
|
30
|
+
content_type: payload.content_type ? payload.content_type : undefined,
|
|
31
|
+
currency: payload.currency ? payload.currency : 'USD',
|
|
32
|
+
value: payload.value ? payload.value : 0,
|
|
33
|
+
query: payload.query ? payload.query : undefined,
|
|
34
|
+
description: payload.description ? payload.description : undefined,
|
|
35
|
+
order_id: payload.order_id ? payload.order_id : undefined,
|
|
36
|
+
shop_id: payload.shop_id ? payload.shop_id : undefined
|
|
152
37
|
},
|
|
153
38
|
{
|
|
154
|
-
event_id: payload.event_id
|
|
39
|
+
event_id: payload.event_id ? payload.event_id : ''
|
|
155
40
|
}
|
|
156
41
|
)
|
|
157
42
|
}
|
package/src/types.ts
CHANGED
|
@@ -13,23 +13,31 @@ export interface TikTokPixel {
|
|
|
13
13
|
event: string,
|
|
14
14
|
{
|
|
15
15
|
contents,
|
|
16
|
+
content_type,
|
|
16
17
|
currency,
|
|
17
18
|
value,
|
|
18
19
|
description,
|
|
19
|
-
query
|
|
20
|
+
query,
|
|
21
|
+
order_id,
|
|
22
|
+
shop_id
|
|
20
23
|
}: {
|
|
21
24
|
contents:
|
|
22
25
|
| {
|
|
23
|
-
price?: number
|
|
24
|
-
quantity?: number
|
|
25
|
-
|
|
26
|
-
content_id?: string
|
|
26
|
+
price?: number | undefined
|
|
27
|
+
quantity?: number | undefined
|
|
28
|
+
content_category?: string | undefined
|
|
29
|
+
content_id?: string | undefined
|
|
30
|
+
content_name?: string | undefined
|
|
31
|
+
brand?: string | undefined
|
|
27
32
|
}[]
|
|
28
33
|
| []
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
content_type: string | undefined
|
|
35
|
+
currency: string | undefined
|
|
36
|
+
value: number | undefined
|
|
31
37
|
description: string | undefined
|
|
32
38
|
query: string | undefined
|
|
39
|
+
order_id: string | undefined
|
|
40
|
+
shop_id: string | undefined
|
|
33
41
|
},
|
|
34
42
|
{
|
|
35
43
|
event_id
|