@segment/analytics-browser-actions-tiktok-pixel 1.0.1-CONMAN-533.1454

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 (53) hide show
  1. package/dist/cjs/generated-types.d.ts +4 -0
  2. package/dist/cjs/generated-types.js +3 -0
  3. package/dist/cjs/generated-types.js.map +1 -0
  4. package/dist/cjs/index.d.ts +11 -0
  5. package/dist/cjs/index.js +139 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/init-script.d.ts +1 -0
  8. package/dist/cjs/init-script.js +54 -0
  9. package/dist/cjs/init-script.js.map +1 -0
  10. package/dist/cjs/reportWebEvent/formatter.d.ts +1 -0
  11. package/dist/cjs/reportWebEvent/formatter.js +16 -0
  12. package/dist/cjs/reportWebEvent/formatter.js.map +1 -0
  13. package/dist/cjs/reportWebEvent/generated-types.d.ts +16 -0
  14. package/dist/cjs/reportWebEvent/generated-types.js +3 -0
  15. package/dist/cjs/reportWebEvent/generated-types.js.map +1 -0
  16. package/dist/cjs/reportWebEvent/index.d.ts +6 -0
  17. package/dist/cjs/reportWebEvent/index.js +135 -0
  18. package/dist/cjs/reportWebEvent/index.js.map +1 -0
  19. package/dist/cjs/types.d.ts +19 -0
  20. package/dist/cjs/types.js +3 -0
  21. package/dist/cjs/types.js.map +1 -0
  22. package/dist/esm/generated-types.d.ts +4 -0
  23. package/dist/esm/generated-types.js +2 -0
  24. package/dist/esm/generated-types.js.map +1 -0
  25. package/dist/esm/index.d.ts +11 -0
  26. package/dist/esm/index.js +135 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/init-script.d.ts +1 -0
  29. package/dist/esm/init-script.js +50 -0
  30. package/dist/esm/init-script.js.map +1 -0
  31. package/dist/esm/reportWebEvent/formatter.d.ts +1 -0
  32. package/dist/esm/reportWebEvent/formatter.js +12 -0
  33. package/dist/esm/reportWebEvent/formatter.js.map +1 -0
  34. package/dist/esm/reportWebEvent/generated-types.d.ts +16 -0
  35. package/dist/esm/reportWebEvent/generated-types.js +2 -0
  36. package/dist/esm/reportWebEvent/generated-types.js.map +1 -0
  37. package/dist/esm/reportWebEvent/index.d.ts +6 -0
  38. package/dist/esm/reportWebEvent/index.js +133 -0
  39. package/dist/esm/reportWebEvent/index.js.map +1 -0
  40. package/dist/esm/types.d.ts +19 -0
  41. package/dist/esm/types.js +2 -0
  42. package/dist/esm/types.js.map +1 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -0
  44. package/package.json +21 -0
  45. package/src/generated-types.ts +12 -0
  46. package/src/index.ts +150 -0
  47. package/src/init-script.ts +50 -0
  48. package/src/reportWebEvent/__tests__/index.test.ts +346 -0
  49. package/src/reportWebEvent/formatter.ts +18 -0
  50. package/src/reportWebEvent/generated-types.ts +57 -0
  51. package/src/reportWebEvent/index.ts +145 -0
  52. package/src/types.ts +27 -0
  53. package/tsconfig.json +9 -0
