@konfiqo/storefront-react 0.4.0 → 0.6.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 +101 -4
- package/dist/index.cjs +808 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +246 -5
- package/dist/index.d.ts +246 -5
- package/dist/index.js +804 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -234,8 +234,8 @@ var CartStore = class {
|
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
236
|
addLine = (input) => this.write((id) => this.client.carts.addLine(id, input));
|
|
237
|
-
updateLine = (
|
|
238
|
-
removeLine = (
|
|
237
|
+
updateLine = (lineId, input) => this.write((id) => this.client.carts.updateLine(id, lineId, input));
|
|
238
|
+
removeLine = (lineId) => this.write((id) => this.client.carts.removeLine(id, lineId));
|
|
239
239
|
setCustomer = (input) => this.write((id) => this.client.carts.setCustomer(id, input));
|
|
240
240
|
setAddress = (input) => this.write((id) => this.client.carts.setAddress(id, input));
|
|
241
241
|
setShippingOption = (optionId) => this.write((id) => this.client.carts.setShippingOption(id, optionId));
|
|
@@ -413,22 +413,22 @@ var StorefrontContext = createContext(null);
|
|
|
413
413
|
function StorefrontProvider({
|
|
414
414
|
storeId,
|
|
415
415
|
client,
|
|
416
|
-
config,
|
|
416
|
+
config: config2,
|
|
417
417
|
cartStorage,
|
|
418
418
|
children
|
|
419
419
|
}) {
|
|
420
420
|
const forbidden = ["serverKey", "trustedStorefrontKey", "buyerIp"].filter(
|
|
421
|
-
(k) =>
|
|
421
|
+
(k) => config2 !== void 0 && k in config2
|
|
422
422
|
);
|
|
423
423
|
if (forbidden.length > 0) {
|
|
424
424
|
throw new Error(
|
|
425
425
|
`StorefrontProvider: config.${forbidden.join(", config.")} must not be passed to a client component (it would reach the browser). Create a server-side client instead.`
|
|
426
426
|
);
|
|
427
427
|
}
|
|
428
|
-
const baseUrl =
|
|
429
|
-
const publishableKey =
|
|
430
|
-
const timeoutMs =
|
|
431
|
-
const customFetch =
|
|
428
|
+
const baseUrl = config2?.baseUrl;
|
|
429
|
+
const publishableKey = config2?.publishableKey;
|
|
430
|
+
const timeoutMs = config2?.timeoutMs;
|
|
431
|
+
const customFetch = config2?.fetch;
|
|
432
432
|
const resolved = useMemo(() => {
|
|
433
433
|
if (client) return client;
|
|
434
434
|
if (baseUrl === void 0 || publishableKey === void 0) {
|
|
@@ -1094,23 +1094,819 @@ function Content({ contentKey, components }) {
|
|
|
1094
1094
|
if (!data) return null;
|
|
1095
1095
|
return /* @__PURE__ */ jsx4(Fragment, { children: renderContent(data.tree, components) });
|
|
1096
1096
|
}
|
|
1097
|
+
|
|
1098
|
+
// src/consent-provider.tsx
|
|
1099
|
+
import {
|
|
1100
|
+
createContext as createContext2,
|
|
1101
|
+
useCallback as useCallback5,
|
|
1102
|
+
useContext as useContext2,
|
|
1103
|
+
useEffect as useEffect10,
|
|
1104
|
+
useMemo as useMemo3,
|
|
1105
|
+
useRef as useRef6,
|
|
1106
|
+
useState as useState4,
|
|
1107
|
+
useSyncExternalStore as useSyncExternalStore3
|
|
1108
|
+
} from "react";
|
|
1109
|
+
|
|
1110
|
+
// src/consent.ts
|
|
1111
|
+
var COOKIE = "_consent";
|
|
1112
|
+
var MAX_AGE = 31536e3;
|
|
1113
|
+
var ID = /^[0-9a-f]{32}$/;
|
|
1114
|
+
var OPTIONAL_CATEGORIES = [
|
|
1115
|
+
"analytics",
|
|
1116
|
+
"marketing"
|
|
1117
|
+
];
|
|
1118
|
+
var currentVersion = "";
|
|
1119
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
1120
|
+
function configureConsent(version) {
|
|
1121
|
+
if (typeof window === "undefined") return;
|
|
1122
|
+
currentVersion = version;
|
|
1123
|
+
}
|
|
1124
|
+
function subscribeConsent(listener) {
|
|
1125
|
+
listeners.add(listener);
|
|
1126
|
+
return () => listeners.delete(listener);
|
|
1127
|
+
}
|
|
1128
|
+
function rawConsent() {
|
|
1129
|
+
try {
|
|
1130
|
+
for (const part of document.cookie.split(";")) {
|
|
1131
|
+
const eq = part.indexOf("=");
|
|
1132
|
+
if (eq < 0 || part.slice(0, eq).trim() !== COOKIE) continue;
|
|
1133
|
+
return part.slice(eq + 1).trim();
|
|
1134
|
+
}
|
|
1135
|
+
} catch {
|
|
1136
|
+
}
|
|
1137
|
+
return "";
|
|
1138
|
+
}
|
|
1139
|
+
function parse(raw) {
|
|
1140
|
+
const parts = raw.split(".");
|
|
1141
|
+
if (parts.length !== 3) return null;
|
|
1142
|
+
const [id, version, list] = parts;
|
|
1143
|
+
if (!ID.test(id)) return null;
|
|
1144
|
+
const items = list === "" ? [] : list.split(",");
|
|
1145
|
+
if (!items.every((c) => OPTIONAL_CATEGORIES.includes(c)))
|
|
1146
|
+
return null;
|
|
1147
|
+
return { id, version, granted: items };
|
|
1148
|
+
}
|
|
1149
|
+
function readConsent(version) {
|
|
1150
|
+
return consentFor(rawConsent(), version);
|
|
1151
|
+
}
|
|
1152
|
+
function consentFor(raw, version) {
|
|
1153
|
+
const parsed = parse(raw);
|
|
1154
|
+
if (!parsed || parsed.version !== version) return null;
|
|
1155
|
+
return { id: parsed.id, granted: parsed.granted };
|
|
1156
|
+
}
|
|
1157
|
+
function newConsentId() {
|
|
1158
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
1159
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1160
|
+
}
|
|
1161
|
+
function writeConsent(version, granted2) {
|
|
1162
|
+
const id = parse(rawConsent())?.id ?? newConsentId();
|
|
1163
|
+
const list = OPTIONAL_CATEGORIES.filter((c) => granted2.includes(c)).join(",");
|
|
1164
|
+
try {
|
|
1165
|
+
document.cookie = `${COOKIE}=${id}.${version}.${list}; Max-Age=${MAX_AGE}; Path=/; SameSite=Lax; Secure`;
|
|
1166
|
+
} catch {
|
|
1167
|
+
}
|
|
1168
|
+
for (const listener of listeners) listener();
|
|
1169
|
+
return id;
|
|
1170
|
+
}
|
|
1171
|
+
function analyticsConsent() {
|
|
1172
|
+
if (!currentVersion) return false;
|
|
1173
|
+
return readConsent(currentVersion)?.granted.includes("analytics") ?? false;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// src/consent-provider.tsx
|
|
1177
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1178
|
+
var noop = () => void 0;
|
|
1179
|
+
var ConsentContext = createContext2({
|
|
1180
|
+
needed: false,
|
|
1181
|
+
open: noop,
|
|
1182
|
+
cookies: [],
|
|
1183
|
+
categories: [],
|
|
1184
|
+
known: false,
|
|
1185
|
+
stored: null,
|
|
1186
|
+
showBar: false,
|
|
1187
|
+
panelOpen: false,
|
|
1188
|
+
close: noop,
|
|
1189
|
+
decide: noop
|
|
1190
|
+
});
|
|
1191
|
+
var serverSnapshot = () => void 0;
|
|
1192
|
+
function ConsentProvider({
|
|
1193
|
+
cookies,
|
|
1194
|
+
version,
|
|
1195
|
+
onDecision,
|
|
1196
|
+
children
|
|
1197
|
+
}) {
|
|
1198
|
+
configureConsent(version);
|
|
1199
|
+
const raw = useSyncExternalStore3(
|
|
1200
|
+
subscribeConsent,
|
|
1201
|
+
rawConsent,
|
|
1202
|
+
serverSnapshot
|
|
1203
|
+
);
|
|
1204
|
+
const [panelOpen, setPanelOpen] = useState4(false);
|
|
1205
|
+
const [decidedVersion, setDecidedVersion] = useState4(null);
|
|
1206
|
+
const opener = useRef6(null);
|
|
1207
|
+
const onDecisionRef = useRef6(onDecision);
|
|
1208
|
+
onDecisionRef.current = onDecision;
|
|
1209
|
+
const categories = useMemo3(
|
|
1210
|
+
() => OPTIONAL_CATEGORIES.filter((c) => cookies.some((k) => k.category === c)),
|
|
1211
|
+
[cookies]
|
|
1212
|
+
);
|
|
1213
|
+
const needed = categories.length > 0;
|
|
1214
|
+
const stored = useMemo3(
|
|
1215
|
+
() => raw === void 0 ? null : consentFor(raw, version),
|
|
1216
|
+
[raw, version]
|
|
1217
|
+
);
|
|
1218
|
+
const known = raw !== void 0;
|
|
1219
|
+
const showBar = needed && known && !stored && decidedVersion !== version;
|
|
1220
|
+
const restorePending = useRef6(false);
|
|
1221
|
+
useEffect10(() => {
|
|
1222
|
+
if (panelOpen || !restorePending.current) return;
|
|
1223
|
+
restorePending.current = false;
|
|
1224
|
+
const target = opener.current;
|
|
1225
|
+
opener.current = null;
|
|
1226
|
+
if (target?.isConnected) target.focus();
|
|
1227
|
+
else document.getElementById("main")?.focus({ preventScroll: true });
|
|
1228
|
+
}, [panelOpen, showBar]);
|
|
1229
|
+
const open = useCallback5((from) => {
|
|
1230
|
+
const active = from ?? document.activeElement;
|
|
1231
|
+
opener.current = active instanceof HTMLElement && active !== document.body ? active : null;
|
|
1232
|
+
setPanelOpen(true);
|
|
1233
|
+
}, []);
|
|
1234
|
+
const close = useCallback5(() => {
|
|
1235
|
+
if (panelOpen) restorePending.current = true;
|
|
1236
|
+
setPanelOpen(false);
|
|
1237
|
+
}, [panelOpen]);
|
|
1238
|
+
const decide = useCallback5(
|
|
1239
|
+
(granted2) => {
|
|
1240
|
+
const allowed = categories.filter((c) => granted2.includes(c));
|
|
1241
|
+
const consentId = writeConsent(version, allowed);
|
|
1242
|
+
try {
|
|
1243
|
+
onDecisionRef.current?.({ consentId, granted: allowed, version });
|
|
1244
|
+
} catch {
|
|
1245
|
+
}
|
|
1246
|
+
setDecidedVersion(version);
|
|
1247
|
+
if (!panelOpen) opener.current = null;
|
|
1248
|
+
restorePending.current = true;
|
|
1249
|
+
setPanelOpen(false);
|
|
1250
|
+
},
|
|
1251
|
+
[categories, version, panelOpen]
|
|
1252
|
+
);
|
|
1253
|
+
const value = useMemo3(
|
|
1254
|
+
() => ({
|
|
1255
|
+
needed,
|
|
1256
|
+
open,
|
|
1257
|
+
cookies,
|
|
1258
|
+
categories,
|
|
1259
|
+
stored,
|
|
1260
|
+
known,
|
|
1261
|
+
showBar,
|
|
1262
|
+
panelOpen,
|
|
1263
|
+
close,
|
|
1264
|
+
decide
|
|
1265
|
+
}),
|
|
1266
|
+
[
|
|
1267
|
+
needed,
|
|
1268
|
+
open,
|
|
1269
|
+
cookies,
|
|
1270
|
+
categories,
|
|
1271
|
+
stored,
|
|
1272
|
+
known,
|
|
1273
|
+
showBar,
|
|
1274
|
+
panelOpen,
|
|
1275
|
+
close,
|
|
1276
|
+
decide
|
|
1277
|
+
]
|
|
1278
|
+
);
|
|
1279
|
+
return /* @__PURE__ */ jsx5(ConsentContext.Provider, { value, children });
|
|
1280
|
+
}
|
|
1281
|
+
function useConsent() {
|
|
1282
|
+
return useContext2(ConsentContext);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// src/analytics.ts
|
|
1286
|
+
var QUERY_ALLOWLIST = [
|
|
1287
|
+
"utm_source",
|
|
1288
|
+
"utm_medium",
|
|
1289
|
+
"utm_campaign",
|
|
1290
|
+
"utm_content",
|
|
1291
|
+
"utm_term",
|
|
1292
|
+
"fbclid",
|
|
1293
|
+
"ttclid",
|
|
1294
|
+
"gclid",
|
|
1295
|
+
"gbraid",
|
|
1296
|
+
"wbraid"
|
|
1297
|
+
];
|
|
1298
|
+
var MAX_URL = 2e3;
|
|
1299
|
+
var MAX_BATCH = 20;
|
|
1300
|
+
function safePath() {
|
|
1301
|
+
const path = location.pathname;
|
|
1302
|
+
return path.startsWith("/orders/") ? "/orders/:id" : path;
|
|
1303
|
+
}
|
|
1304
|
+
function safeQuery() {
|
|
1305
|
+
const path = location.pathname;
|
|
1306
|
+
if (path.startsWith("/orders/") || path.startsWith("/cart/recover"))
|
|
1307
|
+
return "";
|
|
1308
|
+
const source = new URLSearchParams(location.search);
|
|
1309
|
+
const kept = new URLSearchParams();
|
|
1310
|
+
for (const [key, value] of source) {
|
|
1311
|
+
if (QUERY_ALLOWLIST.includes(key)) kept.append(key, value);
|
|
1312
|
+
}
|
|
1313
|
+
const query = kept.toString();
|
|
1314
|
+
return query ? `?${query}` : "";
|
|
1315
|
+
}
|
|
1316
|
+
function referrerOrigin() {
|
|
1317
|
+
try {
|
|
1318
|
+
return document.referrer ? new URL(document.referrer).origin : null;
|
|
1319
|
+
} catch {
|
|
1320
|
+
return null;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
var PREVIEW_KEY = "_preview";
|
|
1324
|
+
var config = null;
|
|
1325
|
+
var first = true;
|
|
1326
|
+
var landingChecked = false;
|
|
1327
|
+
var queue = [];
|
|
1328
|
+
var queuedViews = [];
|
|
1329
|
+
function configureAnalytics(next) {
|
|
1330
|
+
config = next;
|
|
1331
|
+
}
|
|
1332
|
+
function resetAnalytics() {
|
|
1333
|
+
config = null;
|
|
1334
|
+
first = true;
|
|
1335
|
+
landingChecked = false;
|
|
1336
|
+
queue = [];
|
|
1337
|
+
queuedViews = [];
|
|
1338
|
+
}
|
|
1339
|
+
function previewQuery() {
|
|
1340
|
+
return new URLSearchParams(location.search).get(PREVIEW_KEY) === "1";
|
|
1341
|
+
}
|
|
1342
|
+
function readLanding() {
|
|
1343
|
+
if (landingChecked) return;
|
|
1344
|
+
landingChecked = true;
|
|
1345
|
+
try {
|
|
1346
|
+
if (previewQuery()) sessionStorage.setItem(PREVIEW_KEY, "1");
|
|
1347
|
+
} catch {
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
function isPreview() {
|
|
1351
|
+
if (!landingChecked && previewQuery()) return true;
|
|
1352
|
+
try {
|
|
1353
|
+
return sessionStorage.getItem(PREVIEW_KEY) === "1";
|
|
1354
|
+
} catch {
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
function track(type, extra = {}) {
|
|
1359
|
+
try {
|
|
1360
|
+
if (!config) return;
|
|
1361
|
+
readLanding();
|
|
1362
|
+
if (isPreview()) return;
|
|
1363
|
+
if (type === "page_view") {
|
|
1364
|
+
const path = safePath();
|
|
1365
|
+
if (queuedViews.includes(path)) return;
|
|
1366
|
+
queuedViews.push(path);
|
|
1367
|
+
}
|
|
1368
|
+
const url = (first ? safePath() + safeQuery() : safePath()).slice(
|
|
1369
|
+
0,
|
|
1370
|
+
MAX_URL
|
|
1371
|
+
);
|
|
1372
|
+
const referrer = first ? referrerOrigin() : null;
|
|
1373
|
+
first = false;
|
|
1374
|
+
const { productId } = extra;
|
|
1375
|
+
if (queue.length === 0) queueMicrotask(flush);
|
|
1376
|
+
queue.push({ type, url, referrer, ...productId ? { productId } : {} });
|
|
1377
|
+
} catch {
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
function send(cfg, path, body) {
|
|
1381
|
+
void fetch(`${cfg.baseUrl}${path}`, {
|
|
1382
|
+
method: "POST",
|
|
1383
|
+
keepalive: true,
|
|
1384
|
+
headers: {
|
|
1385
|
+
"content-type": "application/json",
|
|
1386
|
+
"x-konfiqo-publishable-key": cfg.publishableKey
|
|
1387
|
+
},
|
|
1388
|
+
body: JSON.stringify(body)
|
|
1389
|
+
}).catch(() => void 0);
|
|
1390
|
+
}
|
|
1391
|
+
function flush() {
|
|
1392
|
+
try {
|
|
1393
|
+
const events = queue;
|
|
1394
|
+
queue = [];
|
|
1395
|
+
queuedViews = [];
|
|
1396
|
+
if (!config) return;
|
|
1397
|
+
const consent = { analytics: analyticsConsent() };
|
|
1398
|
+
for (let i = 0; i < events.length; i += MAX_BATCH) {
|
|
1399
|
+
send(config, "/v1/events", {
|
|
1400
|
+
events: events.slice(i, i + MAX_BATCH),
|
|
1401
|
+
consent
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
} catch {
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
function recordConsent(record) {
|
|
1408
|
+
try {
|
|
1409
|
+
if (!config || isPreview()) return;
|
|
1410
|
+
send(config, "/v1/consents", record);
|
|
1411
|
+
} catch {
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// src/analytics-tracker.tsx
|
|
1416
|
+
import { useEffect as useEffect11 } from "react";
|
|
1417
|
+
function AnalyticsTracker({
|
|
1418
|
+
baseUrl,
|
|
1419
|
+
publishableKey,
|
|
1420
|
+
pathname
|
|
1421
|
+
}) {
|
|
1422
|
+
configureAnalytics({ baseUrl, publishableKey });
|
|
1423
|
+
useEffect11(() => {
|
|
1424
|
+
track("page_view");
|
|
1425
|
+
}, [pathname]);
|
|
1426
|
+
return null;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// src/ad-pixels.ts
|
|
1430
|
+
function itemOf(e) {
|
|
1431
|
+
return e.variantId ? { id: e.variantId, type: "product" } : { id: e.productId, type: "product_group" };
|
|
1432
|
+
}
|
|
1433
|
+
var DEFAULT_CURRENCY = "TRY";
|
|
1434
|
+
var PURCHASE_KEY = "px_purchase_";
|
|
1435
|
+
var GRANT_MARKER_KEY = "px_granted";
|
|
1436
|
+
var win = () => window;
|
|
1437
|
+
var pixels;
|
|
1438
|
+
var currency = DEFAULT_CURRENCY;
|
|
1439
|
+
var granted = false;
|
|
1440
|
+
var loaded = /* @__PURE__ */ new Set();
|
|
1441
|
+
function resetPixels() {
|
|
1442
|
+
pixels = void 0;
|
|
1443
|
+
currency = DEFAULT_CURRENCY;
|
|
1444
|
+
granted = false;
|
|
1445
|
+
optedOut = false;
|
|
1446
|
+
loaded.clear();
|
|
1447
|
+
}
|
|
1448
|
+
var major = (minor) => minor / 100;
|
|
1449
|
+
function addScript(src) {
|
|
1450
|
+
const el = document.createElement("script");
|
|
1451
|
+
el.async = true;
|
|
1452
|
+
el.src = src;
|
|
1453
|
+
document.head.appendChild(el);
|
|
1454
|
+
}
|
|
1455
|
+
function loadMeta(id) {
|
|
1456
|
+
const w = win();
|
|
1457
|
+
if (!w.fbq) {
|
|
1458
|
+
const fbq = function(...args) {
|
|
1459
|
+
const f = fbq;
|
|
1460
|
+
if (f.callMethod) f.callMethod(...args);
|
|
1461
|
+
else f.queue.push(args);
|
|
1462
|
+
};
|
|
1463
|
+
Object.assign(fbq, {
|
|
1464
|
+
push: fbq,
|
|
1465
|
+
loaded: true,
|
|
1466
|
+
version: "2.0",
|
|
1467
|
+
queue: []
|
|
1468
|
+
});
|
|
1469
|
+
w.fbq = fbq;
|
|
1470
|
+
w._fbq = fbq;
|
|
1471
|
+
}
|
|
1472
|
+
w.fbq.disablePushState = true;
|
|
1473
|
+
addScript("https://connect.facebook.net/en_US/fbevents.js");
|
|
1474
|
+
w.fbq("init", id);
|
|
1475
|
+
}
|
|
1476
|
+
var TT_METHODS = [
|
|
1477
|
+
"page",
|
|
1478
|
+
"track",
|
|
1479
|
+
"identify",
|
|
1480
|
+
"instances",
|
|
1481
|
+
"debug",
|
|
1482
|
+
"on",
|
|
1483
|
+
"off",
|
|
1484
|
+
"once",
|
|
1485
|
+
"ready",
|
|
1486
|
+
"alias",
|
|
1487
|
+
"group",
|
|
1488
|
+
"enableCookie",
|
|
1489
|
+
"disableCookie",
|
|
1490
|
+
"holdConsent",
|
|
1491
|
+
"revokeConsent",
|
|
1492
|
+
"grantConsent"
|
|
1493
|
+
];
|
|
1494
|
+
function loadTikTok(id) {
|
|
1495
|
+
const w = win();
|
|
1496
|
+
w.TiktokAnalyticsObject = "ttq";
|
|
1497
|
+
const ttq = w.ttq = w.ttq ?? [];
|
|
1498
|
+
ttq.methods = TT_METHODS;
|
|
1499
|
+
ttq.setAndDefer = (t, m) => {
|
|
1500
|
+
t[m] = (...args) => {
|
|
1501
|
+
t.push([m, ...args]);
|
|
1502
|
+
};
|
|
1503
|
+
};
|
|
1504
|
+
for (const m of ttq.methods) ttq.setAndDefer(ttq, m);
|
|
1505
|
+
ttq.instance = (name) => {
|
|
1506
|
+
const inst = ttq._i[name] ?? [];
|
|
1507
|
+
for (const m of ttq.methods) ttq.setAndDefer(inst, m);
|
|
1508
|
+
return inst;
|
|
1509
|
+
};
|
|
1510
|
+
ttq.load = (name, opts) => {
|
|
1511
|
+
const src = "https://analytics.tiktok.com/i18n/pixel/events.js";
|
|
1512
|
+
ttq._i = ttq._i ?? {};
|
|
1513
|
+
ttq._i[name] = [];
|
|
1514
|
+
ttq._i[name]._u = src;
|
|
1515
|
+
ttq._t = ttq._t ?? {};
|
|
1516
|
+
ttq._t[name] = Date.now();
|
|
1517
|
+
ttq._o = ttq._o ?? {};
|
|
1518
|
+
ttq._o[name] = opts ?? {};
|
|
1519
|
+
addScript(`${src}?sdkid=${encodeURIComponent(name)}&lib=ttq`);
|
|
1520
|
+
};
|
|
1521
|
+
ttq.load(id);
|
|
1522
|
+
}
|
|
1523
|
+
function loadGoogle(g) {
|
|
1524
|
+
const w = win();
|
|
1525
|
+
const ids = [g.ga4Id, g.adsId].filter((v) => !!v);
|
|
1526
|
+
if (ids.length === 0) return;
|
|
1527
|
+
w.dataLayer = w.dataLayer ?? [];
|
|
1528
|
+
if (!w.gtag) {
|
|
1529
|
+
w.gtag = function() {
|
|
1530
|
+
w.dataLayer.push(arguments);
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
addScript(
|
|
1534
|
+
`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(ids[0])}`
|
|
1535
|
+
);
|
|
1536
|
+
w.gtag("js", /* @__PURE__ */ new Date());
|
|
1537
|
+
const cookieDomain = location.hostname;
|
|
1538
|
+
w.gtag("set", { cookie_domain: cookieDomain });
|
|
1539
|
+
for (const id of ids) {
|
|
1540
|
+
w.gtag("config", id, {
|
|
1541
|
+
send_page_view: false,
|
|
1542
|
+
cookie_domain: cookieDomain
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
function onSecretPage(path = typeof location === "undefined" ? "" : location.pathname) {
|
|
1547
|
+
return path.startsWith("/orders/") || path.startsWith("/cart/recover");
|
|
1548
|
+
}
|
|
1549
|
+
function loadAll(p) {
|
|
1550
|
+
if (p.meta && !loaded.has("meta")) {
|
|
1551
|
+
loaded.add("meta");
|
|
1552
|
+
loadMeta(p.meta.pixelId);
|
|
1553
|
+
}
|
|
1554
|
+
if (p.tiktok && !loaded.has("tiktok")) {
|
|
1555
|
+
loaded.add("tiktok");
|
|
1556
|
+
loadTikTok(p.tiktok.pixelId);
|
|
1557
|
+
}
|
|
1558
|
+
if (p.google && !loaded.has("google")) {
|
|
1559
|
+
loaded.add("google");
|
|
1560
|
+
loadGoogle(p.google);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
var PLATFORM_COOKIES = {
|
|
1564
|
+
meta: { names: ["_fbp", "_fbc"], prefixes: [] },
|
|
1565
|
+
tiktok: {
|
|
1566
|
+
names: ["_ttp", "_tt_enable_cookie", "ttcsid"],
|
|
1567
|
+
prefixes: ["ttcsid_"]
|
|
1568
|
+
},
|
|
1569
|
+
google: { names: ["_ga", "_gcl_au", "_gcl_aw"], prefixes: ["_ga_"] }
|
|
1570
|
+
};
|
|
1571
|
+
function platformsOf(p) {
|
|
1572
|
+
return ["meta", "tiktok", "google"].filter((k) => !!p[k]);
|
|
1573
|
+
}
|
|
1574
|
+
function readMarker() {
|
|
1575
|
+
try {
|
|
1576
|
+
return localStorage.getItem(GRANT_MARKER_KEY) !== null;
|
|
1577
|
+
} catch {
|
|
1578
|
+
return false;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function writeMarker(on) {
|
|
1582
|
+
try {
|
|
1583
|
+
if (on) localStorage.setItem(GRANT_MARKER_KEY, "1");
|
|
1584
|
+
else localStorage.removeItem(GRANT_MARKER_KEY);
|
|
1585
|
+
} catch {
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
var PROBE = "_px_probe";
|
|
1589
|
+
function registrableDomain(host) {
|
|
1590
|
+
const parts = host.split(".");
|
|
1591
|
+
for (let i = parts.length - 2; i > 0; i--) {
|
|
1592
|
+
const candidate = parts.slice(i).join(".");
|
|
1593
|
+
document.cookie = `${PROBE}=1; Path=/; Domain=${candidate}`;
|
|
1594
|
+
if (document.cookie.split(";").some((c) => c.trim() === `${PROBE}=1`)) {
|
|
1595
|
+
document.cookie = `${PROBE}=; Max-Age=0; Path=/; Domain=${candidate}`;
|
|
1596
|
+
return candidate;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
return host;
|
|
1600
|
+
}
|
|
1601
|
+
function clearCookies(p, onlyHost) {
|
|
1602
|
+
try {
|
|
1603
|
+
const spec = platformsOf(p).map((k) => PLATFORM_COOKIES[k]);
|
|
1604
|
+
const present = document.cookie.split(";").map((c) => c.split("=")[0].trim()).filter(Boolean);
|
|
1605
|
+
const names = present.filter(
|
|
1606
|
+
(n) => spec.some(
|
|
1607
|
+
(s) => s.names.includes(n) || s.prefixes.some((x) => n.startsWith(x))
|
|
1608
|
+
)
|
|
1609
|
+
);
|
|
1610
|
+
if (names.length === 0) return;
|
|
1611
|
+
const host = location.hostname;
|
|
1612
|
+
const domains = [void 0, host];
|
|
1613
|
+
if (!onlyHost && !/^[\d.]+$/.test(host) && !host.includes(":")) {
|
|
1614
|
+
const site = registrableDomain(host);
|
|
1615
|
+
if (site !== host) domains.push(site);
|
|
1616
|
+
}
|
|
1617
|
+
for (const name of names) {
|
|
1618
|
+
for (const domain of domains) {
|
|
1619
|
+
document.cookie = `${name}=; Max-Age=0; Path=/${domain ? `; Domain=${domain}` : ""}`;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
} catch {
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
var optedOut = false;
|
|
1626
|
+
var GOOGLE_CONSENT = (v) => ({
|
|
1627
|
+
ad_storage: v,
|
|
1628
|
+
analytics_storage: v,
|
|
1629
|
+
ad_user_data: v,
|
|
1630
|
+
ad_personalization: v
|
|
1631
|
+
});
|
|
1632
|
+
function googleIds(g) {
|
|
1633
|
+
return [g?.ga4Id, g?.adsId].filter((v) => !!v);
|
|
1634
|
+
}
|
|
1635
|
+
function optOut(p) {
|
|
1636
|
+
optedOut = true;
|
|
1637
|
+
const w = win();
|
|
1638
|
+
for (const id of googleIds(p.google)) w[`ga-disable-${id}`] = true;
|
|
1639
|
+
if (loaded.has("google") && typeof w.gtag === "function") {
|
|
1640
|
+
w.gtag("consent", "update", GOOGLE_CONSENT("denied"));
|
|
1641
|
+
}
|
|
1642
|
+
if (loaded.has("meta") && typeof w.fbq === "function") {
|
|
1643
|
+
w.fbq("consent", "revoke");
|
|
1644
|
+
}
|
|
1645
|
+
const ttq = w.ttq;
|
|
1646
|
+
if (loaded.has("tiktok") && typeof ttq?.disableCookie === "function") {
|
|
1647
|
+
ttq.disableCookie();
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
function optIn(p) {
|
|
1651
|
+
optedOut = false;
|
|
1652
|
+
const w = win();
|
|
1653
|
+
for (const id of googleIds(p.google)) w[`ga-disable-${id}`] = false;
|
|
1654
|
+
if (loaded.has("google") && typeof w.gtag === "function") {
|
|
1655
|
+
w.gtag("consent", "update", GOOGLE_CONSENT("granted"));
|
|
1656
|
+
}
|
|
1657
|
+
if (loaded.has("meta") && typeof w.fbq === "function") {
|
|
1658
|
+
w.fbq("consent", "grant");
|
|
1659
|
+
}
|
|
1660
|
+
const ttq = w.ttq;
|
|
1661
|
+
if (loaded.has("tiktok") && typeof ttq?.enableCookie === "function") {
|
|
1662
|
+
ttq.enableCookie();
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
function configurePixels(next, isGranted, opts = {}) {
|
|
1666
|
+
try {
|
|
1667
|
+
pixels = next;
|
|
1668
|
+
currency = opts.currency ?? DEFAULT_CURRENCY;
|
|
1669
|
+
const was = granted;
|
|
1670
|
+
granted = isGranted && !!next;
|
|
1671
|
+
if (granted && next) {
|
|
1672
|
+
if (optedOut) optIn(next);
|
|
1673
|
+
if (!onSecretPage()) loadAll(next);
|
|
1674
|
+
if (platformsOf(next).length > 0) writeMarker(true);
|
|
1675
|
+
} else if (next) {
|
|
1676
|
+
if (was) optOut(next);
|
|
1677
|
+
if (was || readMarker()) {
|
|
1678
|
+
clearCookies(next, opts.hostOnly ?? false);
|
|
1679
|
+
writeMarker(false);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
} catch {
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
function purchased(orderId) {
|
|
1686
|
+
try {
|
|
1687
|
+
return localStorage.getItem(PURCHASE_KEY + orderId) !== null;
|
|
1688
|
+
} catch {
|
|
1689
|
+
return false;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
function markPurchased(orderId) {
|
|
1693
|
+
try {
|
|
1694
|
+
localStorage.setItem(PURCHASE_KEY + orderId, "1");
|
|
1695
|
+
} catch {
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
function firePixel(e) {
|
|
1699
|
+
try {
|
|
1700
|
+
if (!granted || !pixels || onSecretPage()) return;
|
|
1701
|
+
loadAll(pixels);
|
|
1702
|
+
if (e.name === "purchase") {
|
|
1703
|
+
if (purchased(e.orderId)) return;
|
|
1704
|
+
markPurchased(e.orderId);
|
|
1705
|
+
}
|
|
1706
|
+
const w = win();
|
|
1707
|
+
if (pixels.meta && w.fbq) meta(w.fbq, e);
|
|
1708
|
+
if (pixels.tiktok && w.ttq) tiktok(w.ttq, e);
|
|
1709
|
+
if (pixels.google && w.gtag) google(w.gtag, pixels.google, e);
|
|
1710
|
+
} catch {
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
function meta(fbq, e) {
|
|
1714
|
+
switch (e.name) {
|
|
1715
|
+
case "page_view":
|
|
1716
|
+
fbq("track", "PageView");
|
|
1717
|
+
return;
|
|
1718
|
+
case "view_item": {
|
|
1719
|
+
const it = itemOf(e);
|
|
1720
|
+
fbq("track", "ViewContent", {
|
|
1721
|
+
content_ids: [it.id],
|
|
1722
|
+
content_type: it.type,
|
|
1723
|
+
value: major(e.priceMinor),
|
|
1724
|
+
currency
|
|
1725
|
+
});
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
case "add_to_cart":
|
|
1729
|
+
fbq("track", "AddToCart", {
|
|
1730
|
+
content_ids: [e.variantId],
|
|
1731
|
+
content_type: "product",
|
|
1732
|
+
contents: [
|
|
1733
|
+
{
|
|
1734
|
+
id: e.variantId,
|
|
1735
|
+
quantity: e.quantity,
|
|
1736
|
+
item_price: major(e.priceMinor)
|
|
1737
|
+
}
|
|
1738
|
+
],
|
|
1739
|
+
value: major(e.priceMinor * e.quantity),
|
|
1740
|
+
currency
|
|
1741
|
+
});
|
|
1742
|
+
return;
|
|
1743
|
+
case "begin_checkout":
|
|
1744
|
+
fbq("track", "InitiateCheckout", {
|
|
1745
|
+
value: major(e.valueMinor),
|
|
1746
|
+
currency
|
|
1747
|
+
});
|
|
1748
|
+
return;
|
|
1749
|
+
case "purchase":
|
|
1750
|
+
fbq(
|
|
1751
|
+
"track",
|
|
1752
|
+
"Purchase",
|
|
1753
|
+
{
|
|
1754
|
+
content_ids: e.items.map((i) => i.id),
|
|
1755
|
+
content_type: "product",
|
|
1756
|
+
contents: e.items.map((i) => ({
|
|
1757
|
+
id: i.id,
|
|
1758
|
+
quantity: i.quantity,
|
|
1759
|
+
item_price: major(i.priceMinor)
|
|
1760
|
+
})),
|
|
1761
|
+
value: major(e.valueMinor),
|
|
1762
|
+
currency
|
|
1763
|
+
},
|
|
1764
|
+
{ eventID: e.orderId }
|
|
1765
|
+
);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
function tiktok(ttq, e) {
|
|
1769
|
+
const content = (id, quantity, priceMinor, type = "product") => ({
|
|
1770
|
+
content_id: id,
|
|
1771
|
+
content_type: type,
|
|
1772
|
+
quantity,
|
|
1773
|
+
price: major(priceMinor)
|
|
1774
|
+
});
|
|
1775
|
+
switch (e.name) {
|
|
1776
|
+
case "page_view":
|
|
1777
|
+
ttq.page();
|
|
1778
|
+
return;
|
|
1779
|
+
case "view_item": {
|
|
1780
|
+
const it = itemOf(e);
|
|
1781
|
+
ttq.track("ViewContent", {
|
|
1782
|
+
contents: [content(it.id, 1, e.priceMinor, it.type)],
|
|
1783
|
+
value: major(e.priceMinor),
|
|
1784
|
+
currency
|
|
1785
|
+
});
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
case "add_to_cart":
|
|
1789
|
+
ttq.track("AddToCart", {
|
|
1790
|
+
contents: [content(e.variantId, e.quantity, e.priceMinor)],
|
|
1791
|
+
value: major(e.priceMinor * e.quantity),
|
|
1792
|
+
currency
|
|
1793
|
+
});
|
|
1794
|
+
return;
|
|
1795
|
+
case "begin_checkout":
|
|
1796
|
+
ttq.track("InitiateCheckout", {
|
|
1797
|
+
value: major(e.valueMinor),
|
|
1798
|
+
currency
|
|
1799
|
+
});
|
|
1800
|
+
return;
|
|
1801
|
+
case "purchase":
|
|
1802
|
+
ttq.track(
|
|
1803
|
+
"CompletePayment",
|
|
1804
|
+
{
|
|
1805
|
+
contents: e.items.map((i) => content(i.id, i.quantity, i.priceMinor)),
|
|
1806
|
+
value: major(e.valueMinor),
|
|
1807
|
+
currency
|
|
1808
|
+
},
|
|
1809
|
+
{ event_id: e.orderId }
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
function google(gtag, g, e) {
|
|
1814
|
+
const item = (id, quantity, priceMinor) => ({
|
|
1815
|
+
item_id: id,
|
|
1816
|
+
quantity,
|
|
1817
|
+
price: major(priceMinor)
|
|
1818
|
+
});
|
|
1819
|
+
switch (e.name) {
|
|
1820
|
+
case "page_view":
|
|
1821
|
+
gtag("event", "page_view");
|
|
1822
|
+
return;
|
|
1823
|
+
case "view_item":
|
|
1824
|
+
gtag("event", "view_item", {
|
|
1825
|
+
currency,
|
|
1826
|
+
value: major(e.priceMinor),
|
|
1827
|
+
items: [item(itemOf(e).id, 1, e.priceMinor)]
|
|
1828
|
+
});
|
|
1829
|
+
return;
|
|
1830
|
+
case "add_to_cart":
|
|
1831
|
+
gtag("event", "add_to_cart", {
|
|
1832
|
+
currency,
|
|
1833
|
+
value: major(e.priceMinor * e.quantity),
|
|
1834
|
+
items: [item(e.variantId, e.quantity, e.priceMinor)]
|
|
1835
|
+
});
|
|
1836
|
+
return;
|
|
1837
|
+
case "begin_checkout":
|
|
1838
|
+
gtag("event", "begin_checkout", {
|
|
1839
|
+
currency,
|
|
1840
|
+
value: major(e.valueMinor)
|
|
1841
|
+
});
|
|
1842
|
+
return;
|
|
1843
|
+
case "purchase":
|
|
1844
|
+
gtag("event", "purchase", {
|
|
1845
|
+
transaction_id: e.orderId,
|
|
1846
|
+
currency,
|
|
1847
|
+
value: major(e.valueMinor),
|
|
1848
|
+
items: e.items.map((i) => item(i.id, i.quantity, i.priceMinor))
|
|
1849
|
+
});
|
|
1850
|
+
if (g.adsId && g.adsConversionLabel) {
|
|
1851
|
+
gtag("event", "conversion", {
|
|
1852
|
+
send_to: `${g.adsId}/${g.adsConversionLabel}`,
|
|
1853
|
+
value: major(e.valueMinor),
|
|
1854
|
+
currency,
|
|
1855
|
+
transaction_id: e.orderId
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// src/ad-pixels-loader.tsx
|
|
1862
|
+
import { useEffect as useEffect12 } from "react";
|
|
1863
|
+
function AdPixelsLoader({
|
|
1864
|
+
pixels: pixels2,
|
|
1865
|
+
hostOnly = false,
|
|
1866
|
+
currency: currency2 = "TRY",
|
|
1867
|
+
pathname
|
|
1868
|
+
}) {
|
|
1869
|
+
const { stored, known } = useConsent();
|
|
1870
|
+
const granted2 = stored?.granted.includes("marketing") ?? false;
|
|
1871
|
+
useEffect12(() => {
|
|
1872
|
+
if (!known) return;
|
|
1873
|
+
configurePixels(pixels2, granted2, { hostOnly, currency: currency2 });
|
|
1874
|
+
}, [pixels2, granted2, known, hostOnly, currency2]);
|
|
1875
|
+
useEffect12(() => {
|
|
1876
|
+
if (granted2) firePixel({ name: "page_view" });
|
|
1877
|
+
}, [granted2, pathname]);
|
|
1878
|
+
return null;
|
|
1879
|
+
}
|
|
1097
1880
|
export {
|
|
1881
|
+
AdPixelsLoader,
|
|
1882
|
+
AnalyticsTracker,
|
|
1098
1883
|
CheckoutChallenge,
|
|
1884
|
+
ConsentProvider,
|
|
1099
1885
|
Content,
|
|
1886
|
+
OPTIONAL_CATEGORIES,
|
|
1100
1887
|
ORDER_POLL_MAX_MS,
|
|
1101
1888
|
ORDER_POLL_MIN_MS,
|
|
1102
1889
|
PaymentForm,
|
|
1103
1890
|
StorefrontProvider,
|
|
1891
|
+
configureAnalytics,
|
|
1892
|
+
configurePixels,
|
|
1104
1893
|
defaultCartStorage,
|
|
1894
|
+
firePixel,
|
|
1105
1895
|
isDeadCartError,
|
|
1106
1896
|
isOrderSettled,
|
|
1897
|
+
onSecretPage,
|
|
1107
1898
|
orderPollDelay,
|
|
1899
|
+
recordConsent,
|
|
1108
1900
|
renderContent,
|
|
1901
|
+
resetAnalytics,
|
|
1902
|
+
resetPixels,
|
|
1903
|
+
track,
|
|
1109
1904
|
useAccount,
|
|
1110
1905
|
useCart,
|
|
1111
1906
|
useCartStorage,
|
|
1112
1907
|
useCategories,
|
|
1113
1908
|
useCheckout,
|
|
1909
|
+
useConsent,
|
|
1114
1910
|
useOrder,
|
|
1115
1911
|
useProduct,
|
|
1116
1912
|
useProducts,
|