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