@@ -0,0 +1,4 @@
1
+ export interface Settings {
2
+ pixelCode: string;
3
+ useExistingPixel?: boolean;
4
+ }
@@ -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/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { Settings } from './generated-types';
2
+ import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types';
3
+ import { TikTokPixel } from './types';
4
+ declare global {
5
+ interface Window {
6
+ ttq: TikTokPixel;
7
+ }
8
+ }
9
+ export declare const destination: BrowserDestinationDefinition<Settings, TikTokPixel>;
10
+ declare const _default: import("@segment/browser-destination-runtime/types").PluginFactory;
11
+ export default _default;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.destination = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const shim_1 = require("@segment/browser-destination-runtime/shim");
6
+ const reportWebEvent_1 = tslib_1.__importDefault(require("./reportWebEvent"));
7
+ const actions_core_1 = require("@segment/actions-core");
8
+ const init_script_1 = require("./init-script");
9
+ const productProperties = {
10
+ price: {
11
+ '@path': '$.price'
12
+ },
13
+ quantity: {
14
+ '@path': '$.quantity'
15
+ },
16
+ content_type: {
17
+ '@path': '$.category'
18
+ },
19
+ content_id: {
20
+ '@path': '$.product_id'
21
+ }
22
+ };
23
+ const singleProductContents = {
24
+ ...actions_core_1.defaultValues(reportWebEvent_1.default.fields),
25
+ contents: {
26
+ '@arrayPath': [
27
+ '$.properties',
28
+ {
29
+ ...productProperties
30
+ }
31
+ ]
32
+ }
33
+ };
34
+ const multiProductContents = {
35
+ ...actions_core_1.defaultValues(reportWebEvent_1.default.fields),
36
+ contents: {
37
+ '@arrayPath': [
38
+ '$.properties.products',
39
+ {
40
+ ...productProperties
41
+ }
42
+ ]
43
+ }
44
+ };
45
+ exports.destination = {
46
+ name: 'TikTok Pixel',
47
+ slug: 'actions-tiktok-pixel',
48
+ mode: 'device',
49
+ presets: [
50
+ {
51
+ name: 'View Content',
52
+ subscribe: 'type="page"',
53
+ partnerAction: 'reportWebEvent',
54
+ mapping: {
55
+ ...singleProductContents,
56
+ event: 'ViewContent'
57
+ }
58
+ },
59
+ {
60
+ name: 'Search',
61
+ subscribe: 'event = "Products Searched"',
62
+ partnerAction: 'reportWebEvent',
63
+ mapping: {
64
+ ...singleProductContents,
65
+ event: 'Search'
66
+ }
67
+ },
68
+ {
69
+ name: 'Add to Wishlist',
70
+ subscribe: 'event = "Product Added to Wishlist"',
71
+ partnerAction: 'reportWebEvent',
72
+ mapping: {
73
+ ...singleProductContents,
74
+ event: 'AddToWishlist'
75
+ }
76
+ },
77
+ {
78
+ name: 'Add to Cart',
79
+ subscribe: 'event = "Product Added"',
80
+ partnerAction: 'reportWebEvent',
81
+ mapping: {
82
+ ...singleProductContents,
83
+ event: 'AddToCart'
84
+ }
85
+ },
86
+ {
87
+ name: 'Initiate Checkout',
88
+ subscribe: 'event = "Checkout Started"',
89
+ partnerAction: 'reportWebEvent',
90
+ mapping: {
91
+ ...multiProductContents,
92
+ event: 'InitiateCheckout'
93
+ }
94
+ },
95
+ {
96
+ name: 'Add Payment Info',
97
+ subscribe: 'event = "Payment Info Entered"',
98
+ partnerAction: 'reportWebEvent',
99
+ mapping: {
100
+ ...multiProductContents,
101
+ event: 'AddPaymentInfo'
102
+ }
103
+ },
104
+ {
105
+ name: 'Place an Order',
106
+ subscribe: 'event = "Order Completed"',
107
+ partnerAction: 'reportWebEvent',
108
+ mapping: {
109
+ ...multiProductContents,
110
+ event: 'PlaceAnOrder'
111
+ }
112
+ }
113
+ ],
114
+ settings: {
115
+ pixelCode: {
116
+ label: 'Pixel Code',
117
+ type: 'string',
118
+ description: "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.",
119
+ required: true
120
+ },
121
+ useExistingPixel: {
122
+ label: 'Use Existing Pixel',
123
+ type: 'boolean',
124
+ description: 'Select "true" to use existing Pixel that is already installed on your website.'
125
+ }
126
+ },
127
+ initialize: async ({ settings }, deps) => {
128
+ if (!settings.useExistingPixel) {
129
+ init_script_1.initScript(settings.pixelCode);
130
+ }
131
+ await deps.resolveWhen(() => window.ttq != null, 100);
132
+ return window.ttq;
133
+ },
134
+ actions: {
135
+ reportWebEvent: reportWebEvent_1.default
136
+ }
137
+ };
138
+ exports.default = shim_1.browserDestination(exports.destination);
139
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAEA,oEAA8E;AAC9E,8EAA6C;AAC7C,wDAAqD;AAErD,+CAA0C;AAQ1C,MAAM,iBAAiB,GAAG;IACxB,KAAK,EAAE;QACL,OAAO,EAAE,SAAS;KACnB;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,YA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
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initScript = void 0;
4
+ function initScript(pixelCode) {
5
+ !(function (w, d, t) {
6
+ w.TiktokAnalyticsObject = t;
7
+ var ttq = (w[t] = w[t] || []);
8
+ (ttq.methods = [
9
+ 'page',
10
+ 'track',
11
+ 'identify',
12
+ 'instances',
13
+ 'debug',
14
+ 'on',
15
+ 'off',
16
+ 'once',
17
+ 'ready',
18
+ 'alias',
19
+ 'group',
20
+ 'enableCookie',
21
+ 'disableCookie'
22
+ ]),
23
+ (ttq.setAndDefer = function (t, e) {
24
+ t[e] = function () {
25
+ t.push([e].concat(Array.prototype.slice.call(arguments, 0)));
26
+ };
27
+ });
28
+ for (var i = 0; i < ttq.methods.length; i++)
29
+ ttq.setAndDefer(ttq, ttq.methods[i]);
30
+ (ttq.instance = function (t) {
31
+ for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++)
32
+ ttq.setAndDefer(e, ttq.methods[n]);
33
+ return e;
34
+ }),
35
+ (ttq.load = function (e, n) {
36
+ var i = 'https://analytics.tiktok.com/i18n/pixel/events.js';
37
+ (ttq._i = ttq._i || {}),
38
+ (ttq._i[e] = []),
39
+ (ttq._i[e]._u = i),
40
+ (ttq._t = ttq._t || {}),
41
+ (ttq._t[e] = +new Date()),
42
+ (ttq._o = ttq._o || {}),
43
+ (ttq._o[e] = n || {});
44
+ var o = document.createElement('script');
45
+ (o.type = 'text/javascript'), (o.async = !0), (o.src = i + '?sdkid=' + e + '&lib=' + t);
46
+ var a = document.getElementsByTagName('script')[0];
47
+ a.parentNode.insertBefore(o, a);
48
+ });
49
+ ttq.load(pixelCode);
50
+ ttq.page();
51
+ })(window, document, 'ttq');
52
+ }
53
+ exports.initScript = initScript;
54
+ //# sourceMappingURL=init-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-script.js","sourceRoot":"","sources":["../../src/init-script.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAC,SAAS;IAClC,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,EAAE,KAAK,CAAC,CAAA;AAC7B,CAAC;AA/CD,gCA+CC"}
@@ -0,0 +1 @@
1
+ export declare function formatPhone(phone: string | undefined): string | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPhone = void 0;
4
+ function formatPhone(phone) {
5
+ if (!phone)
6
+ return undefined;
7
+ const validatedPhone = phone.match(/[0-9]{0,14}/g);
8
+ if (validatedPhone === null) {
9
+ throw new Error(`${phone} is not a valid E.164 phone number.`);
10
+ }
11
+ let formattedPhone = `+${phone.replace(/[^0-9]/g, '')}`;
12
+ formattedPhone = formattedPhone.substring(0, 15);
13
+ return formattedPhone;
14
+ }
15
+ exports.formatPhone = formatPhone;
16
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/reportWebEvent/formatter.ts"],"names":[],"mappings":";;;AAKA,SAAgB,WAAW,CAAC,KAAyB;IACnD,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAE5B,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IAClD,IAAI,cAAc,KAAK,IAAI,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,qCAAqC,CAAC,CAAA;KAC/D;IAED,IAAI,cAAc,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,CAAA;IAEvD,cAAc,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAChD,OAAO,cAAc,CAAA;AACvB,CAAC;AAZD,kCAYC"}
@@ -0,0 +1,16 @@
1
+ export interface Payload {
2
+ event: string;
3
+ phone_number?: string;
4
+ email?: string;
5
+ external_id?: string;
6
+ contents?: {
7
+ price?: number;
8
+ quantity?: number;
9
+ content_type?: string;
10
+ content_id?: string;
11
+ }[];
12
+ currency?: string;
13
+ value?: number;
14
+ description?: string;
15
+ query?: string;
16
+ }
@@ -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/reportWebEvent/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ import { TikTokPixel } from '../types';
5
+ declare const action: BrowserActionDefinition<Settings, TikTokPixel, Payload>;
6
+ export default action;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const formatter_1 = require("./formatter");
4
+ const action = {
5
+ title: 'Report Web Event',
6
+ description: 'Report events directly to TikTok. Data shared can power TikTok solutions like dynamic product ads, custom targeting, campaign optimization and attribution.',
7
+ platform: 'web',
8
+ defaultSubscription: 'type = "track"',
9
+ fields: {
10
+ event: {
11
+ label: 'Event Name',
12
+ type: 'string',
13
+ required: true,
14
+ description: '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.'
15
+ },
16
+ phone_number: {
17
+ label: 'Phone Number',
18
+ description: '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.',
19
+ type: 'string',
20
+ default: {
21
+ '@if': {
22
+ exists: { '@path': '$.properties.phone' },
23
+ then: { '@path': '$.properties.phone' },
24
+ else: { '@path': '$.traits.phone' }
25
+ }
26
+ }
27
+ },
28
+ email: {
29
+ label: 'Email',
30
+ description: 'Email address of the user who triggered the conversion event. Segment will hash this value before sending to TikTok.',
31
+ type: 'string',
32
+ format: 'email',
33
+ default: {
34
+ '@if': {
35
+ exists: { '@path': '$.properties.email' },
36
+ then: { '@path': '$.properties.email' },
37
+ else: { '@path': '$.traits.email' }
38
+ }
39
+ }
40
+ },
41
+ external_id: {
42
+ label: 'External ID',
43
+ description: 'Uniquely identifies the user who triggered the conversion event. Segment will hash this value before sending to TikTok.',
44
+ type: 'string',
45
+ default: {
46
+ '@if': {
47
+ exists: { '@path': '$.userId' },
48
+ then: { '@path': '$.userId' },
49
+ else: { '@path': '$.anonymousId' }
50
+ }
51
+ }
52
+ },
53
+ contents: {
54
+ label: 'Contents',
55
+ type: 'object',
56
+ multiple: true,
57
+ description: 'Related items in a web event.',
58
+ properties: {
59
+ price: {
60
+ label: 'Price',
61
+ description: 'Price of the item.',
62
+ type: 'number'
63
+ },
64
+ quantity: {
65
+ label: 'Quantity',
66
+ description: 'Number of items.',
67
+ type: 'number'
68
+ },
69
+ content_type: {
70
+ label: 'Content Type',
71
+ description: 'Type of the product item.',
72
+ type: 'string'
73
+ },
74
+ content_id: {
75
+ label: 'Content ID',
76
+ description: 'ID of the product item.',
77
+ type: 'string'
78
+ }
79
+ }
80
+ },
81
+ currency: {
82
+ label: 'Currency',
83
+ type: 'string',
84
+ description: 'Currency for the value specified as ISO 4217 code.',
85
+ default: {
86
+ '@path': '$.properties.currency'
87
+ }
88
+ },
89
+ value: {
90
+ label: 'Value',
91
+ type: 'number',
92
+ description: 'Value of the order or items sold.',
93
+ default: {
94
+ '@if': {
95
+ exists: { '@path': '$.properties.value' },
96
+ then: { '@path': '$.properties.value' },
97
+ else: { '@path': '$.properties.revenue' }
98
+ }
99
+ }
100
+ },
101
+ description: {
102
+ label: 'Description',
103
+ type: 'string',
104
+ description: 'A string description of the web event.',
105
+ default: {
106
+ '@path': '$.properties.description'
107
+ }
108
+ },
109
+ query: {
110
+ label: 'Query',
111
+ type: 'string',
112
+ description: 'The text string that was searched for.',
113
+ default: {
114
+ '@path': '$.properties.query'
115
+ }
116
+ }
117
+ },
118
+ perform: (ttq, { payload }) => {
119
+ if (payload.email || payload.phone_number) {
120
+ ttq.identify({
121
+ email: payload.email,
122
+ phone_number: formatter_1.formatPhone(payload.phone_number)
123
+ });
124
+ }
125
+ ttq.track(payload.event, {
126
+ contents: payload.contents ? payload.contents : [],
127
+ currency: payload.currency ? payload.currency : 'USD',
128
+ value: payload.value ? payload.value : 0,
129
+ description: payload.description,
130
+ query: payload.query
131
+ });
132
+ }
133
+ };
134
+ exports.default = action;
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reportWebEvent/index.ts"],"names":[],"mappings":";;AAGA,2CAAyC;AAGzC,MAAM,MAAM,GAA4D;IACtE,KAAK,EAAE,kBAAkB;IACzB,WAAW,EACT,6JAA6J;IAC/J,QAAQ,EAAE,KAAK;IACf,mBAAmB,EAAE,gBAAgB;IACrC,MAAM,EAAE;QACN,KAAK,EAAE;YACL,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,yMAAyM;SAC5M;QAED,YAAY,EAAE;YACZ,KAAK,EAAE,cAAc;YACrB,WAAW,EACT,kKAAkK;YACpK,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;oBACzC,IAAI,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;oBACvC,IAAI,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE;iBACpC;aACF;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,WAAW,EACT,sHAAsH;YACxH,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;oBACzC,IAAI,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;oBACvC,IAAI,EAAE,EAAE,OAAO,EAAE,gB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undefined;
5
+ phone_number: string | undefined;
6
+ }) => void;
7
+ track: (event: string, { contents, currency, value, description, query }: {
8
+ contents: {
9
+ price?: number;
10
+ quantity?: number;
11
+ content_type?: string;
12
+ content_id?: string;
13
+ }[] | [];
14
+ currency: string;
15
+ value: number;
16
+ description: string | undefined;
17
+ query: string | undefined;
18
+ }) => void;
19
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface Settings {
2
+ pixelCode: string;
3
+ useExistingPixel?: boolean;
4
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../src/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { Settings } from './generated-types';
2
+ import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types';
3
+ import { TikTokPixel } from './types';
4
+ declare global {
5
+ interface Window {
6
+ ttq: TikTokPixel;
7
+ }
8
+ }
9
+ export declare const destination: BrowserDestinationDefinition<Settings, TikTokPixel>;
10
+ declare const _default: import("@segment/browser-destination-runtime/types").PluginFactory;
11
+ export default _default;
@@ -0,0 +1,135 @@
1
+ import { browserDestination } from '@segment/browser-destination-runtime/shim';
2
+ import reportWebEvent from './reportWebEvent';
3
+ import { defaultValues } from '@segment/actions-core';
4
+ import { initScript } from './init-script';
5
+ const productProperties = {
6
+ price: {
7
+ '@path': '$.price'
8
+ },
9
+ quantity: {
10
+ '@path': '$.quantity'
11
+ },
12
+ content_type: {
13
+ '@path': '$.category'
14
+ },
15
+ content_id: {
16
+ '@path': '$.product_id'
17
+ }
18
+ };
19
+ const singleProductContents = {
20
+ ...defaultValues(reportWebEvent.fields),
21
+ contents: {
22
+ '@arrayPath': [
23
+ '$.properties',
24
+ {
25
+ ...productProperties
26
+ }
27
+ ]
28
+ }
29
+ };
30
+ const multiProductContents = {
31
+ ...defaultValues(reportWebEvent.fields),
32
+ contents: {
33
+ '@arrayPath': [
34
+ '$.properties.products',
35
+ {
36
+ ...productProperties
37
+ }
38
+ ]
39
+ }
40
+ };
41
+ export const destination = {
42
+ name: 'TikTok Pixel',
43
+ slug: 'actions-tiktok-pixel',
44
+ mode: 'device',
45
+ presets: [
46
+ {
47
+ name: 'View Content',
48
+ subscribe: 'type="page"',
49
+ partnerAction: 'reportWebEvent',
50
+ mapping: {
51
+ ...singleProductContents,
52
+ event: 'ViewContent'
53
+ }
54
+ },
55
+ {
56
+ name: 'Search',
57
+ subscribe: 'event = "Products Searched"',
58
+ partnerAction: 'reportWebEvent',
59
+ mapping: {
60
+ ...singleProductContents,
61
+ event: 'Search'
62
+ }
63
+ },
64
+ {
65
+ name: 'Add to Wishlist',
66
+ subscribe: 'event = "Product Added to Wishlist"',
67
+ partnerAction: 'reportWebEvent',
68
+ mapping: {
69
+ ...singleProductContents,
70
+ event: 'AddToWishlist'
71
+ }
72
+ },
73
+ {
74
+ name: 'Add to Cart',
75
+ subscribe: 'event = "Product Added"',
76
+ partnerAction: 'reportWebEvent',
77
+ mapping: {
78
+ ...singleProductContents,
79
+ event: 'AddToCart'
80
+ }
81
+ },
82
+ {
83
+ name: 'Initiate Checkout',
84
+ subscribe: 'event = "Checkout Started"',
85
+ partnerAction: 'reportWebEvent',
86
+ mapping: {
87
+ ...multiProductContents,
88
+ event: 'InitiateCheckout'
89
+ }
90
+ },
91
+ {
92
+ name: 'Add Payment Info',
93
+ subscribe: 'event = "Payment Info Entered"',
94
+ partnerAction: 'reportWebEvent',
95
+ mapping: {
96
+ ...multiProductContents,
97
+ event: 'AddPaymentInfo'
98
+ }
99
+ },
100
+ {
101
+ name: 'Place an Order',
102
+ subscribe: 'event = "Order Completed"',
103
+ partnerAction: 'reportWebEvent',
104
+ mapping: {
105
+ ...multiProductContents,
106
+ event: 'PlaceAnOrder'
107
+ }
108
+ }
109
+ ],
110
+ settings: {
111
+ pixelCode: {
112
+ label: 'Pixel Code',
113
+ type: 'string',
114
+ description: "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.",
115
+ required: true
116
+ },
117
+ useExistingPixel: {
118
+ label: 'Use Existing Pixel',
119
+ type: 'boolean',
120
+ description: 'Select "true" to use existing Pixel that is already installed on your website.'
121
+ }
122
+ },
123
+ initialize: async ({ settings }, deps) => {
124
+ if (!settings.useExistingPixel) {
125
+ initScript(settings.pixelCode);
126
+ }
127
+ await deps.resolveWhen(() => window.ttq != null, 100);
128
+ return window.ttq;
129
+ },
130
+ actions: {
131
+ reportWebEvent
132
+ }
133
+ };
134
+ export default browserDestination(destination);
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAQ1C,MAAM,iBAAiB,GAAG;IACxB,KAAK,EAAE;QACL,OAAO,EAAE,SAAS;KACnB;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,YAAY;KACtB;IACD,YAAY,EAAE;QACZ,OAAO,EAAE,YAAY;KACtB;IACD,UAAU,EAAE;QACV,OAAO,EAAE,cAAc;KACxB;CACF,CAAA;AAED,MAAM,qBAAqB,GAAG;IAC5B,GAAG,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC;IACvC,QAAQ,EAAE;QACR,YAAY,EAAE;YACZ,cAAc;YACd;gBACE,GAAG,iBAAiB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