@blotoutio/providers-twitter-sdk 0.26.4 → 0.26.6
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 +111 -0
- package/index.js +1 -1
- package/index.mjs +109 -0
- package/package.json +5 -2
package/index.cjs.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const snippet = () => {
|
|
4
|
+
if (!window || !document || window.twq) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const n = (window.twq = function () {
|
|
8
|
+
n['exe']
|
|
9
|
+
? // eslint-disable-next-line prefer-spread,prefer-rest-params
|
|
10
|
+
n['exe'].apply(n, arguments)
|
|
11
|
+
: // eslint-disable-next-line prefer-rest-params
|
|
12
|
+
n['queue'].push(arguments);
|
|
13
|
+
});
|
|
14
|
+
n['version'] = '1.1';
|
|
15
|
+
n['queue'] = [];
|
|
16
|
+
const element = document.createElement('script');
|
|
17
|
+
element.async = !0;
|
|
18
|
+
element.src = 'https://static.ads-twitter.com/uwt.js';
|
|
19
|
+
const script = document.getElementsByTagName('script')[0];
|
|
20
|
+
if (script && script.parentNode) {
|
|
21
|
+
script.parentNode.insertBefore(element, script);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const init = ({ manifest }) => {
|
|
25
|
+
if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const firstLoad = !window.twq;
|
|
29
|
+
snippet();
|
|
30
|
+
if (!firstLoad || !window.twq) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
window.twq('config', manifest.variables['pixelId']);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const prepareData = (data) => {
|
|
37
|
+
const payload = {};
|
|
38
|
+
if (data['value']) {
|
|
39
|
+
payload['value'] = data['value'];
|
|
40
|
+
}
|
|
41
|
+
if (data['currency']) {
|
|
42
|
+
payload['currency'] = data['currency'];
|
|
43
|
+
}
|
|
44
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
45
|
+
payload['contents'] = data['contents'].map((item) => {
|
|
46
|
+
const content = {};
|
|
47
|
+
if (item.id || item.variantId) {
|
|
48
|
+
content['content_id'] = item.id || item.variantId;
|
|
49
|
+
}
|
|
50
|
+
if (item.quantity) {
|
|
51
|
+
content['num_items'] = item.quantity;
|
|
52
|
+
}
|
|
53
|
+
if (item.item_price) {
|
|
54
|
+
content['content_price'] = item.item_price;
|
|
55
|
+
}
|
|
56
|
+
if (item.category) {
|
|
57
|
+
content['content_type'] = item.category;
|
|
58
|
+
}
|
|
59
|
+
if (item.title) {
|
|
60
|
+
content['content_name'] = item.title;
|
|
61
|
+
}
|
|
62
|
+
return content;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return payload;
|
|
66
|
+
};
|
|
67
|
+
const getEventId = (event, conversions) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
if (!event) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const mapping = conversions ? JSON.parse(conversions) : [];
|
|
74
|
+
return ((_b = (_a = mapping.find((item) => item.event === event)) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : null);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
console.error(e);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
81
|
+
const payload = {
|
|
82
|
+
sdkVersion: "0.26.6" ,
|
|
83
|
+
};
|
|
84
|
+
if (window.twq && manifestVariables['enableBrowser'] === '1') {
|
|
85
|
+
const twitterEventId = getEventId(eventName, manifestVariables['mappedConversions']);
|
|
86
|
+
window.twq('event', `tw-${manifestVariables['pixelId']}-${twitterEventId}`, {
|
|
87
|
+
...prepareData(data),
|
|
88
|
+
conversion_id: eventId,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return payload;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const data = {
|
|
95
|
+
name: 'twitter',
|
|
96
|
+
tag,
|
|
97
|
+
init,
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
if (window) {
|
|
101
|
+
if (!window.edgetagProviders) {
|
|
102
|
+
window.edgetagProviders = [];
|
|
103
|
+
}
|
|
104
|
+
window.edgetagProviders.push(data);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// No window
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = data;
|
package/index.js
CHANGED
|
@@ -80,7 +80,7 @@ var ProvidersTwitterSdk = (function () {
|
|
|
80
80
|
};
|
|
81
81
|
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
82
82
|
const payload = {
|
|
83
|
-
sdkVersion: "0.26.
|
|
83
|
+
sdkVersion: "0.26.6" ,
|
|
84
84
|
};
|
|
85
85
|
if (window.twq && manifestVariables['enableBrowser'] === '1') {
|
|
86
86
|
const twitterEventId = getEventId(eventName, manifestVariables['mappedConversions']);
|
package/index.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const snippet = () => {
|
|
2
|
+
if (!window || !document || window.twq) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const n = (window.twq = function () {
|
|
6
|
+
n['exe']
|
|
7
|
+
? // eslint-disable-next-line prefer-spread,prefer-rest-params
|
|
8
|
+
n['exe'].apply(n, arguments)
|
|
9
|
+
: // eslint-disable-next-line prefer-rest-params
|
|
10
|
+
n['queue'].push(arguments);
|
|
11
|
+
});
|
|
12
|
+
n['version'] = '1.1';
|
|
13
|
+
n['queue'] = [];
|
|
14
|
+
const element = document.createElement('script');
|
|
15
|
+
element.async = !0;
|
|
16
|
+
element.src = 'https://static.ads-twitter.com/uwt.js';
|
|
17
|
+
const script = document.getElementsByTagName('script')[0];
|
|
18
|
+
if (script && script.parentNode) {
|
|
19
|
+
script.parentNode.insertBefore(element, script);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const init = ({ manifest }) => {
|
|
23
|
+
if (!manifest.variables || manifest.variables['enableBrowser'] !== '1') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const firstLoad = !window.twq;
|
|
27
|
+
snippet();
|
|
28
|
+
if (!firstLoad || !window.twq) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
window.twq('config', manifest.variables['pixelId']);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const prepareData = (data) => {
|
|
35
|
+
const payload = {};
|
|
36
|
+
if (data['value']) {
|
|
37
|
+
payload['value'] = data['value'];
|
|
38
|
+
}
|
|
39
|
+
if (data['currency']) {
|
|
40
|
+
payload['currency'] = data['currency'];
|
|
41
|
+
}
|
|
42
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
43
|
+
payload['contents'] = data['contents'].map((item) => {
|
|
44
|
+
const content = {};
|
|
45
|
+
if (item.id || item.variantId) {
|
|
46
|
+
content['content_id'] = item.id || item.variantId;
|
|
47
|
+
}
|
|
48
|
+
if (item.quantity) {
|
|
49
|
+
content['num_items'] = item.quantity;
|
|
50
|
+
}
|
|
51
|
+
if (item.item_price) {
|
|
52
|
+
content['content_price'] = item.item_price;
|
|
53
|
+
}
|
|
54
|
+
if (item.category) {
|
|
55
|
+
content['content_type'] = item.category;
|
|
56
|
+
}
|
|
57
|
+
if (item.title) {
|
|
58
|
+
content['content_name'] = item.title;
|
|
59
|
+
}
|
|
60
|
+
return content;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return payload;
|
|
64
|
+
};
|
|
65
|
+
const getEventId = (event, conversions) => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
if (!event) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const mapping = conversions ? JSON.parse(conversions) : [];
|
|
72
|
+
return ((_b = (_a = mapping.find((item) => item.event === event)) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : null);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error(e);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
79
|
+
const payload = {
|
|
80
|
+
sdkVersion: "0.26.6" ,
|
|
81
|
+
};
|
|
82
|
+
if (window.twq && manifestVariables['enableBrowser'] === '1') {
|
|
83
|
+
const twitterEventId = getEventId(eventName, manifestVariables['mappedConversions']);
|
|
84
|
+
window.twq('event', `tw-${manifestVariables['pixelId']}-${twitterEventId}`, {
|
|
85
|
+
...prepareData(data),
|
|
86
|
+
conversion_id: eventId,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return payload;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const data = {
|
|
93
|
+
name: 'twitter',
|
|
94
|
+
tag,
|
|
95
|
+
init,
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
if (window) {
|
|
99
|
+
if (!window.edgetagProviders) {
|
|
100
|
+
window.edgetagProviders = [];
|
|
101
|
+
}
|
|
102
|
+
window.edgetagProviders.push(data);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// No window
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { data as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotoutio/providers-twitter-sdk",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.6",
|
|
4
4
|
"description": "Twitter 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
|
]
|