@blotoutio/providers-tiktok-sdk 0.8.0 → 0.8.2
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 +67 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -59,19 +59,67 @@ var ProvidersTiktokSdk = (function () {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
|
-
const
|
|
62
|
+
const sendIdentityData = (variables, keyName, getEdgeData) => {
|
|
63
|
+
var _a, _b, _c, _d;
|
|
64
|
+
if (!window || !window.ttq) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const customerData = [];
|
|
68
|
+
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 : {};
|
|
69
|
+
const kvData = JSON.parse(sessionStorage.getItem(keyName !== null && keyName !== void 0 ? keyName : '') || '{}')['kv'] || {};
|
|
70
|
+
if (!('email' in tiktokUserInfo)) {
|
|
71
|
+
customerData.push('email');
|
|
72
|
+
}
|
|
73
|
+
if (!('phone_number' in tiktokUserInfo)) {
|
|
74
|
+
customerData.push('phone');
|
|
75
|
+
}
|
|
76
|
+
const identifyData = {};
|
|
77
|
+
const cacheMiss = customerData.filter((item) => !(item in kvData));
|
|
78
|
+
customerData.forEach((item) => {
|
|
79
|
+
if (item in kvData) {
|
|
80
|
+
identifyData[item] = kvData[item];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (getEdgeData && cacheMiss.length) {
|
|
84
|
+
getEdgeData(cacheMiss, (data) => {
|
|
85
|
+
var _a;
|
|
86
|
+
customerData.forEach((item) => {
|
|
87
|
+
if (item in data) {
|
|
88
|
+
identifyData[item] = data[item];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if ('phone' in identifyData) {
|
|
92
|
+
identifyData['phone_number'] = identifyData['phone'];
|
|
93
|
+
delete identifyData['phone'];
|
|
94
|
+
}
|
|
95
|
+
Object.keys(identifyData).length &&
|
|
96
|
+
((_a = window.ttq) === null || _a === void 0 ? void 0 : _a.instance(variables['pixelId']).identify(identifyData));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else if (customerData.length && !cacheMiss.length) {
|
|
100
|
+
if ('phone' in identifyData) {
|
|
101
|
+
identifyData['phone_number'] = identifyData['phone'];
|
|
102
|
+
delete identifyData['phone'];
|
|
103
|
+
}
|
|
104
|
+
Object.keys(identifyData).length &&
|
|
105
|
+
((_d = window.ttq) === null || _d === void 0 ? void 0 : _d.instance(variables['pixelId']).identify(identifyData));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const init = ({ manifest, userId, getEdgeData, keyName }) => {
|
|
63
109
|
if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
|
|
64
110
|
return;
|
|
65
111
|
}
|
|
66
112
|
const firstLoad = !window.ttq;
|
|
67
113
|
snippet();
|
|
68
114
|
if (!firstLoad || !window.ttq) {
|
|
115
|
+
sendIdentityData(manifest.variables, keyName, getEdgeData);
|
|
69
116
|
return;
|
|
70
117
|
}
|
|
71
118
|
window.ttq.load(manifest.variables['pixelId']);
|
|
72
119
|
window.ttq.instance(manifest.variables['pixelId']).identify({
|
|
73
120
|
external_id: userId,
|
|
74
121
|
});
|
|
122
|
+
sendIdentityData(manifest.variables, keyName, getEdgeData);
|
|
75
123
|
};
|
|
76
124
|
|
|
77
125
|
const getEventName = (event) => {
|
|
@@ -165,11 +213,29 @@ var ProvidersTiktokSdk = (function () {
|
|
|
165
213
|
window.ttq.instance(manifestVariables['pixelId']).track(tiktokEventName, Object.assign(Object.assign({}, prepareData(data, tiktokEventName)), { event_id: eventId }));
|
|
166
214
|
};
|
|
167
215
|
|
|
216
|
+
const user = ({ data, manifestVariables }) => {
|
|
217
|
+
if (!window || !window.ttq || !data) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const userData = {};
|
|
221
|
+
if (data['email']) {
|
|
222
|
+
userData.email = data['email'];
|
|
223
|
+
}
|
|
224
|
+
const phone = data['phone'];
|
|
225
|
+
if (phone) {
|
|
226
|
+
userData.phone_number = phone.startsWith('+') ? phone : `+${phone}`;
|
|
227
|
+
}
|
|
228
|
+
if (Object.keys(userData).length) {
|
|
229
|
+
window.ttq.instance(manifestVariables['pixelId']).identify(Object.assign({}, userData));
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
168
233
|
/* eslint-enable */
|
|
169
234
|
const data = {
|
|
170
235
|
name: 'tiktok',
|
|
171
236
|
tag,
|
|
172
237
|
init,
|
|
238
|
+
user,
|
|
173
239
|
};
|
|
174
240
|
try {
|
|
175
241
|
if (window) {
|