@blotoutio/providers-tiktok-sdk 0.26.5 → 0.27.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/index.cjs.js ADDED
@@ -0,0 +1,194 @@
1
+ 'use strict';
2
+
3
+ /* eslint-enable */
4
+ const snippet = () => {
5
+ if (!window || !document || window.ttq) {
6
+ return;
7
+ }
8
+ window.TiktokAnalyticsObject = 'ttq';
9
+ const ttq = (window['ttq'] =
10
+ window['ttq'] || []);
11
+ ttq.methods = [
12
+ 'page',
13
+ 'track',
14
+ 'identify',
15
+ 'instances',
16
+ 'debug',
17
+ 'on',
18
+ 'off',
19
+ 'once',
20
+ 'ready',
21
+ 'alias',
22
+ 'group',
23
+ 'enableCookie',
24
+ 'disableCookie',
25
+ ];
26
+ ttq.setAndDefer = function (t, e) {
27
+ t[e] = function () {
28
+ // eslint-disable-next-line
29
+ t.push([e].concat(Array.prototype.slice.call(arguments, 0)));
30
+ };
31
+ };
32
+ for (let i = 0; i < ttq.methods.length; i++) {
33
+ ttq.setAndDefer(ttq, ttq.methods[i]);
34
+ }
35
+ ttq.instance = function (t) {
36
+ const e = ttq._i[t] || [];
37
+ for (let n = 0; n < ttq.methods.length; n++) {
38
+ ttq.setAndDefer(e, ttq.methods[n]);
39
+ }
40
+ return e;
41
+ };
42
+ ttq.load = function (e, n) {
43
+ const i = 'https://analytics.tiktok.com/i18n/pixel/events.js';
44
+ ttq._i = ttq._i || {};
45
+ ttq._i[e] = [];
46
+ ttq._i[e]['_u'] = i;
47
+ ttq._t = ttq._t || {};
48
+ ttq._t[e] = +new Date();
49
+ ttq._o = ttq._o || {};
50
+ ttq._o[e] = n || {};
51
+ const element = document.createElement('script');
52
+ element.type = 'text/javascript';
53
+ element.async = !0;
54
+ element.src = i + '?sdkid=' + e + '&lib=ttq';
55
+ const script = document.getElementsByTagName('script')[0];
56
+ if (script && script.parentNode) {
57
+ script.parentNode.insertBefore(element, script);
58
+ }
59
+ };
60
+ };
61
+ const init = ({ manifest, userId }) => {
62
+ var _a, _b;
63
+ if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
64
+ return;
65
+ }
66
+ snippet();
67
+ if (!window.ttq) {
68
+ return;
69
+ }
70
+ window.ttq.load(manifest.variables['pixelId']);
71
+ window.ttq._partner = 'Blotout';
72
+ (_b = (_a = window.ttq.instance(manifest.variables['pixelId'])) === null || _a === void 0 ? void 0 : _a.identify) === null || _b === void 0 ? void 0 : _b.call(_a, {
73
+ external_id: userId,
74
+ });
75
+ };
76
+
77
+ const getEventName = (event, manifestVariables) => {
78
+ if (event === 'PageView') {
79
+ return 'Pageview';
80
+ }
81
+ if (event === 'Purchase') {
82
+ return ((manifestVariables && manifestVariables['purchaseEvent']) ||
83
+ 'PlaceAnOrder');
84
+ }
85
+ return event;
86
+ };
87
+ const prepareData = (data) => {
88
+ const payload = {};
89
+ if (data['search']) {
90
+ payload['query'] = data['search'];
91
+ }
92
+ if (data['value']) {
93
+ payload['value'] = data['value'];
94
+ }
95
+ if (data['currency']) {
96
+ payload['currency'] = data['currency'];
97
+ }
98
+ if (data['status']) {
99
+ payload['status'] = data['status'];
100
+ }
101
+ if (data['description']) {
102
+ payload['description'] = data['description'];
103
+ }
104
+ if (data['type']) {
105
+ payload['content_type'] = data['type'];
106
+ }
107
+ if (data['contents'] &&
108
+ Array.isArray(data['contents']) &&
109
+ data['contents'].length > 0) {
110
+ payload['content_type'] = payload['content_type'] || 'product';
111
+ if (data['contents'].length > 1) {
112
+ payload['content_type'] = data['contents'][0].type;
113
+ payload['contents'] = data['contents'].map((item) => {
114
+ const content = {};
115
+ if (item.id) {
116
+ content['content_id'] = item.id;
117
+ }
118
+ if (item.quantity) {
119
+ content['quantity'] = item.quantity;
120
+ }
121
+ if (item.item_price) {
122
+ content['price'] = item.item_price;
123
+ }
124
+ if (item.category) {
125
+ content['content_category'] = item.category;
126
+ }
127
+ if (item.title) {
128
+ content['content_name'] = item.title;
129
+ }
130
+ if (item.type) {
131
+ content['content_type'] = item.type;
132
+ }
133
+ return content;
134
+ });
135
+ }
136
+ else if (data['contents'].length === 1) {
137
+ if (data['contents'][0].item_price) {
138
+ payload['price'] = data['contents'][0].item_price;
139
+ }
140
+ if (data['contents'][0].quantity) {
141
+ payload['quantity'] = data['contents'][0].quantity;
142
+ }
143
+ if (data['contents'][0].id) {
144
+ payload['content_id'] = data['contents'][0].id;
145
+ }
146
+ if (data['contents'][0].title) {
147
+ payload['content_name'] = data['contents'][0].title;
148
+ }
149
+ if (data['contents'][0].type) {
150
+ payload['content_type'] = data['contents'][0].type;
151
+ }
152
+ if (data['contents'][0].category) {
153
+ payload['content_category'] = data['contents'][0].category;
154
+ }
155
+ }
156
+ }
157
+ return payload;
158
+ };
159
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
160
+ if (window.ttq && manifestVariables['enableBrowser'] === '1') {
161
+ const name = data['skipTransformation']
162
+ ? eventName
163
+ : getEventName(eventName, manifestVariables);
164
+ const eventData = data['skipTransformation'] ? data : prepareData(data);
165
+ delete eventData['skipTransformation'];
166
+ window.ttq.instance(manifestVariables['pixelId']).track(name, {
167
+ ...eventData,
168
+ event_id: eventId,
169
+ });
170
+ }
171
+ return {
172
+ sdkVersion: "0.27.0" ,
173
+ };
174
+ };
175
+
176
+ /* eslint-enable */
177
+ const data = {
178
+ name: 'tiktok',
179
+ tag,
180
+ init,
181
+ };
182
+ try {
183
+ if (window) {
184
+ if (!window.edgetagProviders) {
185
+ window.edgetagProviders = [];
186
+ }
187
+ window.edgetagProviders.push(data);
188
+ }
189
+ }
190
+ catch {
191
+ // No window
192
+ }
193
+
194
+ module.exports = data;
package/index.js CHANGED
@@ -170,7 +170,7 @@ var ProvidersTiktokSdk = (function () {
170
170
  });
