@blotoutio/providers-snapchat-sdk 0.8.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/README.md +11 -0
- package/index.js +155 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# providers-snapchat-sdk
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Running unit tests
|
|
6
|
+
|
|
7
|
+
Run `nx test providers-snapchat-sdk` to execute the unit tests via [Jest](https://jestjs.io).
|
|
8
|
+
|
|
9
|
+
## Running lint
|
|
10
|
+
|
|
11
|
+
Run `nx lint providers-snapchat-sdk` to execute the lint via [ESLint](https://eslint.org/).
|
package/index.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var ProvidersSnapchatSdk = (function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const snippet = () => {
|
|
5
|
+
if (!window || !document || window.snaptr) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const a = (window.snaptr = function () {
|
|
9
|
+
a['handleRequest']
|
|
10
|
+
? // eslint-disable-next-line prefer-spread,prefer-rest-params
|
|
11
|
+
a['handleRequest'].apply(a, arguments)
|
|
12
|
+
: // eslint-disable-next-line prefer-rest-params
|
|
13
|
+
a['queue'].push(arguments);
|
|
14
|
+
});
|
|
15
|
+
a['queue'] = [];
|
|
16
|
+
const element = document.createElement('script');
|
|
17
|
+
element.async = !0;
|
|
18
|
+
element.src = 'https://sc-static.net/scevent.min.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.snaptr;
|
|
29
|
+
snippet();
|
|
30
|
+
if (!firstLoad || !window.snaptr) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
window.snaptr('init', manifest.variables['pixelId']);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const prepareData = (data) => {
|
|
37
|
+
const payload = {};
|
|
38
|
+
if (data['currency']) {
|
|
39
|
+
payload['currency'] = data['currency'];
|
|
40
|
+
}
|
|
41
|
+
if (data['search']) {
|
|
42
|
+
payload['search_string'] = data['search'];
|
|
43
|
+
}
|
|
44
|
+
if (data['description']) {
|
|
45
|
+
payload['description'] = data['description'];
|
|
46
|
+
}
|
|
47
|
+
if (data['orderId']) {
|
|
48
|
+
payload['transaction_id'] = data['orderId'];
|
|
49
|
+
}
|
|
50
|
+
if (data['success']) {
|
|
51
|
+
payload['success'] = data['success'];
|
|
52
|
+
}
|
|
53
|
+
if (data['sign_up_method']) {
|
|
54
|
+
payload['sign_up_method'] = data['sign_up_method'];
|
|
55
|
+
}
|
|
56
|
+
if (data['contents'] && Array.isArray(data['contents'])) {
|
|
57
|
+
payload['number_items'] = data['contents']
|
|
58
|
+
.map((content) => content.quantity)
|
|
59
|
+
.join(';');
|
|
60
|
+
payload['item_ids'] = data['contents']
|
|
61
|
+
.map((content) => content.id)
|
|
62
|
+
.join(';');
|
|
63
|
+
payload['item_category'] = data['contents'].map((content) => content.category);
|
|
64
|
+
payload['price'] = data['contents']
|
|
65
|
+
.map((content) => parseFloat(content.item_price))
|
|
66
|
+
.join(';');
|
|
67
|
+
}
|
|
68
|
+
return payload;
|
|
69
|
+
};
|
|
70
|
+
const getSnapEventName = (name) => {
|
|
71
|
+
switch (name) {
|
|
72
|
+
case 'InitiateCheckout': {
|
|
73
|
+
return 'START_CHECKOUT';
|
|
74
|
+
}
|
|
75
|
+
case 'AddToCart': {
|
|
76
|
+
return 'ADD_CART';
|
|
77
|
+
}
|
|
78
|
+
case 'ViewContent': {
|
|
79
|
+
return 'VIEW_CONTENT';
|
|
80
|
+
}
|
|
81
|
+
case 'AddPaymentInfo': {
|
|
82
|
+
return 'ADD_BILLING';
|
|
83
|
+
}
|
|
84
|
+
case 'AddToWishlist': {
|
|
85
|
+
return 'ADD_TO_WISHLIST';
|
|
86
|
+
}
|
|
87
|
+
case 'CompleteRegistration': {
|
|
88
|
+
return 'SIGN_UP';
|
|
89
|
+
}
|
|
90
|
+
case 'PageView': {
|
|
91
|
+
return 'PAGE_VIEW';
|
|
92
|
+
}
|
|
93
|
+
case 'StartTrial': {
|
|
94
|
+
return 'START_TRIAL';
|
|
95
|
+
}
|
|
96
|
+
case 'AdClick': {
|
|
97
|
+
return 'AD_CLICK';
|
|
98
|
+
}
|
|
99
|
+
case 'AdView': {
|
|
100
|
+
return 'AD_VIEW';
|
|
101
|
+
}
|
|
102
|
+
case 'CompleteTutorial': {
|
|
103
|
+
return 'COMPLETE_TUTORIAL';
|
|
104
|
+
}
|
|
105
|
+
case 'ListView': {
|
|
106
|
+
return 'LIST_VIEW';
|
|
107
|
+
}
|
|
108
|
+
case 'SpentCredits': {
|
|
109
|
+
return 'SPENT_CREDITS';
|
|
110
|
+
}
|
|
111
|
+
case 'AppInstall': {
|
|
112
|
+
return 'APP_INSTALL';
|
|
113
|
+
}
|
|
114
|
+
case 'AppOpen': {
|
|
115
|
+
return 'APP_OPEN';
|
|
116
|
+
}
|
|
117
|
+
case 'AchievementUnlocked': {
|
|
118
|
+
return 'ACHIEVEMENT_UNLOCKED';
|
|
119
|
+
}
|
|
120
|
+
case 'LevelComplete': {
|
|
121
|
+
return 'LEVEL_COMPLETE';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (name.startsWith('CustomEvent')) {
|
|
125
|
+
return `CUSTOM_EVENT_${name[name.length - 1]}`;
|
|
126
|
+
}
|
|
127
|
+
return name.toUpperCase();
|
|
128
|
+
};
|
|
129
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
130
|
+
if (!window.snaptr || manifestVariables['enableBrowser'] !== '1') {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
window.snaptr('track', getSnapEventName(eventName), Object.assign(Object.assign({}, prepareData(data)), { client_dedup_id: eventId.toString() }));
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const data = {
|
|
137
|
+
name: 'snapchat',
|
|
138
|
+
tag,
|
|
139
|
+
init,
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
if (window) {
|
|
143
|
+
if (!window.edgetagProviders) {
|
|
144
|
+
window.edgetagProviders = [];
|
|
145
|
+
}
|
|
146
|
+
window.edgetagProviders.push(data);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (_a) {
|
|
150
|
+
// No window
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return data;
|
|
154
|
+
|
|
155
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blotoutio/providers-snapchat-sdk",
|
|
3
|
+
"version": "0.8.3",
|
|
4
|
+
"description": "Snapchat 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
|
+
}
|