@depict-ai/utilishared 2.6.20 → 2.6.22
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/ES10/index.cjs +234 -33
- package/ES10/index.d.ts +78 -1
- package/ES10/index.js +230 -34
- package/latest/index.cjs +230 -34
- package/latest/index.d.ts +78 -1
- package/latest/index.js +226 -35
- package/package.json +2 -2
- package/server/ES10/index.cjs +234 -33
- package/server/ES10/index.d.ts +78 -1
- package/server/ES10/index.js +230 -34
- package/server/latest/index.cjs +230 -34
- package/server/latest/index.d.ts +78 -1
- package/server/latest/index.js +226 -35
package/latest/index.cjs
CHANGED
|
@@ -82,6 +82,11 @@ $parcel$export(module.exports, "get_session_id", () => $e0a87646d12cb987$export$
|
|
|
82
82
|
$parcel$export(module.exports, "get_cookie", () => $e0a87646d12cb987$export$622991c71a1f52b3);
|
|
83
83
|
$parcel$export(module.exports, "get_tracking_event_context_data", () => $e0a87646d12cb987$export$8c6f26a5b6921b95);
|
|
84
84
|
$parcel$export(module.exports, "set_event_transport", () => $92e75e76b1a9e331$export$83c5d6634ba2a3c5);
|
|
85
|
+
$parcel$export(module.exports, "set_event_api", () => $92e75e76b1a9e331$export$1a4819a80859e92e);
|
|
86
|
+
$parcel$export(module.exports, "get_event_api", () => $92e75e76b1a9e331$export$88fbe329a1d960c8);
|
|
87
|
+
$parcel$export(module.exports, "queue_native_events", () => $92e75e76b1a9e331$export$f72bace509bf62ef);
|
|
88
|
+
$parcel$export(module.exports, "native_purchase_event", () => $cf5d1b4537e0340b$export$aad1b28cf2e0eea6);
|
|
89
|
+
$parcel$export(module.exports, "to_native_event", () => $cf5d1b4537e0340b$export$537c002f32ae6f61);
|
|
85
90
|
$parcel$export(module.exports, "filter_depict_payload", () => $0c84f8e99aac5765$export$72036d950e1fae95);
|
|
86
91
|
$parcel$export(module.exports, "send_depict", () => $0c84f8e99aac5765$export$28cacbd9b4306ffc);
|
|
87
92
|
$parcel$export(module.exports, "foolproof_send_beacon", () => $0c84f8e99aac5765$export$cc3b6ddf805f6156);
|
|
@@ -205,7 +210,7 @@ $parcel$export(module.exports, "version", () => $815f67c61b4c0a42$export$83d89fb
|
|
|
205
210
|
$parcel$export(module.exports, "add_to_version_info", () => $e4a18bf12ad092d9$export$2cefb7e61fcbae00);
|
|
206
211
|
$parcel$export(module.exports, "sync_el_content_with_accessor", () => $35303d72263038db$export$c3f56a35e076f139);
|
|
207
212
|
$parcel$export(module.exports, "use_href_accessor", () => $da35c7e27be2a442$export$e35115e6d0715f77);
|
|
208
|
-
const $815f67c61b4c0a42$export$83d89fbfd8236492 = "2.6.
|
|
213
|
+
const $815f67c61b4c0a42$export$83d89fbfd8236492 = "2.6.22";
|
|
209
214
|
const $7b5e577a60b81e60$export$55fe61489d2c7417 = /*@__PURE__*/(() => process.env.STRIP_DEBUG === "true" ? false : process.env.DEBUG === "true" || process.env.NODE_ENV === "development" || process.env.BUILD_TARGET !== "node" && (globalThis?.document?.currentScript?.dataset?.debug === "true" || globalThis?.localStorage?.getItem?.("debug") === "true"))();
|
|
210
215
|
const $e6c6e7929ea385ae$var$browser_prefix_styling = "color: #fff;";
|
|
211
216
|
let $e6c6e7929ea385ae$var$browser_prefix = "[Depict]";
|
|
@@ -1083,6 +1088,135 @@ class $d10801050840d92b$export$1d9c6fddbff3441f extends $d10801050840d92b$export
|
|
|
1083
1088
|
["open", "error", "message"].forEach(event => this.addEventListener(event, $268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => this.#connection_last_active = +new Date())));
|
|
1084
1089
|
}
|
|
1085
1090
|
}
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Where tracking events go: `v3` (the default) posts every event to `/create-events`; `v4` posts each event that the
|
|
1094
|
+
* native events contract can carry to `/v4/{merchant}/events` (NDJSON) and leaves the rest on `/create-events`.
|
|
1095
|
+
*/ /**
|
|
1096
|
+
* One line of `POST /v4/{merchant}/events`, as the strict V4 contract (`Event` in realtime `v4/types`) defines it.
|
|
1097
|
+
* Only these keys are sent.
|
|
1098
|
+
*/ /** The contract's limits, so an event V4 would reject stays on v3 instead of being dropped. */
|
|
1099
|
+
const $cf5d1b4537e0340b$var$EVENT_ID_MAX = 128;
|
|
1100
|
+
const $cf5d1b4537e0340b$var$MARKET_MAX = 128;
|
|
1101
|
+
const $cf5d1b4537e0340b$var$SESSION_ID_MAX = 256;
|
|
1102
|
+
const $cf5d1b4537e0340b$var$PRODUCT_ID_MAX = 500;
|
|
1103
|
+
const $cf5d1b4537e0340b$var$TRACKING_ID_MAX = 1536;
|
|
1104
|
+
const $cf5d1b4537e0340b$var$MERCHANT = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
1105
|
+
/** V4's card tracking id (`d1.<kind>.<request id>.<position>.<product>[.<context>]`); V4 writes no row for others. */
|
|
1106
|
+
const $cf5d1b4537e0340b$var$D1_TRACKING_ID = /^d1\.[slrp]\.[0-9a-f]{32}\.(0|[1-9][0-9]{0,4})\.[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)?$/;
|
|
1107
|
+
const $cf5d1b4537e0340b$var$CURRENCY = /^[A-Z]{3}$/;
|
|
1108
|
+
const $cf5d1b4537e0340b$var$non_empty = (value, max) => typeof value === "string" && value.length > 0 && value.length <= max;
|
|
1109
|
+
function $cf5d1b4537e0340b$export$637d3149de458a95(tenant) {
|
|
1110
|
+
return typeof tenant === "string" && $cf5d1b4537e0340b$var$MERCHANT.test(tenant) ? tenant : undefined;
|
|
1111
|
+
}
|
|
1112
|
+
function $cf5d1b4537e0340b$export$e7dbc5ffe3253bf0(value) {
|
|
1113
|
+
return typeof value === "string" && value.length <= $cf5d1b4537e0340b$var$TRACKING_ID_MAX && $cf5d1b4537e0340b$var$D1_TRACKING_ID.test(value) ? value : undefined;
|
|
1114
|
+
}
|
|
1115
|
+
function $cf5d1b4537e0340b$export$3ad94ee026666a31(body, ts) {
|
|
1116
|
+
const {
|
|
1117
|
+
deduplication_id: deduplication_id,
|
|
1118
|
+
market: market,
|
|
1119
|
+
session_id: session_id
|
|
1120
|
+
} = body;
|
|
1121
|
+
if (!$cf5d1b4537e0340b$var$non_empty(deduplication_id, $cf5d1b4537e0340b$var$EVENT_ID_MAX) || !$cf5d1b4537e0340b$var$non_empty(market, $cf5d1b4537e0340b$var$MARKET_MAX)) return undefined;
|
|
1122
|
+
if (!$cf5d1b4537e0340b$var$non_empty(session_id, $cf5d1b4537e0340b$var$SESSION_ID_MAX)) return undefined;
|
|
1123
|
+
return {
|
|
1124
|
+
event_id: deduplication_id,
|
|
1125
|
+
market: market,
|
|
1126
|
+
session_id: session_id,
|
|
1127
|
+
ts: ts
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
function $cf5d1b4537e0340b$export$537c002f32ae6f61(body, ts) {
|
|
1131
|
+
const merchant = $cf5d1b4537e0340b$export$637d3149de458a95(body.tenant);
|
|
1132
|
+
const base = $cf5d1b4537e0340b$export$3ad94ee026666a31(body, ts);
|
|
1133
|
+
if (!merchant || !base) return undefined;
|
|
1134
|
+
const optional = (key, value) => typeof value === "string" && value ? {
|
|
1135
|
+
[key]: value
|
|
1136
|
+
} : {};
|
|
1137
|
+
const context = {
|
|
1138
|
+
...optional("url", body.url),
|
|
1139
|
+
...optional("referrer", body.document_referrer)
|
|
1140
|
+
};
|
|
1141
|
+
// The first result id set, as v3's intake reads it (resultIdOf in realtime): a v3 id there keeps the event on v3.
|
|
1142
|
+
const result_id = body.product_listing_result_id ?? body.recommendation_id ?? body.search_result_id;
|
|
1143
|
+
const tracking_id = $cf5d1b4537e0340b$export$e7dbc5ffe3253bf0(result_id);
|
|
1144
|
+
const has_result_id = result_id != null;
|
|
1145
|
+
const product_id = $cf5d1b4537e0340b$var$non_empty(body.product_id, $cf5d1b4537e0340b$var$PRODUCT_ID_MAX) ? body.product_id : undefined;
|
|
1146
|
+
if (body.product_id != null && !product_id) return undefined;
|
|
1147
|
+
let event;
|
|
1148
|
+
switch (body.type) {
|
|
1149
|
+
case "element_visible":
|
|
1150
|
+
case "click":
|
|
1151
|
+
if (!tracking_id) return undefined;
|
|
1152
|
+
event = {
|
|
1153
|
+
...base,
|
|
1154
|
+
type: body.type === "click" ? "click" : "impression",
|
|
1155
|
+
tracking_id: tracking_id,
|
|
1156
|
+
...context
|
|
1157
|
+
};
|
|
1158
|
+
break;
|
|
1159
|
+
case "add_to_cart":
|
|
1160
|
+
if (has_result_id ? !tracking_id : !product_id) return undefined;
|
|
1161
|
+
event = {
|
|
1162
|
+
...base,
|
|
1163
|
+
type: "add_to_cart",
|
|
1164
|
+
...(tracking_id ? {
|
|
1165
|
+
tracking_id: tracking_id
|
|
1166
|
+
} : {}),
|
|
1167
|
+
...(product_id ? {
|
|
1168
|
+
product_id: product_id
|
|
1169
|
+
} : {}),
|
|
1170
|
+
...context
|
|
1171
|
+
};
|
|
1172
|
+
break;
|
|
1173
|
+
case "page_view":
|
|
1174
|
+
if (!product_id || has_result_id && !tracking_id) return undefined;
|
|
1175
|
+
event = {
|
|
1176
|
+
...base,
|
|
1177
|
+
type: "product_view",
|
|
1178
|
+
product_id: product_id,
|
|
1179
|
+
...(tracking_id ? {
|
|
1180
|
+
tracking_id: tracking_id
|
|
1181
|
+
} : {}),
|
|
1182
|
+
...context
|
|
1183
|
+
};
|
|
1184
|
+
break;
|
|
1185
|
+
default:
|
|
1186
|
+
return undefined;
|
|
1187
|
+
}
|
|
1188
|
+
return {
|
|
1189
|
+
merchant: merchant,
|
|
1190
|
+
event: event
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
function $cf5d1b4537e0340b$export$aad1b28cf2e0eea6(data, ts) {
|
|
1194
|
+
const base = $cf5d1b4537e0340b$export$3ad94ee026666a31({
|
|
1195
|
+
deduplication_id: data.event_id,
|
|
1196
|
+
market: data.market,
|
|
1197
|
+
session_id: data.session_id
|
|
1198
|
+
}, ts);
|
|
1199
|
+
if (!base || !$cf5d1b4537e0340b$var$non_empty(data.transaction_id, Infinity) || !$cf5d1b4537e0340b$var$CURRENCY.test(data.currency)) return undefined;
|
|
1200
|
+
const valid_items = data.items.every(item => $cf5d1b4537e0340b$var$non_empty(item.sku, Infinity) && typeof item.price === "number" && Number.isFinite(item.price) && Number.isInteger(item.quantity) && item.quantity > 0);
|
|
1201
|
+
if (!valid_items) return undefined;
|
|
1202
|
+
return {
|
|
1203
|
+
...base,
|
|
1204
|
+
type: "purchase",
|
|
1205
|
+
purchase: {
|
|
1206
|
+
transaction_id: data.transaction_id,
|
|
1207
|
+
currency: data.currency,
|
|
1208
|
+
items: data.items.map(({
|
|
1209
|
+
sku: sku,
|
|
1210
|
+
price: price,
|
|
1211
|
+
quantity: quantity
|
|
1212
|
+
}) => ({
|
|
1213
|
+
sku: sku,
|
|
1214
|
+
price: price,
|
|
1215
|
+
quantity: quantity
|
|
1216
|
+
}))
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1086
1220
|
const $4c6861fbcd3a0611$export$362abebb4b313340 = process.env.DEPICT_BASE_URL || "https://api.depict.ai";
|
|
1087
1221
|
|
|
1088
1222
|
/**
|
|
@@ -1100,14 +1234,24 @@ function $650b64c1b384c895$export$a6db784f019668ba() {
|
|
|
1100
1234
|
const $92e75e76b1a9e331$var$MAX_BODY_BYTES = 49152;
|
|
1101
1235
|
const $92e75e76b1a9e331$var$IMPRESSION_DELAY_MS = 250;
|
|
1102
1236
|
let $92e75e76b1a9e331$var$transport = "http";
|
|
1237
|
+
let $92e75e76b1a9e331$var$event_api = "v3";
|
|
1103
1238
|
let $92e75e76b1a9e331$var$socket;
|
|
1104
|
-
let $92e75e76b1a9e331$var$queued_events = [];
|
|
1105
|
-
let $92e75e76b1a9e331$var$queued_bytes = 2;
|
|
1106
1239
|
let $92e75e76b1a9e331$var$flush_timer;
|
|
1107
1240
|
let $92e75e76b1a9e331$var$listening = false;
|
|
1241
|
+
/**
|
|
1242
|
+
* Queued events per endpoint. v3's `/create-events` takes a JSON array; V4's `/v4/{merchant}/events` takes NDJSON.
|
|
1243
|
+
* Both bodies are the events joined by one separator byte, plus v3's two brackets.
|
|
1244
|
+
*/
|
|
1245
|
+
const $92e75e76b1a9e331$var$batches = new Map();
|
|
1108
1246
|
function $92e75e76b1a9e331$export$83c5d6634ba2a3c5(value) {
|
|
1109
1247
|
$92e75e76b1a9e331$var$transport = value === "both" ? "both" : "http";
|
|
1110
1248
|
}
|
|
1249
|
+
function $92e75e76b1a9e331$export$1a4819a80859e92e(value) {
|
|
1250
|
+
$92e75e76b1a9e331$var$event_api = value === "v4" ? "v4" : "v3";
|
|
1251
|
+
}
|
|
1252
|
+
function $92e75e76b1a9e331$export$88fbe329a1d960c8() {
|
|
1253
|
+
return $92e75e76b1a9e331$var$event_api;
|
|
1254
|
+
}
|
|
1111
1255
|
function $92e75e76b1a9e331$var$send_beacon(url, body) {
|
|
1112
1256
|
try {
|
|
1113
1257
|
if (!navigator.sendBeacon(url, new Blob([body], {
|
|
@@ -1117,7 +1261,17 @@ function $92e75e76b1a9e331$var$send_beacon(url, body) {
|
|
|
1117
1261
|
$268cbd9e4ade92db$export$f18d5b0af29128b7(error, "warning");
|
|
1118
1262
|
}
|
|
1119
1263
|
}
|
|
1120
|
-
|
|
1264
|
+
/** V4 answers 200 even when it rejects lines; a rejected line is an event the contract no longer takes. */
|
|
1265
|
+
function $92e75e76b1a9e331$var$check_native_response(response, url) {
|
|
1266
|
+
if (response.status !== 200 || typeof response.json !== "function") return;
|
|
1267
|
+
response.json().then(body => {
|
|
1268
|
+
if (body?.rejected) $268cbd9e4ade92db$export$f18d5b0af29128b7(new Error("V4 rejected tracking events"), "warning", {
|
|
1269
|
+
url: url,
|
|
1270
|
+
...body
|
|
1271
|
+
});
|
|
1272
|
+
}).catch(() => {});
|
|
1273
|
+
}
|
|
1274
|
+
function $92e75e76b1a9e331$var$send_batch(url, body, retried = false, native = false) {
|
|
1121
1275
|
let request;
|
|
1122
1276
|
try {
|
|
1123
1277
|
request = fetch(url, {
|
|
@@ -1134,20 +1288,61 @@ function $92e75e76b1a9e331$var$send_batch(url, body, retried = false) {
|
|
|
1134
1288
|
return;
|
|
1135
1289
|
}
|
|
1136
1290
|
request.then(response => {
|
|
1137
|
-
if (response.status >= 500 && !retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true);
|
|
1291
|
+
if (response.status >= 500 && !retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true, native);else if (native) $92e75e76b1a9e331$var$check_native_response(response, url);
|
|
1138
1292
|
}, () => {
|
|
1139
|
-
if (!retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true);else $92e75e76b1a9e331$var$send_beacon(url, body);
|
|
1293
|
+
if (!retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true, native);else $92e75e76b1a9e331$var$send_beacon(url, body);
|
|
1140
1294
|
}).catch(error => $268cbd9e4ade92db$export$f18d5b0af29128b7(error, "warning"));
|
|
1141
1295
|
}
|
|
1296
|
+
function $92e75e76b1a9e331$var$flush_batch(url) {
|
|
1297
|
+
const batch = $92e75e76b1a9e331$var$batches.get(url);
|
|
1298
|
+
if (!batch) return;
|
|
1299
|
+
$92e75e76b1a9e331$var$batches.delete(url);
|
|
1300
|
+
$92e75e76b1a9e331$var$send_batch(url, batch.ndjson ? batch.events.join("\n") : `[${batch.events.join(",")}]`, false, batch.ndjson);
|
|
1301
|
+
}
|
|
1142
1302
|
const $92e75e76b1a9e331$var$flush = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
|
|
1143
1303
|
clearTimeout($92e75e76b1a9e331$var$flush_timer);
|
|
1144
1304
|
$92e75e76b1a9e331$var$flush_timer = undefined;
|
|
1145
|
-
|
|
1146
|
-
const body = `[${$92e75e76b1a9e331$var$queued_events.join(",")}]`;
|
|
1147
|
-
$92e75e76b1a9e331$var$queued_events = [];
|
|
1148
|
-
$92e75e76b1a9e331$var$queued_bytes = 2;
|
|
1149
|
-
$92e75e76b1a9e331$var$send_batch(String($e4a18bf12ad092d9$export$fe609f0216e4ebef((0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/create-events")), body);
|
|
1305
|
+
for (const url of [...$92e75e76b1a9e331$var$batches.keys()]) $92e75e76b1a9e331$var$flush_batch(url);
|
|
1150
1306
|
});
|
|
1307
|
+
const $92e75e76b1a9e331$var$v3_url = () => String($e4a18bf12ad092d9$export$fe609f0216e4ebef((0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/create-events"));
|
|
1308
|
+
/** No version params: like the native reads, V4 gets only what its contract defines. */
|
|
1309
|
+
const $92e75e76b1a9e331$var$v4_url = merchant => `${(0, $4c6861fbcd3a0611$export$362abebb4b313340)}/v4/${encodeURIComponent(merchant)}/events`;
|
|
1310
|
+
function $92e75e76b1a9e331$var$listen() {
|
|
1311
|
+
if ($92e75e76b1a9e331$var$listening) return;
|
|
1312
|
+
document.addEventListener("visibilitychange", () => {
|
|
1313
|
+
if (document.visibilityState === "hidden") $92e75e76b1a9e331$var$flush();
|
|
1314
|
+
});
|
|
1315
|
+
window.addEventListener("pagehide", $92e75e76b1a9e331$var$flush);
|
|
1316
|
+
$92e75e76b1a9e331$var$listening = true;
|
|
1317
|
+
}
|
|
1318
|
+
/** Adds one serialized event to its endpoint's batch, sending the batch first if the event wouldn't fit. */
|
|
1319
|
+
function $92e75e76b1a9e331$var$enqueue(url, json, ndjson, type) {
|
|
1320
|
+
const bytes = new Blob([json]).size;
|
|
1321
|
+
const empty_bytes = ndjson ? 0 : 2;
|
|
1322
|
+
if (bytes + empty_bytes > $92e75e76b1a9e331$var$MAX_BODY_BYTES) {
|
|
1323
|
+
$268cbd9e4ade92db$export$f18d5b0af29128b7(new Error("Event exceeds the keepalive body limit"), "warning", {
|
|
1324
|
+
bytes: bytes,
|
|
1325
|
+
type: type
|
|
1326
|
+
});
|
|
1327
|
+
return false;
|
|
1328
|
+
}
|
|
1329
|
+
let batch = $92e75e76b1a9e331$var$batches.get(url);
|
|
1330
|
+
if (batch && batch.bytes + bytes + 1 > $92e75e76b1a9e331$var$MAX_BODY_BYTES) {
|
|
1331
|
+
$92e75e76b1a9e331$var$flush_batch(url);
|
|
1332
|
+
batch = undefined;
|
|
1333
|
+
}
|
|
1334
|
+
if (!batch) $92e75e76b1a9e331$var$batches.set(url, batch = {
|
|
1335
|
+
events: [],
|
|
1336
|
+
bytes: empty_bytes,
|
|
1337
|
+
ndjson: ndjson
|
|
1338
|
+
});
|
|
1339
|
+
batch.bytes += bytes + (batch.events.length ? 1 : 0);
|
|
1340
|
+
batch.events.push(json);
|
|
1341
|
+
return true;
|
|
1342
|
+
}
|
|
1343
|
+
function $92e75e76b1a9e331$var$schedule(immediate) {
|
|
1344
|
+
if (immediate) $92e75e76b1a9e331$var$flush();else if ($92e75e76b1a9e331$var$batches.size && $92e75e76b1a9e331$var$flush_timer === undefined) $92e75e76b1a9e331$var$flush_timer = setTimeout($92e75e76b1a9e331$var$flush, $92e75e76b1a9e331$var$IMPRESSION_DELAY_MS);
|
|
1345
|
+
}
|
|
1151
1346
|
const $92e75e76b1a9e331$var$send_canary = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(json => {
|
|
1152
1347
|
if (typeof WebSocket !== "function") return;
|
|
1153
1348
|
$92e75e76b1a9e331$var$socket ||= new (0, $d10801050840d92b$export$1d9c6fddbff3441f)("wss://ws.depict.ai/ws/create-events");
|
|
@@ -1159,36 +1354,37 @@ const $92e75e76b1a9e331$var$send_canary = /*@__PURE__*/$268cbd9e4ade92db$export$
|
|
|
1159
1354
|
}, undefined, "warning");
|
|
1160
1355
|
function $92e75e76b1a9e331$export$fb18f6dbe1c6f251(payload) {
|
|
1161
1356
|
if (process.env.DEPICT === "false" || typeof document === "undefined") return;
|
|
1162
|
-
|
|
1163
|
-
document.addEventListener("visibilitychange", () => {
|
|
1164
|
-
if (document.visibilityState === "hidden") $92e75e76b1a9e331$var$flush();
|
|
1165
|
-
});
|
|
1166
|
-
window.addEventListener("pagehide", $92e75e76b1a9e331$var$flush);
|
|
1167
|
-
$92e75e76b1a9e331$var$listening = true;
|
|
1168
|
-
}
|
|
1357
|
+
$92e75e76b1a9e331$var$listen();
|
|
1169
1358
|
let accepted = true;
|
|
1170
1359
|
let immediate = document.visibilityState === "hidden";
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
});
|
|
1360
|
+
const ts = new Date().toISOString();
|
|
1361
|
+
for (const raw of payload) {
|
|
1362
|
+
const event = {
|
|
1363
|
+
...raw,
|
|
1364
|
+
deduplication_id: raw.deduplication_id || $650b64c1b384c895$export$656831b7e9c341c3()
|
|
1365
|
+
};
|
|
1366
|
+
const native = $92e75e76b1a9e331$var$event_api === "v4" ? $cf5d1b4537e0340b$export$537c002f32ae6f61(event, ts) : undefined;
|
|
1367
|
+
const json = JSON.stringify(native ? native.event : event);
|
|
1368
|
+
const queued = native ? $92e75e76b1a9e331$var$enqueue($92e75e76b1a9e331$var$v4_url(native.merchant), json, true, event.type) : $92e75e76b1a9e331$var$enqueue($92e75e76b1a9e331$var$v3_url(), json, false, event.type);
|
|
1369
|
+
if (!queued) {
|
|
1182
1370
|
accepted = false;
|
|
1183
1371
|
continue;
|
|
1184
1372
|
}
|
|
1185
|
-
if ($92e75e76b1a9e331$var$queued_bytes + bytes + ($92e75e76b1a9e331$var$queued_events.length ? 1 : 0) > $92e75e76b1a9e331$var$MAX_BODY_BYTES) $92e75e76b1a9e331$var$flush();
|
|
1186
|
-
$92e75e76b1a9e331$var$queued_bytes += bytes + ($92e75e76b1a9e331$var$queued_events.length ? 1 : 0);
|
|
1187
|
-
$92e75e76b1a9e331$var$queued_events.push(json);
|
|
1188
1373
|
immediate ||= event.type !== "element_visible";
|
|
1189
|
-
|
|
1374
|
+
// The canary socket is v3's; an event sent to V4 isn't mirrored there.
|
|
1375
|
+
if ($92e75e76b1a9e331$var$transport === "both" && !native) $92e75e76b1a9e331$var$send_canary(json);
|
|
1190
1376
|
}
|
|
1191
|
-
|
|
1377
|
+
$92e75e76b1a9e331$var$schedule(immediate);
|
|
1378
|
+
return accepted;
|
|
1379
|
+
}
|
|
1380
|
+
function $92e75e76b1a9e331$export$f72bace509bf62ef(merchant, events) {
|
|
1381
|
+
if (process.env.DEPICT === "false" || typeof document === "undefined") return;
|
|
1382
|
+
const path_merchant = $cf5d1b4537e0340b$export$637d3149de458a95(merchant);
|
|
1383
|
+
if (!path_merchant) return false;
|
|
1384
|
+
$92e75e76b1a9e331$var$listen();
|
|
1385
|
+
let accepted = true;
|
|
1386
|
+
for (const event of events) accepted = $92e75e76b1a9e331$var$enqueue($92e75e76b1a9e331$var$v4_url(path_merchant), JSON.stringify(event), true, event.type) && accepted;
|
|
1387
|
+
$92e75e76b1a9e331$var$schedule(true);
|
|
1192
1388
|
return accepted;
|
|
1193
1389
|
}
|
|
1194
1390
|
const $0c84f8e99aac5765$var$c = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9);
|
package/latest/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSX, Accessor } from "solid-js";
|
|
2
|
-
export const version = "2.6.
|
|
2
|
+
export const version = "2.6.22";
|
|
3
3
|
export const is_debug: boolean;
|
|
4
4
|
/**
|
|
5
5
|
* Sets the prefix of dlog, dwarn, and derror messages in the browser console. Defaults to `[Depict]`.
|
|
@@ -217,6 +217,71 @@ export class DepictAPIWS extends AutoReconnectingWS {
|
|
|
217
217
|
initial_retry_ms: number;
|
|
218
218
|
}>]);
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Where tracking events go: `v3` (the default) posts every event to `/create-events`; `v4` posts each event that the
|
|
222
|
+
* native events contract can carry to `/v4/{merchant}/events` (NDJSON) and leaves the rest on `/create-events`.
|
|
223
|
+
*/
|
|
224
|
+
export type EventApi = "v3" | "v4";
|
|
225
|
+
/**
|
|
226
|
+
* One line of `POST /v4/{merchant}/events`, as the strict V4 contract (`Event` in realtime `v4/types`) defines it.
|
|
227
|
+
* Only these keys are sent.
|
|
228
|
+
*/
|
|
229
|
+
export type NativeEvent = {
|
|
230
|
+
event_id: string;
|
|
231
|
+
type: "impression" | "click" | "add_to_cart" | "product_view" | "purchase";
|
|
232
|
+
market: string;
|
|
233
|
+
session_id: string;
|
|
234
|
+
ts: string;
|
|
235
|
+
product_id?: string;
|
|
236
|
+
tracking_id?: string;
|
|
237
|
+
url?: string;
|
|
238
|
+
referrer?: string;
|
|
239
|
+
purchase?: {
|
|
240
|
+
transaction_id: string;
|
|
241
|
+
currency: string;
|
|
242
|
+
items: {
|
|
243
|
+
sku: string;
|
|
244
|
+
price: number;
|
|
245
|
+
quantity: number;
|
|
246
|
+
}[];
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Maps a v3 `/create-events` body to a native V4 event, with the merchant it's posted under. Undefined means V4
|
|
251
|
+
* can't take it as v3 did, so it stays on `/create-events`:
|
|
252
|
+
*
|
|
253
|
+
* - `element_visible` → `impression` and `click` → `click`, only with a d1 `recommendation_id`, `search_result_id` or
|
|
254
|
+
* `product_listing_result_id` (the card's V4 `tracking_id`). V4 decodes the kind from the id, so the result
|
|
255
|
+
* field it came in doesn't matter. A v3 result id (from a v3 recommendation, say) stays on v3: V4 writes no row
|
|
256
|
+
* for an id it can't decode.
|
|
257
|
+
* - `add_to_cart` → `add_to_cart`, with the d1 result id or a `product_id` (a PDP button).
|
|
258
|
+
* - `page_view` → `product_view`, only on a PDP (`product_id` set). V4 has no plain page view.
|
|
259
|
+
* - Anything else (`recommendations_inserted`, `purchase` on `/create-events`, errors) has no V4 type.
|
|
260
|
+
*
|
|
261
|
+
* Fields V4 has no place for are not sent: `tenant` (it's the path), `entity_price`, `currency` (outside purchase),
|
|
262
|
+
* `document_width`, `attribution_id`, `click_location`, `ab_test_group`, `variant_ids`, `entity_identifiers`,
|
|
263
|
+
* `recommendation_type`, `error_type`, `detail`.
|
|
264
|
+
*/
|
|
265
|
+
export function to_native_event(body: depict_body, ts: string): {
|
|
266
|
+
merchant: string;
|
|
267
|
+
event: NativeEvent;
|
|
268
|
+
} | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* A native purchase event, or undefined when it would break the contract (then the caller keeps v3's
|
|
271
|
+
* `/v2/create-events`).
|
|
272
|
+
*/
|
|
273
|
+
export function native_purchase_event(data: {
|
|
274
|
+
event_id: string;
|
|
275
|
+
market?: string;
|
|
276
|
+
session_id?: string;
|
|
277
|
+
transaction_id: string;
|
|
278
|
+
currency: string;
|
|
279
|
+
items: {
|
|
280
|
+
sku: string;
|
|
281
|
+
price: number;
|
|
282
|
+
quantity: number;
|
|
283
|
+
}[];
|
|
284
|
+
}, ts: string): NativeEvent | undefined;
|
|
220
285
|
export const base_url: string;
|
|
221
286
|
/**
|
|
222
287
|
* Returns a random string
|
|
@@ -230,6 +295,18 @@ export type EventTransport = "http" | "both";
|
|
|
230
295
|
* Switching to http stops new socket sends but leaves an existing canary socket open.
|
|
231
296
|
*/
|
|
232
297
|
export function set_event_transport(value: EventTransport): void;
|
|
298
|
+
/**
|
|
299
|
+
* Configure before tracking starts; shared by users of this utilishared module. `v4` sends each event the native
|
|
300
|
+
* events contract can carry to `/v4/{merchant}/events` instead of `/create-events` (see `to_native_event`); `v3`
|
|
301
|
+
* (the default) sends everything to `/create-events`.
|
|
302
|
+
*/
|
|
303
|
+
export function set_event_api(value: EventApi): void;
|
|
304
|
+
export function get_event_api(): EventApi;
|
|
305
|
+
/**
|
|
306
|
+
* Sends native V4 events for `merchant` right away (with whatever else is queued), with the same retries and
|
|
307
|
+
* beacon fallback as v3 events. Returns false if the merchant isn't one V4 accepts or an event is too large.
|
|
308
|
+
*/
|
|
309
|
+
export function queue_native_events(merchant: string, events: NativeEvent[]): boolean | undefined;
|
|
233
310
|
export type event_types = "page_view" | "click" | "add_to_cart" | "purchase" | "element_visible";
|
|
234
311
|
declare const allowed_keys: readonly ["deduplication_id", "tenant", "market", "type", "session_id", "product_id", "entity_identifiers", "url", "entity_price", "currency", "document_referrer", "document_width", "attribution_id", "recommendation_id", "click_location", "ab_test_group", "variant_ids", "transaction_id", "error_type", "detail", "recommendation_type", "search_result_id", "product_listing_result_id"];
|
|
235
312
|
export type depict_body = Partial<{ [K in (typeof allowed_keys)[number]]: any }>;
|