171
171
  }
172
172
  return {
173
- sdkVersion: "0.26.5" ,
173
+ sdkVersion: "0.27.0" ,
174
174
  };
175
175
  };
176
176
 
package/index.mjs ADDED
@@ -0,0 +1,192 @@
1
+ /* eslint-enable */
2
+ const snippet = () => {
3
+ if (!window || !document || window.ttq) {
4
+ return;
5
+ }
6
+ window.TiktokAnalyticsObject = 'ttq';
7
+ const ttq = (window['ttq'] =
8
+ window['ttq'] || []);
9
+ ttq.methods = [
10
+ 'page',
11
+ 'track',
12
+ 'identify',
13
+ 'instances',
14
+ 'debug',
15
+ 'on',
16
+ 'off',
17
+ 'once',
18
+ 'ready',
19
+ 'alias',
20
+ 'group',
21
+ 'enableCookie',
22
+ 'disableCookie',
23
+ ];
24
+ ttq.setAndDefer = function (t, e) {
25
+ t[e] = function () {
26
+ // eslint-disable-next-line
27
+ t.push([e].concat(Array.prototype.slice.call(arguments, 0)));
28
+ };
29
+ };
30
+ for (let i = 0; i < ttq.methods.length; i++) {
31
+ ttq.setAndDefer(ttq, ttq.methods[i]);
32
+ }
33
+ ttq.instance = function (t) {
34
+ const e = ttq._i[t] || [];
35
+ for (let n = 0; n < ttq.methods.length; n++) {
36
+ ttq.setAndDefer(e, ttq.methods[n]);
37
+ }
38
+ return e;
39
+ };
40
+ ttq.load = function (e, n) {
41
+ const i = 'https://analytics.tiktok.com/i18n/pixel/events.js';
42
+ ttq._i = ttq._i || {};
43
+ ttq._i[e] = [];
44
+ ttq._i[e]['_u'] = i;
45
+ ttq._t = ttq._t || {};
46
+ ttq._t[e] = +new Date();
47
+ ttq._o = ttq._o || {};
48
+ ttq._o[e] = n || {};
49
+ const element = document.createElement('script');
50
+ element.type = 'text/javascript';
51
+ element.async = !0;
52
+ element.src = i + '?sdkid=' + e + '&lib=ttq';
53
+ const script = document.getElementsByTagName('script')[0];
54
+ if (script && script.parentNode) {
55
+ script.parentNode.insertBefore(element, script);
56
+ }
57
+ };
58
+ };
59
+ const init = ({ manifest, userId }) => {
60
+ var _a, _b;
61
+ if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
62
+ return;
63
+ }
64
+ snippet();
65
+ if (!window.ttq) {
66
+ return;
67
+ }
68
+ window.ttq.load(manifest.variables['pixelId']);
69
+ window.ttq._partner = 'Blotout';
70
+ (_b = (_a = window.ttq.instance(manifest.variables['pixelId'])) === null || _a === void 0 ? void 0 : _a.identify) === null || _b === void 0 ? void 0 : _b.call(_a, {
71
+ external_id: userId,
72
+ });
73
+ };
74
+
75
+ const getEventName = (event, manifestVariables) => {
76
+ if (event === 'PageView') {
77
+ return 'Pageview';
78
+ }
79
+ if (event === 'Purchase') {
80
+ return ((manifestVariables && manifestVariables['purchaseEvent']) ||
81
+ 'PlaceAnOrder');
82
+ }
83
+ return event;
84
+ };
85
+ const prepareData = (data) => {
86
+ const payload = {};
87
+ if (data['search']) {
88
+ payload['query'] = data['search'];
89
+ }
90
+ if (data['value']) {
91
+ payload['value'] = data['value'];
92
+ }
93
+ if (data['currency']) {
94
+ payload['currency'] = data['currency'];
95
+ }
96
+ if (data['status']) {
97
+ payload['status'] = data['status'];
98
+ }
99
+ if (data['description']) {
100
+ payload['description'] = data['description'];
101
+ }
102
+ if (data['type']) {
103
+ payload['content_type'] = data['type'];
104
+ }
105
+ if (data['contents'] &&
106
+ Array.isArray(data['contents']) &&
107
+ data['contents'].length > 0) {
108
+ payload['content_type'] = payload['content_type'] || 'product';
109
+ if (data['contents'].length > 1) {
110
+ payload['content_type'] = data['contents'][0].type;
111
+ payload['contents'] = data['contents'].map((item) => {
112
+ const content = {};
113
+ if (item.id) {
114
+ content['content_id'] = item.id;
115
+ }
116
+ if (item.quantity) {
117
+ content['quantity'] = item.quantity;
118
+ }
119
+ if (item.item_price) {
120
+ content['price'] = item.item_price;
121
+ }
122
+ if (item.category) {
123
+ content['content_category'] = item.category;
124
+ }
125
+ if (item.title) {
126
+ content['content_name'] = item.title;
127
+ }
128
+ if (item.type) {
129
+ content['content_type'] = item.type;
130
+ }
131
+ return content;
132
+ });
133
+ }
134
+ else if (data['contents'].length === 1) {
135
+ if (data['contents'][0].item_price) {
136
+ payload['price'] = data['contents'][0].item_price;
137
+ }
138
+ if (data['contents'][0].quantity) {
139
+ payload['quantity'] = data['contents'][0].quantity;
140
+ }
141
+ if (data['contents'][0].id) {
142
+ payload['content_id'] = data['contents'][0].id;
143
+ }
144
+ if (data['contents'][0].title) {
145
+ payload['content_name'] = data['contents'][0].title;
146
+ }
147
+ if (data['contents'][0].type) {
148
+ payload['content_type'] = data['contents'][0].type;
149
+ }
150
+ if (data['contents'][0].category) {
151
+ payload['content_category'] = data['contents'][0].category;
152
+ }
153
+ }
154
+ }
155
+ return payload;
156
+ };
157
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
158
+ if (window.ttq && manifestVariables['enableBrowser'] === '1') {
159
+ const name = data['skipTransformation']
160
+ ? eventName
161
+ : getEventName(eventName, manifestVariables);
162
+ const eventData = data['skipTransformation'] ? data : prepareData(data);
163
+ delete eventData['skipTransformation'];
164
+ window.ttq.instance(manifestVariables['pixelId']).track(name, {
165
+ ...eventData,
166
+ event_id: eventId,
167
+ });
168
+ }
169
+ return {
170
+ sdkVersion: "0.27.0" ,
171
+ };
172
+ };
173
+
174
+ /* eslint-enable */
175
+ const data = {
176
+ name: 'tiktok',
177
+ tag,
178
+ init,
179
+ };
180
+ try {
181
+ if (window) {
182
+ if (!window.edgetagProviders) {
183
+ window.edgetagProviders = [];
184
+ }
185
+ window.edgetagProviders.push(data);
186
+ }
187
+ }
188
+ catch {
189
+ // No window
190
+ }
191
+
192
+ export { data as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-tiktok-sdk",
3
- "version": "0.26.5",
3
+ "version": "0.27.0",
4
4
  "description": "Tiktok Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",
@@ -8,13 +8,16 @@
8
8
  "publishConfig": {
9
9
  "access": "public"
10
10
  },
11
- "main": "./index.js",
11
+ "main": "./index.cjs.js",
12
+ "module": "./index.mjs",
12
13
  "repository": {
13
14
  "type": "git",
14
15
  "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
15
16
  },
16
17
  "files": [
17
18
  "index.js",
19
+ "index.cjs.js",
20
+ "index.mjs",
18
21
  "package.json",
19
22
  "README.md"
20
23
  ]