@blotoutio/providers-tiktok-sdk 0.10.1 → 0.10.3
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 +15 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
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
|
+
|
|
4
9
|
/* eslint-enable */
|
|
5
10
|
const snippet = () => {
|
|
6
11
|
if (!window || !document || window.ttq) {
|
|
@@ -88,7 +93,8 @@ var ProvidersTiktokSdk = (function () {
|
|
|
88
93
|
identifyData[item] = data[item];
|
|
89
94
|
}
|
|
90
95
|
});
|
|
91
|
-
if ('phone' in identifyData
|
|
96
|
+
if ('phone' in identifyData &&
|
|
97
|
+
validatePhoneNumber(identifyData['phone'])) {
|
|
92
98
|
identifyData['phone_number'] = identifyData['phone'];
|
|
93
99
|
delete identifyData['phone'];
|
|
94
100
|
}
|
|
@@ -97,7 +103,7 @@ var ProvidersTiktokSdk = (function () {
|
|
|
97
103
|
});
|
|
98
104
|
}
|
|
99
105
|
else if (customerData.length && !cacheMiss.length) {
|
|
100
|
-
if ('phone' in identifyData) {
|
|
106
|
+
if ('phone' in identifyData && validatePhoneNumber(identifyData['phone'])) {
|
|
101
107
|
identifyData['phone_number'] = identifyData['phone'];
|
|
102
108
|
delete identifyData['phone'];
|
|
103
109
|
}
|
|
@@ -116,6 +122,7 @@ var ProvidersTiktokSdk = (function () {
|
|
|
116
122
|
return;
|
|
117
123
|
}
|
|
118
124
|
window.ttq.load(manifest.variables['pixelId']);
|
|
125
|
+
window.ttq._partner = 'Blotout';
|
|
119
126
|
window.ttq.instance(manifest.variables['pixelId']).identify({
|
|
120
127
|
external_id: userId,
|
|
121
128
|
});
|
|
@@ -133,9 +140,7 @@ var ProvidersTiktokSdk = (function () {
|
|
|
133
140
|
return event;
|
|
134
141
|
};
|
|
135
142
|
const prepareData = (data) => {
|
|
136
|
-
const payload = {
|
|
137
|
-
app: 'Blotout',
|
|
138
|
-
};
|
|
143
|
+
const payload = {};
|
|
139
144
|
if (data['search']) {
|
|
140
145
|
payload['query'] = data['search'];
|
|
141
146
|
}
|
|
@@ -212,11 +217,12 @@ var ProvidersTiktokSdk = (function () {
|
|
|
212
217
|
window.ttq.instance(manifestVariables['pixelId']).track(tiktokEventName, Object.assign(Object.assign({}, prepareData(data)), { event_id: eventId }));
|
|
213
218
|
}
|
|
214
219
|
return {
|
|
215
|
-
sdkVersion: "0.10.
|
|
220
|
+
sdkVersion: "0.10.3" ,
|
|
216
221
|
};
|
|
217
222
|
};
|
|
218
223
|
|
|
219
224
|
const user = ({ data, manifestVariables }) => {
|
|
225
|
+
var _a;
|
|
220
226
|
if (!window || !window.ttq || !data) {
|
|
221
227
|
return;
|
|
222
228
|
}
|
|
@@ -224,9 +230,9 @@ var ProvidersTiktokSdk = (function () {
|
|
|
224
230
|
if (data['email']) {
|
|
225
231
|
userData.email = data['email'];
|
|
226
232
|
}
|
|
227
|
-
const phone = data['phone'];
|
|
228
|
-
if (phone) {
|
|
229
|
-
userData.phone_number = phone
|
|
233
|
+
const phone = (_a = data['phone']) !== null && _a !== void 0 ? _a : '';
|
|
234
|
+
if (phone && validatePhoneNumber(phone)) {
|
|
235
|
+
userData.phone_number = phone;
|
|
230
236
|
}
|
|
231
237
|
if (Object.keys(userData).length) {
|
|
232
238
|
window.ttq.instance(manifestVariables['pixelId']).identify(Object.assign({}, userData));
|