@blotoutio/providers-trybe-sdk 1.45.1
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 +24 -0
- package/index.cjs.js +196 -0
- package/index.d.ts +1 -0
- package/index.js +199 -0
- package/index.mjs +194 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @blotoutio/providers-trybe-sdk
|
|
2
|
+
|
|
3
|
+
Browser-side Trybe integration for EdgeTag. Calls the Trybe pixel's `window.trybe.track*`
|
|
4
|
+
methods when EdgeTag events fire.
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
The Trybe pixel must be installed on the page before this SDK runs. The pixel sets up
|
|
9
|
+
`window.trybe` and the visitor-ID cookie (`ugc_vid_{storeId}`).
|
|
10
|
+
|
|
11
|
+
## Event Mapping
|
|
12
|
+
|
|
13
|
+
| EdgeTag Event | Trybe Method |
|
|
14
|
+
| ------------------ | --------------------------------------- |
|
|
15
|
+
| `ViewContent` | `window.trybe.trackProductViewed()` |
|
|
16
|
+
| `AddToCart` | `window.trybe.trackAddToCart()` |
|
|
17
|
+
| `InitiateCheckout` | `window.trybe.trackCheckoutStarted()` |
|
|
18
|
+
| `Purchase` | `window.trybe.trackCheckoutCompleted()` |
|
|
19
|
+
|
|
20
|
+
## Visitor ID
|
|
21
|
+
|
|
22
|
+
The SDK automatically reads `window.trybe.vid` and passes it back to the server-side
|
|
23
|
+
EdgeTag CDN worker via `providerData`. The CDN worker independently reads the same ID
|
|
24
|
+
from the `ugc_vid_{storeId}` cookie for reliable server-side order attribution.
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const packageName = 'trybe';
|
|
4
|
+
|
|
5
|
+
const canLog = () => {
|
|
6
|
+
try {
|
|
7
|
+
return localStorage.getItem('edgeTagDebug') === '1';
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const prefix = `[EdgeTag]`;
|
|
14
|
+
const logger = {
|
|
15
|
+
log: (...args) => {
|
|
16
|
+
if (canLog()) {
|
|
17
|
+
console.log(prefix, ...args);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
error: (...args) => {
|
|
21
|
+
if (canLog()) {
|
|
22
|
+
console.error(prefix, ...args);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
info: (...args) => {
|
|
26
|
+
if (canLog()) {
|
|
27
|
+
console.info(prefix, ...args);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
trace: (...args) => {
|
|
31
|
+
if (canLog()) {
|
|
32
|
+
console.trace(prefix, ...args);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const tag = ({ eventName, data, manifestVariables }) => {
|
|
38
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
|
|
39
|
+
try {
|
|
40
|
+
if (!(window === null || window === void 0 ? void 0 : window._trybe)) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
const excludedEvents = (_a = manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['trybeExcludedEvents']) !== null && _a !== void 0 ? _a : '';
|
|
44
|
+
if (excludedEvents
|
|
45
|
+
.split(',')
|
|
46
|
+
.map((e) => e.trim())
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.includes(eventName)) {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
const d = (data !== null && data !== void 0 ? data : {});
|
|
52
|
+
const vid = window._trybe.vid;
|
|
53
|
+
if (!vid) {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
switch (eventName) {
|
|
57
|
+
case 'ViewContent': {
|
|
58
|
+
const item = Array.isArray(d['contents'])
|
|
59
|
+
? d['contents'][0]
|
|
60
|
+
: null;
|
|
61
|
+
(_c = (_b = window._trybe).trackProductViewed) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
62
|
+
vid,
|
|
63
|
+
productId: String((_e = (_d = item === null || item === void 0 ? void 0 : item['id']) !== null && _d !== void 0 ? _d : d['productId']) !== null && _e !== void 0 ? _e : ''),
|
|
64
|
+
productName: String((_g = (_f = item === null || item === void 0 ? void 0 : item['title']) !== null && _f !== void 0 ? _f : d['productName']) !== null && _g !== void 0 ? _g : ''),
|
|
65
|
+
price: Number((_j = (_h = item === null || item === void 0 ? void 0 : item['item_price']) !== null && _h !== void 0 ? _h : d['price']) !== null && _j !== void 0 ? _j : 0),
|
|
66
|
+
currency: String((_k = d['currency']) !== null && _k !== void 0 ? _k : 'USD'),
|
|
67
|
+
productUrl: String((_l = d['productUrl']) !== null && _l !== void 0 ? _l : window.location.href),
|
|
68
|
+
imageUrl: String((_o = (_m = item === null || item === void 0 ? void 0 : item['imageUrl']) !== null && _m !== void 0 ? _m : d['imageUrl']) !== null && _o !== void 0 ? _o : ''),
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'AddToCart': {
|
|
73
|
+
const item = Array.isArray(d['contents'])
|
|
74
|
+
? d['contents'][0]
|
|
75
|
+
: null;
|
|
76
|
+
(_q = (_p = window._trybe).trackAddToCart) === null || _q === void 0 ? void 0 : _q.call(_p, {
|
|
77
|
+
vid,
|
|
78
|
+
productId: String((_s = (_r = item === null || item === void 0 ? void 0 : item['id']) !== null && _r !== void 0 ? _r : d['productId']) !== null && _s !== void 0 ? _s : ''),
|
|
79
|
+
productName: String((_u = (_t = item === null || item === void 0 ? void 0 : item['title']) !== null && _t !== void 0 ? _t : d['productName']) !== null && _u !== void 0 ? _u : ''),
|
|
80
|
+
quantity: Number((_w = (_v = item === null || item === void 0 ? void 0 : item['quantity']) !== null && _v !== void 0 ? _v : d['quantity']) !== null && _w !== void 0 ? _w : 1),
|
|
81
|
+
price: Number((_y = (_x = item === null || item === void 0 ? void 0 : item['item_price']) !== null && _x !== void 0 ? _x : d['price']) !== null && _y !== void 0 ? _y : 0),
|
|
82
|
+
currency: String((_z = d['currency']) !== null && _z !== void 0 ? _z : 'USD'),
|
|
83
|
+
});
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'InitiateCheckout': {
|
|
87
|
+
const contents = Array.isArray(d['contents'])
|
|
88
|
+
? d['contents']
|
|
89
|
+
: [];
|
|
90
|
+
(_1 = (_0 = window._trybe).trackCheckoutStarted) === null || _1 === void 0 ? void 0 : _1.call(_0, {
|
|
91
|
+
vid,
|
|
92
|
+
cartValue: Number((_2 = d['value']) !== null && _2 !== void 0 ? _2 : 0),
|
|
93
|
+
currency: String((_3 = d['currency']) !== null && _3 !== void 0 ? _3 : 'USD'),
|
|
94
|
+
itemCount: contents.length || Number((_4 = d['itemCount']) !== null && _4 !== void 0 ? _4 : 0),
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'Purchase': {
|
|
99
|
+
(_6 = (_5 = window._trybe).trackCheckoutCompleted) === null || _6 === void 0 ? void 0 : _6.call(_5, {
|
|
100
|
+
vid,
|
|
101
|
+
orderId: String((_7 = d['orderId']) !== null && _7 !== void 0 ? _7 : ''),
|
|
102
|
+
orderValue: Number((_8 = d['value']) !== null && _8 !== void 0 ? _8 : 0),
|
|
103
|
+
currency: String((_9 = d['currency']) !== null && _9 !== void 0 ? _9 : 'USD'),
|
|
104
|
+
});
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return { vid };
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
logger.error(error);
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const loadPixel = (pixelCode, storeId, pixelDomain) => {
|
|
119
|
+
if (!window || !document) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
let customDomain;
|
|
123
|
+
try {
|
|
124
|
+
customDomain = new URL(pixelDomain).hostname;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
logger.error(new Error(`Trybe pixel not loaded: invalid TRYBE_PIXEL_DOMAIN value "${pixelDomain}". Must be a valid URL (e.g. https://tracks.example.com).`));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const hadTrybe = Boolean(window._trybe);
|
|
131
|
+
window._trybe = window._trybe || {
|
|
132
|
+
pixelCode,
|
|
133
|
+
storeId,
|
|
134
|
+
platform: 'CUSTOM',
|
|
135
|
+
autoTracking: 'false',
|
|
136
|
+
customDomain,
|
|
137
|
+
serviceUrl: 'https://prod-trybe-platform-6mi3j.ondigitalocean.app/attribution',
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
const script = document.createElement('script');
|
|
141
|
+
script.src = `${pixelDomain}/pixel.js`;
|
|
142
|
+
script.async = true;
|
|
143
|
+
script.setAttribute('data-pixel-code', pixelCode);
|
|
144
|
+
script.setAttribute('data-store-id', storeId);
|
|
145
|
+
script.setAttribute('data-platform', 'CUSTOM');
|
|
146
|
+
script.setAttribute('data-auto-tracking', 'false');
|
|
147
|
+
document.head.appendChild(script);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (!hadTrybe) {
|
|
151
|
+
delete window._trybe;
|
|
152
|
+
}
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const init = ({ manifest }) => {
|
|
157
|
+
var _a, _b, _c;
|
|
158
|
+
try {
|
|
159
|
+
if (!window) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (window._trybe) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const pixelCode = (_a = manifest.variables) === null || _a === void 0 ? void 0 : _a['pixelCode'];
|
|
166
|
+
const storeId = (_b = manifest.variables) === null || _b === void 0 ? void 0 : _b['storeId'];
|
|
167
|
+
const pixelDomain = (_c = manifest.variables) === null || _c === void 0 ? void 0 : _c['pixelDomain'];
|
|
168
|
+
if (!pixelCode || !storeId || !pixelDomain) {
|
|
169
|
+
logger.log('Trybe pixel is not loaded. Ensure the Trybe pixel is installed on the page or TRYBE_PIXEL_CODE, TRYBE_STORE_ID, and TRYBE_PIXEL_DOMAIN are configured.');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
loadPixel(pixelCode, storeId, pixelDomain);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
logger.error(error);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const data = {
|
|
180
|
+
name: packageName,
|
|
181
|
+
init,
|
|
182
|
+
tag,
|
|
183
|
+
};
|
|
184
|
+
try {
|
|
185
|
+
if (!window.edgetagProviders) {
|
|
186
|
+
window.edgetagProviders = [];
|
|
187
|
+
}
|
|
188
|
+
if (!window.edgetagProviders.some((p) => p.name === data.name)) {
|
|
189
|
+
window.edgetagProviders.push(data);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// No window
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = data;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '@blotoutio/providers-trybe-sdk'
|
package/index.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
var ProvidersTrybeSdk = (function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const packageName = 'trybe';
|
|
5
|
+
|
|
6
|
+
const canLog = () => {
|
|
7
|
+
try {
|
|
8
|
+
return localStorage.getItem('edgeTagDebug') === '1';
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const prefix = `[EdgeTag]`;
|
|
15
|
+
const logger = {
|
|
16
|
+
log: (...args) => {
|
|
17
|
+
if (canLog()) {
|
|
18
|
+
console.log(prefix, ...args);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
error: (...args) => {
|
|
22
|
+
if (canLog()) {
|
|
23
|
+
console.error(prefix, ...args);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
info: (...args) => {
|
|
27
|
+
if (canLog()) {
|
|
28
|
+
console.info(prefix, ...args);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
trace: (...args) => {
|
|
32
|
+
if (canLog()) {
|
|
33
|
+
console.trace(prefix, ...args);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const tag = ({ eventName, data, manifestVariables }) => {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
|
|
40
|
+
try {
|
|
41
|
+
if (!(window === null || window === void 0 ? void 0 : window._trybe)) {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
const excludedEvents = (_a = manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['trybeExcludedEvents']) !== null && _a !== void 0 ? _a : '';
|
|
45
|
+
if (excludedEvents
|
|
46
|
+
.split(',')
|
|
47
|
+
.map((e) => e.trim())
|
|
48
|
+
.filter(Boolean)
|
|
49
|
+
.includes(eventName)) {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
const d = (data !== null && data !== void 0 ? data : {});
|
|
53
|
+
const vid = window._trybe.vid;
|
|
54
|
+
if (!vid) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
switch (eventName) {
|
|
58
|
+
case 'ViewContent': {
|
|
59
|
+
const item = Array.isArray(d['contents'])
|
|
60
|
+
? d['contents'][0]
|
|
61
|
+
: null;
|
|
62
|
+
(_c = (_b = window._trybe).trackProductViewed) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
63
|
+
vid,
|
|
64
|
+
productId: String((_e = (_d = item === null || item === void 0 ? void 0 : item['id']) !== null && _d !== void 0 ? _d : d['productId']) !== null && _e !== void 0 ? _e : ''),
|
|
65
|
+
productName: String((_g = (_f = item === null || item === void 0 ? void 0 : item['title']) !== null && _f !== void 0 ? _f : d['productName']) !== null && _g !== void 0 ? _g : ''),
|
|
66
|
+
price: Number((_j = (_h = item === null || item === void 0 ? void 0 : item['item_price']) !== null && _h !== void 0 ? _h : d['price']) !== null && _j !== void 0 ? _j : 0),
|
|
67
|
+
currency: String((_k = d['currency']) !== null && _k !== void 0 ? _k : 'USD'),
|
|
68
|
+
productUrl: String((_l = d['productUrl']) !== null && _l !== void 0 ? _l : window.location.href),
|
|
69
|
+
imageUrl: String((_o = (_m = item === null || item === void 0 ? void 0 : item['imageUrl']) !== null && _m !== void 0 ? _m : d['imageUrl']) !== null && _o !== void 0 ? _o : ''),
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case 'AddToCart': {
|
|
74
|
+
const item = Array.isArray(d['contents'])
|
|
75
|
+
? d['contents'][0]
|
|
76
|
+
: null;
|
|
77
|
+
(_q = (_p = window._trybe).trackAddToCart) === null || _q === void 0 ? void 0 : _q.call(_p, {
|
|
78
|
+
vid,
|
|
79
|
+
productId: String((_s = (_r = item === null || item === void 0 ? void 0 : item['id']) !== null && _r !== void 0 ? _r : d['productId']) !== null && _s !== void 0 ? _s : ''),
|
|
80
|
+
productName: String((_u = (_t = item === null || item === void 0 ? void 0 : item['title']) !== null && _t !== void 0 ? _t : d['productName']) !== null && _u !== void 0 ? _u : ''),
|
|
81
|
+
quantity: Number((_w = (_v = item === null || item === void 0 ? void 0 : item['quantity']) !== null && _v !== void 0 ? _v : d['quantity']) !== null && _w !== void 0 ? _w : 1),
|
|
82
|
+
price: Number((_y = (_x = item === null || item === void 0 ? void 0 : item['item_price']) !== null && _x !== void 0 ? _x : d['price']) !== null && _y !== void 0 ? _y : 0),
|
|
83
|
+
currency: String((_z = d['currency']) !== null && _z !== void 0 ? _z : 'USD'),
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'InitiateCheckout': {
|
|
88
|
+
const contents = Array.isArray(d['contents'])
|
|
89
|
+
? d['contents']
|
|
90
|
+
: [];
|
|
91
|
+
(_1 = (_0 = window._trybe).trackCheckoutStarted) === null || _1 === void 0 ? void 0 : _1.call(_0, {
|
|
92
|
+
vid,
|
|
93
|
+
cartValue: Number((_2 = d['value']) !== null && _2 !== void 0 ? _2 : 0),
|
|
94
|
+
currency: String((_3 = d['currency']) !== null && _3 !== void 0 ? _3 : 'USD'),
|
|
95
|
+
itemCount: contents.length || Number((_4 = d['itemCount']) !== null && _4 !== void 0 ? _4 : 0),
|
|
96
|
+
});
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 'Purchase': {
|
|
100
|
+
(_6 = (_5 = window._trybe).trackCheckoutCompleted) === null || _6 === void 0 ? void 0 : _6.call(_5, {
|
|
101
|
+
vid,
|
|
102
|
+
orderId: String((_7 = d['orderId']) !== null && _7 !== void 0 ? _7 : ''),
|
|
103
|
+
orderValue: Number((_8 = d['value']) !== null && _8 !== void 0 ? _8 : 0),
|
|
104
|
+
currency: String((_9 = d['currency']) !== null && _9 !== void 0 ? _9 : 'USD'),
|
|
105
|
+
});
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
return { vid };
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
logger.error(error);
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const loadPixel = (pixelCode, storeId, pixelDomain) => {
|
|
120
|
+
if (!window || !document) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let customDomain;
|
|
124
|
+
try {
|
|
125
|
+
customDomain = new URL(pixelDomain).hostname;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
logger.error(new Error(`Trybe pixel not loaded: invalid TRYBE_PIXEL_DOMAIN value "${pixelDomain}". Must be a valid URL (e.g. https://tracks.example.com).`));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const hadTrybe = Boolean(window._trybe);
|
|
132
|
+
window._trybe = window._trybe || {
|
|
133
|
+
pixelCode,
|
|
134
|
+
storeId,
|
|
135
|
+
platform: 'CUSTOM',
|
|
136
|
+
autoTracking: 'false',
|
|
137
|
+
customDomain,
|
|
138
|
+
serviceUrl: 'https://prod-trybe-platform-6mi3j.ondigitalocean.app/attribution',
|
|
139
|
+
};
|
|
140
|
+
try {
|
|
141
|
+
const script = document.createElement('script');
|
|
142
|
+
script.src = `${pixelDomain}/pixel.js`;
|
|
143
|
+
script.async = true;
|
|
144
|
+
script.setAttribute('data-pixel-code', pixelCode);
|
|
145
|
+
script.setAttribute('data-store-id', storeId);
|
|
146
|
+
script.setAttribute('data-platform', 'CUSTOM');
|
|
147
|
+
script.setAttribute('data-auto-tracking', 'false');
|
|
148
|
+
document.head.appendChild(script);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (!hadTrybe) {
|
|
152
|
+
delete window._trybe;
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const init = ({ manifest }) => {
|
|
158
|
+
var _a, _b, _c;
|
|
159
|
+
try {
|
|
160
|
+
if (!window) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (window._trybe) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const pixelCode = (_a = manifest.variables) === null || _a === void 0 ? void 0 : _a['pixelCode'];
|
|
167
|
+
const storeId = (_b = manifest.variables) === null || _b === void 0 ? void 0 : _b['storeId'];
|
|
168
|
+
const pixelDomain = (_c = manifest.variables) === null || _c === void 0 ? void 0 : _c['pixelDomain'];
|
|
169
|
+
if (!pixelCode || !storeId || !pixelDomain) {
|
|
170
|
+
logger.log('Trybe pixel is not loaded. Ensure the Trybe pixel is installed on the page or TRYBE_PIXEL_CODE, TRYBE_STORE_ID, and TRYBE_PIXEL_DOMAIN are configured.');
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
loadPixel(pixelCode, storeId, pixelDomain);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
logger.error(error);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const data = {
|
|
181
|
+
name: packageName,
|
|
182
|
+
init,
|
|
183
|
+
tag,
|
|
184
|
+
};
|
|
185
|
+
try {
|
|
186
|
+
if (!window.edgetagProviders) {
|
|
187
|
+
window.edgetagProviders = [];
|
|
188
|
+
}
|
|
189
|
+
if (!window.edgetagProviders.some((p) => p.name === data.name)) {
|
|
190
|
+
window.edgetagProviders.push(data);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
// No window
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return data;
|
|
198
|
+
|
|
199
|
+
})();
|
package/index.mjs
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const packageName = 'trybe';
|
|
2
|
+
|
|
3
|
+
const canLog = () => {
|
|
4
|
+
try {
|
|
5
|
+
return localStorage.getItem('edgeTagDebug') === '1';
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const prefix = `[EdgeTag]`;
|
|
12
|
+
const logger = {
|
|
13
|
+
log: (...args) => {
|
|
14
|
+
if (canLog()) {
|
|
15
|
+
console.log(prefix, ...args);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
error: (...args) => {
|
|
19
|
+
if (canLog()) {
|
|
20
|
+
console.error(prefix, ...args);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
info: (...args) => {
|
|
24
|
+
if (canLog()) {
|
|
25
|
+
console.info(prefix, ...args);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
trace: (...args) => {
|
|
29
|
+
if (canLog()) {
|
|
30
|
+
console.trace(prefix, ...args);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const tag = ({ eventName, data, manifestVariables }) => {
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
|
|
37
|
+
try {
|
|
38
|
+
if (!(window === null || window === void 0 ? void 0 : window._trybe)) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
const excludedEvents = (_a = manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['trybeExcludedEvents']) !== null && _a !== void 0 ? _a : '';
|
|
42
|
+
if (excludedEvents
|
|
43
|
+
.split(',')
|
|
44
|
+
.map((e) => e.trim())
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.includes(eventName)) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
const d = (data !== null && data !== void 0 ? data : {});
|
|
50
|
+
const vid = window._trybe.vid;
|
|
51
|
+
if (!vid) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
switch (eventName) {
|
|
55
|
+
case 'ViewContent': {
|
|
56
|
+
const item = Array.isArray(d['contents'])
|
|
57
|
+
? d['contents'][0]
|
|
58
|
+
: null;
|
|
59
|
+
(_c = (_b = window._trybe).trackProductViewed) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
60
|
+
vid,
|
|
61
|
+
productId: String((_e = (_d = item === null || item === void 0 ? void 0 : item['id']) !== null && _d !== void 0 ? _d : d['productId']) !== null && _e !== void 0 ? _e : ''),
|
|
62
|
+
productName: String((_g = (_f = item === null || item === void 0 ? void 0 : item['title']) !== null && _f !== void 0 ? _f : d['productName']) !== null && _g !== void 0 ? _g : ''),
|
|
63
|
+
price: Number((_j = (_h = item === null || item === void 0 ? void 0 : item['item_price']) !== null && _h !== void 0 ? _h : d['price']) !== null && _j !== void 0 ? _j : 0),
|
|
64
|
+
currency: String((_k = d['currency']) !== null && _k !== void 0 ? _k : 'USD'),
|
|
65
|
+
productUrl: String((_l = d['productUrl']) !== null && _l !== void 0 ? _l : window.location.href),
|
|
66
|
+
imageUrl: String((_o = (_m = item === null || item === void 0 ? void 0 : item['imageUrl']) !== null && _m !== void 0 ? _m : d['imageUrl']) !== null && _o !== void 0 ? _o : ''),
|
|
67
|
+
});
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'AddToCart': {
|
|
71
|
+
const item = Array.isArray(d['contents'])
|
|
72
|
+
? d['contents'][0]
|
|
73
|
+
: null;
|
|
74
|
+
(_q = (_p = window._trybe).trackAddToCart) === null || _q === void 0 ? void 0 : _q.call(_p, {
|
|
75
|
+
vid,
|
|
76
|
+
productId: String((_s = (_r = item === null || item === void 0 ? void 0 : item['id']) !== null && _r !== void 0 ? _r : d['productId']) !== null && _s !== void 0 ? _s : ''),
|
|
77
|
+
productName: String((_u = (_t = item === null || item === void 0 ? void 0 : item['title']) !== null && _t !== void 0 ? _t : d['productName']) !== null && _u !== void 0 ? _u : ''),
|
|
78
|
+
quantity: Number((_w = (_v = item === null || item === void 0 ? void 0 : item['quantity']) !== null && _v !== void 0 ? _v : d['quantity']) !== null && _w !== void 0 ? _w : 1),
|
|
79
|
+
price: Number((_y = (_x = item === null || item === void 0 ? void 0 : item['item_price']) !== null && _x !== void 0 ? _x : d['price']) !== null && _y !== void 0 ? _y : 0),
|
|
80
|
+
currency: String((_z = d['currency']) !== null && _z !== void 0 ? _z : 'USD'),
|
|
81
|
+
});
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'InitiateCheckout': {
|
|
85
|
+
const contents = Array.isArray(d['contents'])
|
|
86
|
+
? d['contents']
|
|
87
|
+
: [];
|
|
88
|
+
(_1 = (_0 = window._trybe).trackCheckoutStarted) === null || _1 === void 0 ? void 0 : _1.call(_0, {
|
|
89
|
+
vid,
|
|
90
|
+
cartValue: Number((_2 = d['value']) !== null && _2 !== void 0 ? _2 : 0),
|
|
91
|
+
currency: String((_3 = d['currency']) !== null && _3 !== void 0 ? _3 : 'USD'),
|
|
92
|
+
itemCount: contents.length || Number((_4 = d['itemCount']) !== null && _4 !== void 0 ? _4 : 0),
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'Purchase': {
|
|
97
|
+
(_6 = (_5 = window._trybe).trackCheckoutCompleted) === null || _6 === void 0 ? void 0 : _6.call(_5, {
|
|
98
|
+
vid,
|
|
99
|
+
orderId: String((_7 = d['orderId']) !== null && _7 !== void 0 ? _7 : ''),
|
|
100
|
+
orderValue: Number((_8 = d['value']) !== null && _8 !== void 0 ? _8 : 0),
|
|
101
|
+
currency: String((_9 = d['currency']) !== null && _9 !== void 0 ? _9 : 'USD'),
|
|
102
|
+
});
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return { vid };
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
logger.error(error);
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const loadPixel = (pixelCode, storeId, pixelDomain) => {
|
|
117
|
+
if (!window || !document) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let customDomain;
|
|
121
|
+
try {
|
|
122
|
+
customDomain = new URL(pixelDomain).hostname;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
logger.error(new Error(`Trybe pixel not loaded: invalid TRYBE_PIXEL_DOMAIN value "${pixelDomain}". Must be a valid URL (e.g. https://tracks.example.com).`));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const hadTrybe = Boolean(window._trybe);
|
|
129
|
+
window._trybe = window._trybe || {
|
|
130
|
+
pixelCode,
|
|
131
|
+
storeId,
|
|
132
|
+
platform: 'CUSTOM',
|
|
133
|
+
autoTracking: 'false',
|
|
134
|
+
customDomain,
|
|
135
|
+
serviceUrl: 'https://prod-trybe-platform-6mi3j.ondigitalocean.app/attribution',
|
|
136
|
+
};
|
|
137
|
+
try {
|
|
138
|
+
const script = document.createElement('script');
|
|
139
|
+
script.src = `${pixelDomain}/pixel.js`;
|
|
140
|
+
script.async = true;
|
|
141
|
+
script.setAttribute('data-pixel-code', pixelCode);
|
|
142
|
+
script.setAttribute('data-store-id', storeId);
|
|
143
|
+
script.setAttribute('data-platform', 'CUSTOM');
|
|
144
|
+
script.setAttribute('data-auto-tracking', 'false');
|
|
145
|
+
document.head.appendChild(script);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (!hadTrybe) {
|
|
149
|
+
delete window._trybe;
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const init = ({ manifest }) => {
|
|
155
|
+
var _a, _b, _c;
|
|
156
|
+
try {
|
|
157
|
+
if (!window) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (window._trybe) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const pixelCode = (_a = manifest.variables) === null || _a === void 0 ? void 0 : _a['pixelCode'];
|
|
164
|
+
const storeId = (_b = manifest.variables) === null || _b === void 0 ? void 0 : _b['storeId'];
|
|
165
|
+
const pixelDomain = (_c = manifest.variables) === null || _c === void 0 ? void 0 : _c['pixelDomain'];
|
|
166
|
+
if (!pixelCode || !storeId || !pixelDomain) {
|
|
167
|
+
logger.log('Trybe pixel is not loaded. Ensure the Trybe pixel is installed on the page or TRYBE_PIXEL_CODE, TRYBE_STORE_ID, and TRYBE_PIXEL_DOMAIN are configured.');
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
loadPixel(pixelCode, storeId, pixelDomain);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
logger.error(error);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const data = {
|
|
178
|
+
name: packageName,
|
|
179
|
+
init,
|
|
180
|
+
tag,
|
|
181
|
+
};
|
|
182
|
+
try {
|
|
183
|
+
if (!window.edgetagProviders) {
|
|
184
|
+
window.edgetagProviders = [];
|
|
185
|
+
}
|
|
186
|
+
if (!window.edgetagProviders.some((p) => p.name === data.name)) {
|
|
187
|
+
window.edgetagProviders.push(data);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// No window
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { data as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blotoutio/providers-trybe-sdk",
|
|
3
|
+
"version": "1.45.1",
|
|
4
|
+
"description": "Trybe 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.cjs.js",
|
|
12
|
+
"module": "./index.mjs",
|
|
13
|
+
"types": "./index.d.ts",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/blotoutio/edgetag-sdk.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"index.d.ts",
|
|
21
|
+
"index.cjs.js",
|
|
22
|
+
"index.mjs",
|
|
23
|
+
"package.json",
|
|
24
|
+
"README.md"
|
|
25
|
+
]
|
|
26
|
+
}
|