@konfiqo/storefront-react 0.5.0 → 0.6.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/dist/index.js CHANGED
@@ -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) => config !== void 0 && k in config
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 = config?.baseUrl;
429
- const publishableKey = config?.publishableKey;
430
- const timeoutMs = config?.timeoutMs;
431
- const customFetch = config?.fetch;
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,836 @@ 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
+ var configured = false;
1442
+ var MAX_EARLY = 20;
1443
+ var early = [];
1444
+ function resetPixels() {
1445
+ pixels = void 0;
1446
+ currency = DEFAULT_CURRENCY;
1447
+ granted = false;
1448
+ optedOut = false;
1449
+ loaded.clear();
1450
+ configured = false;
1451
+ early.length = 0;
1452
+ }
1453
+ var major = (minor) => minor / 100;
1454
+ function addScript(src) {
1455
+ const el = document.createElement("script");
1456
+ el.async = true;
1457
+ el.src = src;
1458
+ document.head.appendChild(el);
1459
+ }
1460
+ function loadMeta(id) {
1461
+ const w = win();
1462
+ if (!w.fbq) {
1463
+ const fbq = function(...args) {
1464
+ const f = fbq;
1465
+ if (f.callMethod) f.callMethod(...args);
1466
+ else f.queue.push(args);
1467
+ };
1468
+ Object.assign(fbq, {
1469
+ push: fbq,
1470
+ loaded: true,
1471
+ version: "2.0",
1472
+ queue: []
1473
+ });
1474
+ w.fbq = fbq;
1475
+ w._fbq = fbq;
1476
+ }
1477
+ w.fbq.disablePushState = true;
1478
+ addScript("https://connect.facebook.net/en_US/fbevents.js");
1479
+ w.fbq("init", id);
1480
+ }
1481
+ var TT_METHODS = [
1482
+ "page",
1483
+ "track",
1484
+ "identify",
1485
+ "instances",
1486
+ "debug",
1487
+ "on",
1488
+ "off",
1489
+ "once",
1490
+ "ready",
1491
+ "alias",
1492
+ "group",
1493
+ "enableCookie",
1494
+ "disableCookie",
1495
+ "holdConsent",
1496
+ "revokeConsent",
1497
+ "grantConsent"
1498
+ ];
1499
+ function loadTikTok(id) {
1500
+ const w = win();
1501
+ w.TiktokAnalyticsObject = "ttq";
1502
+ const ttq = w.ttq = w.ttq ?? [];
1503
+ ttq.methods = TT_METHODS;
1504
+ ttq.setAndDefer = (t, m) => {
1505
+ t[m] = (...args) => {
1506
+ t.push([m, ...args]);
1507
+ };
1508
+ };
1509
+ for (const m of ttq.methods) ttq.setAndDefer(ttq, m);
1510
+ ttq.instance = (name) => {
1511
+ const inst = ttq._i[name] ?? [];
1512
+ for (const m of ttq.methods) ttq.setAndDefer(inst, m);
1513
+ return inst;
1514
+ };
1515
+ ttq.load = (name, opts) => {
1516
+ const src = "https://analytics.tiktok.com/i18n/pixel/events.js";
1517
+ ttq._i = ttq._i ?? {};
1518
+ ttq._i[name] = [];
1519
+ ttq._i[name]._u = src;
1520
+ ttq._t = ttq._t ?? {};
1521
+ ttq._t[name] = Date.now();
1522
+ ttq._o = ttq._o ?? {};
1523
+ ttq._o[name] = opts ?? {};
1524
+ addScript(`${src}?sdkid=${encodeURIComponent(name)}&lib=ttq`);
1525
+ };
1526
+ ttq.load(id);
1527
+ }
1528
+ function loadGoogle(g) {
1529
+ const w = win();
1530
+ const ids = [g.ga4Id, g.adsId].filter((v) => !!v);
1531
+ if (ids.length === 0) return;
1532
+ w.dataLayer = w.dataLayer ?? [];
1533
+ if (!w.gtag) {
1534
+ w.gtag = function() {
1535
+ w.dataLayer.push(arguments);
1536
+ };
1537
+ }
1538
+ addScript(
1539
+ `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(ids[0])}`
1540
+ );
1541
+ w.gtag("js", /* @__PURE__ */ new Date());
1542
+ const cookieDomain = location.hostname;
1543
+ w.gtag("set", { cookie_domain: cookieDomain });
1544
+ for (const id of ids) {
1545
+ w.gtag("config", id, {
1546
+ send_page_view: false,
1547
+ cookie_domain: cookieDomain
1548
+ });
1549
+ }
1550
+ }
1551
+ function onSecretPage(path = typeof location === "undefined" ? "" : location.pathname) {
1552
+ return path.startsWith("/orders/") || path.startsWith("/cart/recover");
1553
+ }
1554
+ function loadAll(p) {
1555
+ if (p.meta && !loaded.has("meta")) {
1556
+ loaded.add("meta");
1557
+ loadMeta(p.meta.pixelId);
1558
+ }
1559
+ if (p.tiktok && !loaded.has("tiktok")) {
1560
+ loaded.add("tiktok");
1561
+ loadTikTok(p.tiktok.pixelId);
1562
+ }
1563
+ if (p.google && !loaded.has("google")) {
1564
+ loaded.add("google");
1565
+ loadGoogle(p.google);
1566
+ }
1567
+ }
1568
+ var PLATFORM_COOKIES = {
1569
+ meta: { names: ["_fbp", "_fbc"], prefixes: [] },
1570
+ tiktok: {
1571
+ names: ["_ttp", "_tt_enable_cookie", "ttcsid"],
1572
+ prefixes: ["ttcsid_"]
1573
+ },
1574
+ google: { names: ["_ga", "_gcl_au", "_gcl_aw"], prefixes: ["_ga_"] }
1575
+ };
1576
+ function platformsOf(p) {
1577
+ return ["meta", "tiktok", "google"].filter((k) => !!p[k]);
1578
+ }
1579
+ function readMarker() {
1580
+ try {
1581
+ return localStorage.getItem(GRANT_MARKER_KEY) !== null;
1582
+ } catch {
1583
+ return false;
1584
+ }
1585
+ }
1586
+ function writeMarker(on) {
1587
+ try {
1588
+ if (on) localStorage.setItem(GRANT_MARKER_KEY, "1");
1589
+ else localStorage.removeItem(GRANT_MARKER_KEY);
1590
+ } catch {
1591
+ }
1592
+ }
1593
+ var PROBE = "_px_probe";
1594
+ function registrableDomain(host) {
1595
+ const parts = host.split(".");
1596
+ for (let i = parts.length - 2; i > 0; i--) {
1597
+ const candidate = parts.slice(i).join(".");
1598
+ document.cookie = `${PROBE}=1; Path=/; Domain=${candidate}`;
1599
+ if (document.cookie.split(";").some((c) => c.trim() === `${PROBE}=1`)) {
1600
+ document.cookie = `${PROBE}=; Max-Age=0; Path=/; Domain=${candidate}`;
1601
+ return candidate;
1602
+ }
1603
+ }
1604
+ return host;
1605
+ }
1606
+ function clearCookies(p, onlyHost) {
1607
+ try {
1608
+ const spec = platformsOf(p).map((k) => PLATFORM_COOKIES[k]);
1609
+ const present = document.cookie.split(";").map((c) => c.split("=")[0].trim()).filter(Boolean);
1610
+ const names = present.filter(
1611
+ (n) => spec.some(
1612
+ (s) => s.names.includes(n) || s.prefixes.some((x) => n.startsWith(x))
1613
+ )
1614
+ );
1615
+ if (names.length === 0) return;
1616
+ const host = location.hostname;
1617
+ const domains = [void 0, host];
1618
+ if (!onlyHost && !/^[\d.]+$/.test(host) && !host.includes(":")) {
1619
+ const site = registrableDomain(host);
1620
+ if (site !== host) domains.push(site);
1621
+ }
1622
+ for (const name of names) {
1623
+ for (const domain of domains) {
1624
+ document.cookie = `${name}=; Max-Age=0; Path=/${domain ? `; Domain=${domain}` : ""}`;
1625
+ }
1626
+ }
1627
+ } catch {
1628
+ }
1629
+ }
1630
+ var optedOut = false;
1631
+ var GOOGLE_CONSENT = (v) => ({
1632
+ ad_storage: v,
1633
+ analytics_storage: v,
1634
+ ad_user_data: v,
1635
+ ad_personalization: v
1636
+ });
1637
+ function googleIds(g) {
1638
+ return [g?.ga4Id, g?.adsId].filter((v) => !!v);
1639
+ }
1640
+ function optOut(p) {
1641
+ optedOut = true;
1642
+ const w = win();
1643
+ for (const id of googleIds(p.google)) w[`ga-disable-${id}`] = true;
1644
+ if (loaded.has("google") && typeof w.gtag === "function") {
1645
+ w.gtag("consent", "update", GOOGLE_CONSENT("denied"));
1646
+ }
1647
+ if (loaded.has("meta") && typeof w.fbq === "function") {
1648
+ w.fbq("consent", "revoke");
1649
+ }
1650
+ const ttq = w.ttq;
1651
+ if (loaded.has("tiktok") && typeof ttq?.disableCookie === "function") {
1652
+ ttq.disableCookie();
1653
+ }
1654
+ }
1655
+ function optIn(p) {
1656
+ optedOut = false;
1657
+ const w = win();
1658
+ for (const id of googleIds(p.google)) w[`ga-disable-${id}`] = false;
1659
+ if (loaded.has("google") && typeof w.gtag === "function") {
1660
+ w.gtag("consent", "update", GOOGLE_CONSENT("granted"));
1661
+ }
1662
+ if (loaded.has("meta") && typeof w.fbq === "function") {
1663
+ w.fbq("consent", "grant");
1664
+ }
1665
+ const ttq = w.ttq;
1666
+ if (loaded.has("tiktok") && typeof ttq?.enableCookie === "function") {
1667
+ ttq.enableCookie();
1668
+ }
1669
+ }
1670
+ function configurePixels(next, isGranted, opts = {}) {
1671
+ const held = configured ? [] : early.splice(0);
1672
+ configured = true;
1673
+ try {
1674
+ pixels = next;
1675
+ currency = opts.currency ?? DEFAULT_CURRENCY;
1676
+ const was = granted;
1677
+ granted = isGranted && !!next;
1678
+ if (granted && next) {
1679
+ if (optedOut) optIn(next);
1680
+ if (!onSecretPage()) loadAll(next);
1681
+ if (platformsOf(next).length > 0) writeMarker(true);
1682
+ } else if (next) {
1683
+ if (was) optOut(next);
1684
+ if (was || readMarker()) {
1685
+ clearCookies(next, opts.hostOnly ?? false);
1686
+ writeMarker(false);
1687
+ }
1688
+ }
1689
+ for (const e of held) send2(e);
1690
+ } catch {
1691
+ }
1692
+ }
1693
+ function purchased(orderId) {
1694
+ try {
1695
+ return localStorage.getItem(PURCHASE_KEY + orderId) !== null;
1696
+ } catch {
1697
+ return false;
1698
+ }
1699
+ }
1700
+ function markPurchased(orderId) {
1701
+ try {
1702
+ localStorage.setItem(PURCHASE_KEY + orderId, "1");
1703
+ } catch {
1704
+ }
1705
+ }
1706
+ function firePixel(e) {
1707
+ if (!configured) {
1708
+ if (typeof window === "undefined" || onSecretPage()) return;
1709
+ early.push(e);
1710
+ if (early.length > MAX_EARLY) early.shift();
1711
+ return;
1712
+ }
1713
+ send2(e);
1714
+ }
1715
+ function send2(e) {
1716
+ try {
1717
+ if (!granted || !pixels || onSecretPage()) return;
1718
+ loadAll(pixels);
1719
+ if (e.name === "purchase") {
1720
+ if (purchased(e.orderId)) return;
1721
+ markPurchased(e.orderId);
1722
+ }
1723
+ const w = win();
1724
+ if (pixels.meta && w.fbq) meta(w.fbq, e);
1725
+ if (pixels.tiktok && w.ttq) tiktok(w.ttq, e);
1726
+ if (pixels.google && w.gtag) google(w.gtag, pixels.google, e);
1727
+ } catch {
1728
+ }
1729
+ }
1730
+ function meta(fbq, e) {
1731
+ switch (e.name) {
1732
+ case "page_view":
1733
+ fbq("track", "PageView");
1734
+ return;
1735
+ case "view_item": {
1736
+ const it = itemOf(e);
1737
+ fbq("track", "ViewContent", {
1738
+ content_ids: [it.id],
1739
+ content_type: it.type,
1740
+ value: major(e.priceMinor),
1741
+ currency
1742
+ });
1743
+ return;
1744
+ }
1745
+ case "add_to_cart":
1746
+ fbq("track", "AddToCart", {
1747
+ content_ids: [e.variantId],
1748
+ content_type: "product",
1749
+ contents: [
1750
+ {
1751
+ id: e.variantId,
1752
+ quantity: e.quantity,
1753
+ item_price: major(e.priceMinor)
1754
+ }
1755
+ ],
1756
+ value: major(e.priceMinor * e.quantity),
1757
+ currency
1758
+ });
1759
+ return;
1760
+ case "begin_checkout":
1761
+ fbq("track", "InitiateCheckout", {
1762
+ value: major(e.valueMinor),
1763
+ currency
1764
+ });
1765
+ return;
1766
+ case "purchase":
1767
+ fbq(
1768
+ "track",
1769
+ "Purchase",
1770
+ {
1771
+ content_ids: e.items.map((i) => i.id),
1772
+ content_type: "product",
1773
+ contents: e.items.map((i) => ({
1774
+ id: i.id,
1775
+ quantity: i.quantity,
1776
+ item_price: major(i.priceMinor)
1777
+ })),
1778
+ value: major(e.valueMinor),
1779
+ currency
1780
+ },
1781
+ { eventID: e.orderId }
1782
+ );
1783
+ }
1784
+ }
1785
+ function tiktok(ttq, e) {
1786
+ const content = (id, quantity, priceMinor, type = "product") => ({
1787
+ content_id: id,
1788
+ content_type: type,
1789
+ quantity,
1790
+ price: major(priceMinor)
1791
+ });
1792
+ switch (e.name) {
1793
+ case "page_view":
1794
+ ttq.page();
1795
+ return;
1796
+ case "view_item": {
1797
+ const it = itemOf(e);
1798
+ ttq.track("ViewContent", {
1799
+ contents: [content(it.id, 1, e.priceMinor, it.type)],
1800
+ value: major(e.priceMinor),
1801
+ currency
1802
+ });
1803
+ return;
1804
+ }
1805
+ case "add_to_cart":
1806
+ ttq.track("AddToCart", {
1807
+ contents: [content(e.variantId, e.quantity, e.priceMinor)],
1808
+ value: major(e.priceMinor * e.quantity),
1809
+ currency
1810
+ });
1811
+ return;
1812
+ case "begin_checkout":
1813
+ ttq.track("InitiateCheckout", {
1814
+ value: major(e.valueMinor),
1815
+ currency
1816
+ });
1817
+ return;
1818
+ case "purchase":
1819
+ ttq.track(
1820
+ "CompletePayment",
1821
+ {
1822
+ contents: e.items.map((i) => content(i.id, i.quantity, i.priceMinor)),
1823
+ value: major(e.valueMinor),
1824
+ currency
1825
+ },
1826
+ { event_id: e.orderId }
1827
+ );
1828
+ }
1829
+ }
1830
+ function google(gtag, g, e) {
1831
+ const item = (id, quantity, priceMinor) => ({
1832
+ item_id: id,
1833
+ quantity,
1834
+ price: major(priceMinor)
1835
+ });
1836
+ switch (e.name) {
1837
+ case "page_view":
1838
+ gtag("event", "page_view");
1839
+ return;
1840
+ case "view_item":
1841
+ gtag("event", "view_item", {
1842
+ currency,
1843
+ value: major(e.priceMinor),
1844
+ items: [item(itemOf(e).id, 1, e.priceMinor)]
1845
+ });
1846
+ return;
1847
+ case "add_to_cart":
1848
+ gtag("event", "add_to_cart", {
1849
+ currency,
1850
+ value: major(e.priceMinor * e.quantity),
1851
+ items: [item(e.variantId, e.quantity, e.priceMinor)]
1852
+ });
1853
+ return;
1854
+ case "begin_checkout":
1855
+ gtag("event", "begin_checkout", {
1856
+ currency,
1857
+ value: major(e.valueMinor)
1858
+ });
1859
+ return;
1860
+ case "purchase":
1861
+ gtag("event", "purchase", {
1862
+ transaction_id: e.orderId,
1863
+ currency,
1864
+ value: major(e.valueMinor),
1865
+ items: e.items.map((i) => item(i.id, i.quantity, i.priceMinor))
1866
+ });
1867
+ if (g.adsId && g.adsConversionLabel) {
1868
+ gtag("event", "conversion", {
1869
+ send_to: `${g.adsId}/${g.adsConversionLabel}`,
1870
+ value: major(e.valueMinor),
1871
+ currency,
1872
+ transaction_id: e.orderId
1873
+ });
1874
+ }
1875
+ }
1876
+ }
1877
+
1878
+ // src/ad-pixels-loader.tsx
1879
+ import { useEffect as useEffect12 } from "react";
1880
+ function AdPixelsLoader({
1881
+ pixels: pixels2,
1882
+ hostOnly = false,
1883
+ currency: currency2 = "TRY",
1884
+ pathname
1885
+ }) {
1886
+ const { stored, known } = useConsent();
1887
+ const granted2 = stored?.granted.includes("marketing") ?? false;
1888
+ useEffect12(() => {
1889
+ if (!known) return;
1890
+ configurePixels(pixels2, granted2, { hostOnly, currency: currency2 });
1891
+ }, [pixels2, granted2, known, hostOnly, currency2]);
1892
+ useEffect12(() => {
1893
+ if (granted2) firePixel({ name: "page_view" });
1894
+ }, [granted2, pathname]);
1895
+ return null;
1896
+ }
1097
1897
  export {
1898
+ AdPixelsLoader,
1899
+ AnalyticsTracker,
1098
1900
  CheckoutChallenge,
1901
+ ConsentProvider,
1099
1902
  Content,
1903
+ OPTIONAL_CATEGORIES,
1100
1904
  ORDER_POLL_MAX_MS,
1101
1905
  ORDER_POLL_MIN_MS,
1102
1906
  PaymentForm,
1103
1907
  StorefrontProvider,
1908
+ configureAnalytics,
1909
+ configurePixels,
1104
1910
  defaultCartStorage,
1911
+ firePixel,
1105
1912
  isDeadCartError,
1106
1913
  isOrderSettled,
1914
+ onSecretPage,
1107
1915
  orderPollDelay,
1916
+ recordConsent,
1108
1917
  renderContent,
1918
+ resetAnalytics,
1919
+ resetPixels,
1920
+ track,
1109
1921
  useAccount,
1110
1922
  useCart,
1111
1923
  useCartStorage,
1112
1924
  useCategories,
1113
1925
  useCheckout,
1926
+ useConsent,
1114
1927
  useOrder,
1115
1928
  useProduct,
1116
1929
  useProducts,