@blotoutio/providers-tiktok-sdk 0.15.0 → 0.16.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.js +2 -75
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
var ProvidersTiktokSdk = (function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const E164Pattern = /^\+[1-9]\d{10,14}$/;
|
|
5
|
-
const validatePhoneNumber = (value) => {
|
|
6
|
-
return E164Pattern.test(value.split(' ').join(''));
|
|
7
|
-
};
|
|
8
|
-
|
|
9
4
|
/* eslint-enable */
|
|
10
5
|
const snippet = () => {
|
|
11
6
|
if (!window || !document || window.ttq) {
|
|
@@ -64,61 +59,13 @@ var ProvidersTiktokSdk = (function () {
|
|
|
64
59
|
}
|
|
65
60
|
};
|
|
66
61
|
};
|
|
67
|
-
const
|
|
68
|
-
var _a, _b, _c, _d;
|
|
69
|
-
if (!window || !window.ttq) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const customerData = [];
|
|
73
|
-
const tiktokUserInfo = (_c = (_b = (_a = window.ttq.context) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.userInfo) !== null && _c !== void 0 ? _c : {};
|
|
74
|
-
const kvData = JSON.parse(sessionStorage.getItem(keyName !== null && keyName !== void 0 ? keyName : '') || '{}')['kv'] || {};
|
|
75
|
-
if (!('email' in tiktokUserInfo)) {
|
|
76
|
-
customerData.push('email');
|
|
77
|
-
}
|
|
78
|
-
if (!('phone_number' in tiktokUserInfo)) {
|
|
79
|
-
customerData.push('phone');
|
|
80
|
-
}
|
|
81
|
-
const identifyData = {};
|
|
82
|
-
const cacheMiss = customerData.filter((item) => !(item in kvData));
|
|
83
|
-
customerData.forEach((item) => {
|
|
84
|
-
if (item in kvData) {
|
|
85
|
-
identifyData[item] = kvData[item];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
if (getEdgeData && cacheMiss.length) {
|
|
89
|
-
getEdgeData(cacheMiss, (data) => {
|
|
90
|
-
var _a;
|
|
91
|
-
customerData.forEach((item) => {
|
|
92
|
-
if (item in data) {
|
|
93
|
-
identifyData[item] = data[item];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
if ('phone' in identifyData &&
|
|
97
|
-
validatePhoneNumber(identifyData['phone'])) {
|
|
98
|
-
identifyData['phone_number'] = identifyData['phone'];
|
|
99
|
-
delete identifyData['phone'];
|
|
100
|
-
}
|
|
101
|
-
Object.keys(identifyData).length &&
|
|
102
|
-
((_a = window.ttq) === null || _a === void 0 ? void 0 : _a.instance(variables['pixelId']).identify(identifyData));
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
else if (customerData.length && !cacheMiss.length) {
|
|
106
|
-
if ('phone' in identifyData && validatePhoneNumber(identifyData['phone'])) {
|
|
107
|
-
identifyData['phone_number'] = identifyData['phone'];
|
|
108
|
-
delete identifyData['phone'];
|
|
109
|
-
}
|
|
110
|
-
Object.keys(identifyData).length &&
|
|
111
|
-
((_d = window.ttq) === null || _d === void 0 ? void 0 : _d.instance(variables['pixelId']).identify(identifyData));
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const init = ({ manifest, userId, getEdgeData, keyName }) => {
|
|
62
|
+
const init = ({ manifest, userId }) => {
|
|
115
63
|
if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
|
|
116
64
|
return;
|
|
117
65
|
}
|
|
118
66
|
const firstLoad = !window.ttq;
|
|
119
67
|
snippet();
|
|
120
68
|
if (!firstLoad || !window.ttq) {
|
|
121
|
-
sendIdentityData(manifest.variables, keyName, getEdgeData);
|
|
122
69
|
return;
|
|
123
70
|
}
|
|
124
71
|
window.ttq.load(manifest.variables['pixelId']);
|
|
@@ -126,7 +73,6 @@ var ProvidersTiktokSdk = (function () {
|
|
|
126
73
|
window.ttq.instance(manifest.variables['pixelId']).identify({
|
|
127
74
|
external_id: userId,
|
|
128
75
|
});
|
|
129
|
-
sendIdentityData(manifest.variables, keyName, getEdgeData);
|
|
130
76
|
};
|
|
131
77
|
|
|
132
78
|
const getEventName = (event, manifestVariables) => {
|
|
@@ -217,34 +163,15 @@ var ProvidersTiktokSdk = (function () {
|
|
|
217
163
|
window.ttq.instance(manifestVariables['pixelId']).track(tiktokEventName, Object.assign(Object.assign({}, prepareData(data)), { event_id: eventId }));
|
|
218
164
|
}
|
|
219
165
|
return {
|
|
220
|
-
sdkVersion: "0.
|
|
166
|
+
sdkVersion: "0.16.0" ,
|
|
221
167
|
};
|
|
222
168
|
};
|
|
223
169
|
|
|
224
|
-
const user = ({ data, manifestVariables }) => {
|
|
225
|
-
var _a;
|
|
226
|
-
if (!window || !window.ttq || !data || !manifestVariables['pixelId']) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const userData = {};
|
|
230
|
-
if (data['email']) {
|
|
231
|
-
userData.email = data['email'];
|
|
232
|
-
}
|
|
233
|
-
const phone = (_a = data['phone']) !== null && _a !== void 0 ? _a : '';
|
|
234
|
-
if (phone && validatePhoneNumber(phone)) {
|
|
235
|
-
userData.phone_number = phone;
|
|
236
|
-
}
|
|
237
|
-
if (Object.keys(userData).length) {
|
|
238
|
-
window.ttq.instance(manifestVariables['pixelId']).identify(Object.assign({}, userData));
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
|
|
242
170
|
/* eslint-enable */
|
|
243
171
|
const data = {
|
|
244
172
|
name: 'tiktok',
|
|
245
173
|
tag,
|
|
246
174
|
init,
|
|
247
|
-
user,
|
|
248
175
|
};
|
|
249
176
|
try {
|
|
250
177
|
if (window) {
|