@hanzo/event 0.3.43 → 0.3.48
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/consent.d.ts +36 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/cookie.d.ts +5 -0
- package/dist/cookie.d.ts.map +1 -0
- package/dist/events.d.ts +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/index.cjs +508 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +487 -38
- package/dist/index.mjs.map +1 -1
- package/dist/items.d.ts +22 -0
- package/dist/items.d.ts.map +1 -0
- package/dist/react.cjs +64 -12
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +8 -0
- package/dist/react.d.ts +8 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/react.mjs +65 -14
- package/dist/react.mjs.map +1 -1
- package/dist/tags.d.ts +55 -0
- package/dist/tags.d.ts.map +1 -0
- package/dist/touch.d.ts +7 -0
- package/dist/touch.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/consent.test.ts +140 -0
- package/src/consent.ts +116 -0
- package/src/cookie.ts +28 -0
- package/src/events.ts +1 -1
- package/src/index.ts +10 -0
- package/src/items.test.ts +22 -0
- package/src/items.ts +44 -0
- package/src/react.tsx +22 -0
- package/src/tags.test.ts +205 -0
- package/src/tags.ts +482 -0
- package/src/touch.ts +68 -0
package/dist/index.cjs
CHANGED
|
@@ -19,20 +19,20 @@ var SOCIAL_HOSTS = [
|
|
|
19
19
|
var SEARCH_HOSTS = ["google.", "bing.", "duckduckgo.", "yahoo.", "baidu.", "ecosia."];
|
|
20
20
|
function parseAttribution(search, referrer) {
|
|
21
21
|
const q = new URLSearchParams(search || "");
|
|
22
|
-
const
|
|
22
|
+
const get2 = (k) => {
|
|
23
23
|
const v = q.get(k);
|
|
24
24
|
return v ? v.trim() : void 0;
|
|
25
25
|
};
|
|
26
26
|
const a = {
|
|
27
27
|
utm: {
|
|
28
|
-
source:
|
|
29
|
-
medium:
|
|
30
|
-
campaign:
|
|
31
|
-
term:
|
|
32
|
-
content:
|
|
28
|
+
source: get2("utm_source"),
|
|
29
|
+
medium: get2("utm_medium"),
|
|
30
|
+
campaign: get2("utm_campaign"),
|
|
31
|
+
term: get2("utm_term"),
|
|
32
|
+
content: get2("utm_content")
|
|
33
33
|
},
|
|
34
34
|
referrer: referrer ? referrer.trim() : void 0,
|
|
35
|
-
refCode:
|
|
35
|
+
refCode: get2("ref") || get2("refCode") || get2("ref_code") || void 0
|
|
36
36
|
};
|
|
37
37
|
a.channel = deriveChannel(a);
|
|
38
38
|
return a;
|
|
@@ -289,13 +289,13 @@ var HZ_ANON_ADOPT = ["hz_anon_id", "hz_id"];
|
|
|
289
289
|
var HZ_ANON_DOMAIN = "hanzo.ai";
|
|
290
290
|
var HZ_ANON_MAX_AGE = 2 * 365 * 24 * 60 * 60;
|
|
291
291
|
var hzAnonMemo;
|
|
292
|
-
function hzUuidv7(
|
|
292
|
+
function hzUuidv7(now2) {
|
|
293
293
|
var b = new Uint8Array(16);
|
|
294
294
|
var i;
|
|
295
295
|
var c = typeof crypto !== "undefined" ? crypto : void 0;
|
|
296
296
|
if (c && typeof c.getRandomValues === "function") c.getRandomValues(b);
|
|
297
297
|
else for (i = 0; i < 16; i++) b[i] = Math.random() * 256 | 0;
|
|
298
|
-
var t = Math.floor(
|
|
298
|
+
var t = Math.floor(now2 === void 0 ? Date.now() : now2);
|
|
299
299
|
for (i = 5; i >= 0; i--) {
|
|
300
300
|
b[i] = t % 256;
|
|
301
301
|
t = Math.floor(t / 256);
|
|
@@ -407,7 +407,7 @@ function uuidv7Time(id) {
|
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
// package.json
|
|
410
|
-
var version = "0.3.
|
|
410
|
+
var version = "0.3.48";
|
|
411
411
|
|
|
412
412
|
// src/version.ts
|
|
413
413
|
var VERSION = version;
|
|
@@ -540,22 +540,22 @@ function coerceTag(v) {
|
|
|
540
540
|
return s.length > MAX_TAG_LEN ? s.slice(0, MAX_TAG_LEN) : s;
|
|
541
541
|
}
|
|
542
542
|
function buildSentryEvent(input) {
|
|
543
|
-
const { error, options = {}, identity, capturePII = false } = input;
|
|
543
|
+
const { error, options: options2 = {}, identity, capturePII = false } = input;
|
|
544
544
|
const norm = normalizeError(error);
|
|
545
|
-
const handled =
|
|
546
|
-
const level =
|
|
547
|
-
const
|
|
548
|
-
if (identity.product)
|
|
549
|
-
if (identity.sessionId)
|
|
545
|
+
const handled = options2.handled !== false;
|
|
546
|
+
const level = options2.level ?? (handled ? "error" : "fatal");
|
|
547
|
+
const tags2 = { handled: String(handled) };
|
|
548
|
+
if (identity.product) tags2.product = identity.product;
|
|
549
|
+
if (identity.sessionId) tags2.session = identity.sessionId;
|
|
550
550
|
try {
|
|
551
|
-
const props =
|
|
551
|
+
const props = options2.properties ?? {};
|
|
552
552
|
let n = 0;
|
|
553
553
|
for (const k of Object.keys(props)) {
|
|
554
554
|
if (n >= MAX_TAGS) break;
|
|
555
555
|
try {
|
|
556
556
|
const val = props[k];
|
|
557
557
|
if (val === void 0 || val === null) continue;
|
|
558
|
-
|
|
558
|
+
tags2[k] = scrubText(coerceTag(val), capturePII);
|
|
559
559
|
n++;
|
|
560
560
|
} catch {
|
|
561
561
|
continue;
|
|
@@ -580,7 +580,7 @@ function buildSentryEvent(input) {
|
|
|
580
580
|
}
|
|
581
581
|
]
|
|
582
582
|
},
|
|
583
|
-
tags,
|
|
583
|
+
tags: tags2,
|
|
584
584
|
sdk: { name: "@hanzo/event", version: VERSION }
|
|
585
585
|
};
|
|
586
586
|
if (identity.userId) event.user = { id: identity.userId };
|
|
@@ -710,7 +710,7 @@ function ls() {
|
|
|
710
710
|
function anonId() {
|
|
711
711
|
return hzAnonId() || void 0;
|
|
712
712
|
}
|
|
713
|
-
function sessionId(
|
|
713
|
+
function sessionId(now2 = Date.now()) {
|
|
714
714
|
const s = ls();
|
|
715
715
|
if (!s) return void 0;
|
|
716
716
|
let state = null;
|
|
@@ -719,17 +719,17 @@ function sessionId(now = Date.now()) {
|
|
|
719
719
|
} catch {
|
|
720
720
|
state = null;
|
|
721
721
|
}
|
|
722
|
-
if (!state ||
|
|
723
|
-
state = { id: hzUuidv7(
|
|
722
|
+
if (!state || now2 - state.last > SESSION_TTL_MS) {
|
|
723
|
+
state = { id: hzUuidv7(now2), last: now2 };
|
|
724
724
|
} else {
|
|
725
|
-
state.last =
|
|
725
|
+
state.last = now2;
|
|
726
726
|
}
|
|
727
727
|
s.setItem(KEY.session, JSON.stringify(state));
|
|
728
728
|
return state.id;
|
|
729
729
|
}
|
|
730
|
-
function adoptSession(id,
|
|
730
|
+
function adoptSession(id, now2 = Date.now()) {
|
|
731
731
|
const s = ls();
|
|
732
|
-
if (s) s.setItem(KEY.session, JSON.stringify({ id, last:
|
|
732
|
+
if (s) s.setItem(KEY.session, JSON.stringify({ id, last: now2 }));
|
|
733
733
|
}
|
|
734
734
|
function adoptAnonId(id) {
|
|
735
735
|
hzAnonAdopt(id);
|
|
@@ -815,10 +815,10 @@ function linkUrl(url, state, fromHost, base) {
|
|
|
815
815
|
}
|
|
816
816
|
if (u.protocol !== "https:" && u.protocol !== "http:") return url;
|
|
817
817
|
if (!orgOf(u.hostname) || u.hostname === fromHost) return url;
|
|
818
|
-
const
|
|
819
|
-
if (isId(state.anonId))
|
|
820
|
-
if (isId(state.sessionId))
|
|
821
|
-
if (state.firstTouch)
|
|
818
|
+
const set2 = (k, v) => v && u.searchParams.set(k, v);
|
|
819
|
+
if (isId(state.anonId)) set2(LINK_PARAMS.anon, state.anonId);
|
|
820
|
+
if (isId(state.sessionId)) set2(LINK_PARAMS.session, state.sessionId);
|
|
821
|
+
if (state.firstTouch) set2(LINK_PARAMS.firstTouch, encodeFirstTouch(state.firstTouch));
|
|
822
822
|
return u.toString();
|
|
823
823
|
}
|
|
824
824
|
function readLink(search) {
|
|
@@ -1168,11 +1168,11 @@ var Analytics = class {
|
|
|
1168
1168
|
* or publishable key is attached here — the two planes authenticate
|
|
1169
1169
|
* independently. Errors are sent one envelope per event, immediately: batching
|
|
1170
1170
|
* a crash report is how you lose it. */
|
|
1171
|
-
sendError(err,
|
|
1171
|
+
sendError(err, options2) {
|
|
1172
1172
|
if (!this.cfg.enabled || !this.dsn) return;
|
|
1173
1173
|
const event = buildSentryEvent({
|
|
1174
1174
|
error: err,
|
|
1175
|
-
options,
|
|
1175
|
+
options: options2,
|
|
1176
1176
|
identity: this.errorIdentity(),
|
|
1177
1177
|
capturePII: this.cfg.capturePII ?? false
|
|
1178
1178
|
});
|
|
@@ -1259,16 +1259,16 @@ var Analytics = class {
|
|
|
1259
1259
|
};
|
|
1260
1260
|
var CLIENTS = /* @__PURE__ */ Symbol.for("hanzo.event.clients");
|
|
1261
1261
|
function registry() {
|
|
1262
|
-
const
|
|
1263
|
-
const existing =
|
|
1262
|
+
const g2 = globalThis;
|
|
1263
|
+
const existing = g2[CLIENTS];
|
|
1264
1264
|
if (existing) return existing;
|
|
1265
1265
|
const fresh = /* @__PURE__ */ new Map();
|
|
1266
|
-
|
|
1266
|
+
g2[CLIENTS] = fresh;
|
|
1267
1267
|
return fresh;
|
|
1268
1268
|
}
|
|
1269
1269
|
function resetClients() {
|
|
1270
|
-
const
|
|
1271
|
-
delete
|
|
1270
|
+
const g2 = globalThis;
|
|
1271
|
+
delete g2[CLIENTS];
|
|
1272
1272
|
}
|
|
1273
1273
|
function createAnalytics(config) {
|
|
1274
1274
|
if (!isBrowser() || config.enabled === false) return new Analytics(config);
|
|
@@ -1284,6 +1284,455 @@ function createAnalytics(config) {
|
|
|
1284
1284
|
return fresh;
|
|
1285
1285
|
}
|
|
1286
1286
|
|
|
1287
|
+
// src/cookie.ts
|
|
1288
|
+
var DAY = 86400;
|
|
1289
|
+
function domain() {
|
|
1290
|
+
const h = window.location.hostname;
|
|
1291
|
+
if (h === "localhost" || /^[\d.]+$/.test(h) || h.includes(":")) return "";
|
|
1292
|
+
const parts = h.split(".");
|
|
1293
|
+
return parts.length > 2 ? `; Domain=.${parts.slice(-2).join(".")}` : `; Domain=.${h}`;
|
|
1294
|
+
}
|
|
1295
|
+
function get(name) {
|
|
1296
|
+
if (typeof document === "undefined") return void 0;
|
|
1297
|
+
const hit = document.cookie.split("; ").find((c) => c.startsWith(`${name}=`));
|
|
1298
|
+
return hit ? decodeURIComponent(hit.slice(name.length + 1)) : void 0;
|
|
1299
|
+
}
|
|
1300
|
+
function set(name, value, days) {
|
|
1301
|
+
if (typeof document === "undefined") return;
|
|
1302
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
1303
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Max-Age=${days * DAY}; Path=/; SameSite=Lax${domain()}${secure}`;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// src/consent.ts
|
|
1307
|
+
var CONSENT_COOKIE = "hz_consent";
|
|
1308
|
+
var CONSENT_EVENT = "hzconsent";
|
|
1309
|
+
var US = /^(America\/(New_York|Chicago|Denver|Los_Angeles|Phoenix|Anchorage|Adak|Boise|Detroit|Juneau|Sitka|Nome|Yakutat|Menominee|Metlakatla|Indiana\/.*|Kentucky\/.*|North_Dakota\/.*)|Pacific\/Honolulu|US\/.*)$/;
|
|
1310
|
+
function gpc() {
|
|
1311
|
+
if (typeof navigator === "undefined") return false;
|
|
1312
|
+
return navigator.globalPrivacyControl === true;
|
|
1313
|
+
}
|
|
1314
|
+
function refused() {
|
|
1315
|
+
if (typeof window === "undefined") return false;
|
|
1316
|
+
const n = navigator;
|
|
1317
|
+
const dnt = n.doNotTrack ?? window.doNotTrack ?? n.msDoNotTrack;
|
|
1318
|
+
return gpc() || dnt === "1" || dnt === "yes";
|
|
1319
|
+
}
|
|
1320
|
+
function region() {
|
|
1321
|
+
try {
|
|
1322
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
|
|
1323
|
+
return US.test(zone) ? "opt-out" : "opt-in";
|
|
1324
|
+
} catch {
|
|
1325
|
+
return "opt-in";
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
function stored() {
|
|
1329
|
+
return get(CONSENT_COOKIE) !== void 0;
|
|
1330
|
+
}
|
|
1331
|
+
function read2() {
|
|
1332
|
+
const kept = get(CONSENT_COOKIE);
|
|
1333
|
+
const on = kept !== void 0 ? kept.split(",") : region() === "opt-in" || refused() ? [] : ["analytics", "marketing", "ads"];
|
|
1334
|
+
const has = (k) => on.includes(k);
|
|
1335
|
+
return { analytics: has("analytics"), marketing: has("marketing") && !gpc(), ads: has("ads") && !gpc() };
|
|
1336
|
+
}
|
|
1337
|
+
function asks() {
|
|
1338
|
+
return typeof document !== "undefined" && region() === "opt-in" && !stored();
|
|
1339
|
+
}
|
|
1340
|
+
function render(c) {
|
|
1341
|
+
return ["analytics", "marketing", "ads"].filter((k) => c[k]).join(",");
|
|
1342
|
+
}
|
|
1343
|
+
function save(c) {
|
|
1344
|
+
const out = { analytics: c.analytics, marketing: c.marketing && !gpc(), ads: c.ads && !gpc() };
|
|
1345
|
+
set(CONSENT_COOKIE, render(out), 395);
|
|
1346
|
+
if (typeof window !== "undefined") window.dispatchEvent(new Event(CONSENT_EVENT));
|
|
1347
|
+
}
|
|
1348
|
+
var acceptAll = () => save({ analytics: true, marketing: true, ads: true });
|
|
1349
|
+
var rejectAll = () => save({ analytics: false, marketing: false, ads: false });
|
|
1350
|
+
|
|
1351
|
+
// src/touch.ts
|
|
1352
|
+
var CLICK_IDS = ["gclid", "gbraid", "wbraid", "fbclid", "li_fat_id", "twclid", "ttclid"];
|
|
1353
|
+
var DAYS = 90;
|
|
1354
|
+
var now = () => Math.floor(Date.now() / 1e3);
|
|
1355
|
+
var rand = () => Math.floor(Math.random() * 2 ** 31);
|
|
1356
|
+
function capture(c) {
|
|
1357
|
+
if (typeof window === "undefined") return;
|
|
1358
|
+
if (c.marketing) {
|
|
1359
|
+
const q = new URLSearchParams(window.location.search);
|
|
1360
|
+
const click = {};
|
|
1361
|
+
for (const k of CLICK_IDS) {
|
|
1362
|
+
const v = q.get(k)?.trim();
|
|
1363
|
+
if (v) click[k] = v;
|
|
1364
|
+
}
|
|
1365
|
+
if (Object.keys(click).length) {
|
|
1366
|
+
click.clicked = now();
|
|
1367
|
+
set("hz_touch", JSON.stringify(click), DAYS);
|
|
1368
|
+
if (click.fbclid) set("_fbc", `fb.1.${Date.now()}.${click.fbclid}`, DAYS);
|
|
1369
|
+
}
|
|
1370
|
+
if (!get("_fbp")) set("_fbp", `fb.1.${Date.now()}.${rand()}`, DAYS);
|
|
1371
|
+
}
|
|
1372
|
+
if (c.analytics && !get("_ga") && !get("hz_cid")) set("hz_cid", `${rand()}.${now()}`, 730);
|
|
1373
|
+
}
|
|
1374
|
+
function touch(c) {
|
|
1375
|
+
const out = {};
|
|
1376
|
+
if (c.marketing) {
|
|
1377
|
+
try {
|
|
1378
|
+
Object.assign(out, JSON.parse(get("hz_touch") ?? "{}"));
|
|
1379
|
+
} catch {
|
|
1380
|
+
}
|
|
1381
|
+
const fbc = get("_fbc");
|
|
1382
|
+
const fbp = get("_fbp");
|
|
1383
|
+
if (fbc) out.fbc = fbc;
|
|
1384
|
+
if (fbp) out.fbp = fbp;
|
|
1385
|
+
}
|
|
1386
|
+
if (c.analytics) {
|
|
1387
|
+
const ga = get("_ga")?.split(".");
|
|
1388
|
+
const cid = ga && ga.length >= 4 ? ga.slice(-2).join(".") : get("hz_cid");
|
|
1389
|
+
if (cid) out.cid = cid;
|
|
1390
|
+
}
|
|
1391
|
+
return out;
|
|
1392
|
+
}
|
|
1393
|
+
var SITE_KEY = Object.freeze({
|
|
1394
|
+
"hanzo.ai": "pk-CmfLA2K6kvsPflrS9DSkt06H_kSoQB_21sjedt6VJdc",
|
|
1395
|
+
"www.hanzo.ai": "pk-CmfLA2K6kvsPflrS9DSkt06H_kSoQB_21sjedt6VJdc",
|
|
1396
|
+
"hanzo.app": "pk-wlnXN2a9_vmCm60yTFtQ629Q8TyuaxBNZbY1RWT72gQ",
|
|
1397
|
+
"hanzo.team": "pk-NCzD2FiHpZv8KUpkCX4olT1LJOJsMxBC_Z8NkiQsOFQ",
|
|
1398
|
+
"pay.hanzo.ai": "pk-eX6kv7JZNoiYn1WkeJH3tT_8OvkVYScmCXnLMwxTKf8",
|
|
1399
|
+
"platform.hanzo.ai": "pk-My1RpZLEUnTj8vAdPbWKYdDUuhxZJ4dVjHcwjZN4rZ8",
|
|
1400
|
+
"docs.hanzo.ai": "pk-jukhtjMT2ymoeBDAeFjINQWlBv-v9sNn1TPztiCrrwk",
|
|
1401
|
+
"hanzo.bot": "pk-W5d7Mn7ZukT7igyscIy6Pqe8JpA0Ge604Yn4xNR4JCU",
|
|
1402
|
+
"cloud.hanzo.ai": "pk-RAfEGHPoNdCEU9fnA_cPd_Xo9Tci44rlYQV9xuJ1Ob0"
|
|
1403
|
+
});
|
|
1404
|
+
var page = () => window;
|
|
1405
|
+
var tags = [];
|
|
1406
|
+
var configured = false;
|
|
1407
|
+
var options = {};
|
|
1408
|
+
var loaded = /* @__PURE__ */ new Set();
|
|
1409
|
+
var google = "idle";
|
|
1410
|
+
var configAnswered = false;
|
|
1411
|
+
var held = [];
|
|
1412
|
+
var leaving = false;
|
|
1413
|
+
function settled() {
|
|
1414
|
+
return configAnswered && google !== "wait";
|
|
1415
|
+
}
|
|
1416
|
+
function flush() {
|
|
1417
|
+
if (settled() || leaving) held.splice(0).forEach((send) => send());
|
|
1418
|
+
}
|
|
1419
|
+
function script(src, onload, onerror) {
|
|
1420
|
+
const s = document.createElement("script");
|
|
1421
|
+
s.async = true;
|
|
1422
|
+
s.src = src;
|
|
1423
|
+
if (onload) s.onload = onload;
|
|
1424
|
+
if (onerror) s.onerror = onerror;
|
|
1425
|
+
document.head.appendChild(s);
|
|
1426
|
+
}
|
|
1427
|
+
function gtagStub() {
|
|
1428
|
+
const p = page();
|
|
1429
|
+
p.dataLayer = p.dataLayer || [];
|
|
1430
|
+
if (!p.gtag) {
|
|
1431
|
+
p.gtag = function() {
|
|
1432
|
+
p.dataLayer.push(arguments);
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
return p.gtag;
|
|
1436
|
+
}
|
|
1437
|
+
var g = (on) => on ? "granted" : "denied";
|
|
1438
|
+
function consentMode(c, first) {
|
|
1439
|
+
const gtag = gtagStub();
|
|
1440
|
+
const state = {
|
|
1441
|
+
analytics_storage: g(c.analytics),
|
|
1442
|
+
ad_storage: g(c.marketing),
|
|
1443
|
+
ad_user_data: g(c.marketing),
|
|
1444
|
+
ad_personalization: g(c.marketing && c.ads)
|
|
1445
|
+
};
|
|
1446
|
+
if (first) {
|
|
1447
|
+
gtag("consent", "default", {
|
|
1448
|
+
analytics_storage: "denied",
|
|
1449
|
+
ad_storage: "denied",
|
|
1450
|
+
ad_user_data: "denied",
|
|
1451
|
+
ad_personalization: "denied",
|
|
1452
|
+
wait_for_update: 500
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
gtag("consent", "update", state);
|
|
1456
|
+
}
|
|
1457
|
+
function loadGoogle(ids) {
|
|
1458
|
+
const gtag = gtagStub();
|
|
1459
|
+
const fresh = ids.filter((id) => !loaded.has(id));
|
|
1460
|
+
if (!fresh.length) return;
|
|
1461
|
+
if (google === "idle") {
|
|
1462
|
+
google = "wait";
|
|
1463
|
+
gtag("js", /* @__PURE__ */ new Date());
|
|
1464
|
+
const done = (to) => () => {
|
|
1465
|
+
if (google !== "wait") return;
|
|
1466
|
+
google = to;
|
|
1467
|
+
flush();
|
|
1468
|
+
};
|
|
1469
|
+
script(`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(fresh[0])}`, done("loaded"), done("failed"));
|
|
1470
|
+
setTimeout(done("failed"), 8e3);
|
|
1471
|
+
}
|
|
1472
|
+
for (const id of fresh) {
|
|
1473
|
+
loaded.add(id);
|
|
1474
|
+
gtag("config", id, options.domains ? { linker: { domains: options.domains } } : {});
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
function loadMeta(id, c) {
|
|
1478
|
+
const p = page();
|
|
1479
|
+
if (!p.fbq) {
|
|
1480
|
+
const n = p.fbq = function(...a) {
|
|
1481
|
+
if (n.callMethod) n.callMethod(...a);
|
|
1482
|
+
else n.queue.push(a);
|
|
1483
|
+
};
|
|
1484
|
+
if (!p._fbq) p._fbq = n;
|
|
1485
|
+
n.push = n;
|
|
1486
|
+
n.loaded = true;
|
|
1487
|
+
n.version = "2.0";
|
|
1488
|
+
n.queue = [];
|
|
1489
|
+
script("https://connect.facebook.net/en_US/fbevents.js");
|
|
1490
|
+
}
|
|
1491
|
+
if (!c.ads) p.fbq("dataProcessingOptions", ["LDU"], 0, 0);
|
|
1492
|
+
p.fbq("init", id);
|
|
1493
|
+
p.fbq("track", "PageView");
|
|
1494
|
+
}
|
|
1495
|
+
function loadLinkedIn(id) {
|
|
1496
|
+
const p = page();
|
|
1497
|
+
p._linkedin_data_partner_ids = p._linkedin_data_partner_ids || [];
|
|
1498
|
+
p._linkedin_data_partner_ids.push(id);
|
|
1499
|
+
if (!p.lintrk) {
|
|
1500
|
+
const l = p.lintrk = function(...a) {
|
|
1501
|
+
l.q.push(a);
|
|
1502
|
+
};
|
|
1503
|
+
l.q = [];
|
|
1504
|
+
}
|
|
1505
|
+
script("https://snap.licdn.com/li.lms-analytics/insight.min.js");
|
|
1506
|
+
}
|
|
1507
|
+
function loadX(id) {
|
|
1508
|
+
const p = page();
|
|
1509
|
+
if (!p.twq) {
|
|
1510
|
+
const s = p.twq = function(...a) {
|
|
1511
|
+
if (s.exe) s.exe(...a);
|
|
1512
|
+
else s.queue.push(a);
|
|
1513
|
+
};
|
|
1514
|
+
s.version = "1.1";
|
|
1515
|
+
s.queue = [];
|
|
1516
|
+
script("https://static.ads-twitter.com/uwt.js");
|
|
1517
|
+
}
|
|
1518
|
+
p.twq("config", id);
|
|
1519
|
+
}
|
|
1520
|
+
var TIKTOK_METHODS = ["page", "track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"];
|
|
1521
|
+
function loadTikTok(id) {
|
|
1522
|
+
const p = page();
|
|
1523
|
+
p.TiktokAnalyticsObject = "ttq";
|
|
1524
|
+
const q = p.ttq = p.ttq || [];
|
|
1525
|
+
if (!q._i) {
|
|
1526
|
+
q.methods = TIKTOK_METHODS;
|
|
1527
|
+
for (const m of TIKTOK_METHODS) q[m] = (...a) => q.push([m, ...a]);
|
|
1528
|
+
q._i = {};
|
|
1529
|
+
q._t = {};
|
|
1530
|
+
q._o = {};
|
|
1531
|
+
q.load = (sdk) => {
|
|
1532
|
+
q._i[sdk] = [];
|
|
1533
|
+
q._t[sdk] = Date.now();
|
|
1534
|
+
script(`https://analytics.tiktok.com/i18n/pixel/events.js?sdkid=${encodeURIComponent(sdk)}&lib=ttq`);
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
q.load(id);
|
|
1538
|
+
q.page();
|
|
1539
|
+
}
|
|
1540
|
+
var NEEDS = {
|
|
1541
|
+
ga: "analytics",
|
|
1542
|
+
gads: "marketing",
|
|
1543
|
+
meta: "marketing",
|
|
1544
|
+
linkedin: "marketing",
|
|
1545
|
+
x: "marketing",
|
|
1546
|
+
tiktok: "marketing"
|
|
1547
|
+
};
|
|
1548
|
+
var allowed = (t, c) => t.type === "ga" ? c.analytics || c.marketing : Boolean(NEEDS[t.type] && c[NEEDS[t.type]]);
|
|
1549
|
+
function apply() {
|
|
1550
|
+
if (typeof window === "undefined" || !configured) return;
|
|
1551
|
+
const c = read2();
|
|
1552
|
+
capture(c);
|
|
1553
|
+
const on = tags.filter((t) => allowed(t, c));
|
|
1554
|
+
const ids = on.filter((t) => t.type === "ga" || t.type === "gads").map((t) => t.id);
|
|
1555
|
+
if (ids.length) {
|
|
1556
|
+
consentMode(c, !loaded.has("consent"));
|
|
1557
|
+
loaded.add("consent");
|
|
1558
|
+
loadGoogle(ids);
|
|
1559
|
+
}
|
|
1560
|
+
for (const t of on) {
|
|
1561
|
+
const k = `${t.type}:${t.id}`;
|
|
1562
|
+
if (loaded.has(k)) continue;
|
|
1563
|
+
if (t.type === "meta") loadMeta(t.id, c);
|
|
1564
|
+
else if (t.type === "linkedin") loadLinkedIn(t.id);
|
|
1565
|
+
else if (t.type === "x") loadX(t.id);
|
|
1566
|
+
else if (t.type === "tiktok") loadTikTok(t.id);
|
|
1567
|
+
else continue;
|
|
1568
|
+
loaded.add(k);
|
|
1569
|
+
}
|
|
1570
|
+
flush();
|
|
1571
|
+
}
|
|
1572
|
+
function start(o = {}) {
|
|
1573
|
+
if (typeof window === "undefined") return () => void 0;
|
|
1574
|
+
options = o;
|
|
1575
|
+
addEventListener(CONSENT_EVENT, apply);
|
|
1576
|
+
addEventListener("pagehide", pagehide);
|
|
1577
|
+
if (!configured) {
|
|
1578
|
+
configured = true;
|
|
1579
|
+
const base = (o.base ?? "https://api.hanzo.ai").replace(/\/$/, "");
|
|
1580
|
+
const q = new URLSearchParams();
|
|
1581
|
+
const host = o.host ?? window.location.hostname;
|
|
1582
|
+
const key = o.key ?? SITE_KEY[host];
|
|
1583
|
+
if (key) q.set("key", key);
|
|
1584
|
+
q.set("host", host);
|
|
1585
|
+
const answer = (list) => {
|
|
1586
|
+
tags = list;
|
|
1587
|
+
configAnswered = true;
|
|
1588
|
+
apply();
|
|
1589
|
+
};
|
|
1590
|
+
const cap = setTimeout(() => answer([]), 3e3);
|
|
1591
|
+
fetch(`${base}/v1/project/tags?${q}`).then((r) => r.ok ? r.json() : { tags: [] }).then((j) => {
|
|
1592
|
+
clearTimeout(cap);
|
|
1593
|
+
answer(Array.isArray(j.tags) ? j.tags : []);
|
|
1594
|
+
}).catch(() => {
|
|
1595
|
+
clearTimeout(cap);
|
|
1596
|
+
answer([]);
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
return () => {
|
|
1600
|
+
removeEventListener(CONSENT_EVENT, apply);
|
|
1601
|
+
removeEventListener("pagehide", pagehide);
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
function pagehide() {
|
|
1605
|
+
leaving = true;
|
|
1606
|
+
flush();
|
|
1607
|
+
}
|
|
1608
|
+
function reach() {
|
|
1609
|
+
const c = read2();
|
|
1610
|
+
const to = [];
|
|
1611
|
+
for (const t of tags) {
|
|
1612
|
+
if (!allowed(t, c)) continue;
|
|
1613
|
+
const running = t.type === "ga" ? google === "loaded" && c.analytics : t.type === "gads" ? google === "loaded" && c.marketing : loaded.has(`${t.type}:${t.id}`);
|
|
1614
|
+
if (running && !to.includes(t.type)) to.push(t.type);
|
|
1615
|
+
}
|
|
1616
|
+
return to.join(",");
|
|
1617
|
+
}
|
|
1618
|
+
var META_STANDARD = /* @__PURE__ */ new Set([
|
|
1619
|
+
"AddPaymentInfo",
|
|
1620
|
+
"AddToCart",
|
|
1621
|
+
"AddToWishlist",
|
|
1622
|
+
"CompleteRegistration",
|
|
1623
|
+
"Contact",
|
|
1624
|
+
"CustomizeProduct",
|
|
1625
|
+
"Donate",
|
|
1626
|
+
"FindLocation",
|
|
1627
|
+
"InitiateCheckout",
|
|
1628
|
+
"Lead",
|
|
1629
|
+
"Purchase",
|
|
1630
|
+
"Schedule",
|
|
1631
|
+
"Search",
|
|
1632
|
+
"StartTrial",
|
|
1633
|
+
"SubmitApplication",
|
|
1634
|
+
"Subscribe",
|
|
1635
|
+
"ViewContent"
|
|
1636
|
+
]);
|
|
1637
|
+
function shape(platform, p) {
|
|
1638
|
+
const items = Array.isArray(p.items) ? p.items : [];
|
|
1639
|
+
const out = {};
|
|
1640
|
+
if (typeof p.value === "number") out.value = p.value;
|
|
1641
|
+
out.currency = typeof p.currency === "string" ? p.currency : "USD";
|
|
1642
|
+
if (!items.length) return out;
|
|
1643
|
+
if (platform === "meta") {
|
|
1644
|
+
out.content_type = "product";
|
|
1645
|
+
out.content_ids = items.map((i) => i.item_id);
|
|
1646
|
+
out.contents = items.map((i) => ({ id: i.item_id, quantity: i.quantity ?? 1, item_price: i.price }));
|
|
1647
|
+
out.content_name = items[0].item_name;
|
|
1648
|
+
out.num_items = items.reduce((n, i) => n + (i.quantity ?? 1), 0);
|
|
1649
|
+
} else if (platform === "tiktok") {
|
|
1650
|
+
out.content_type = "product";
|
|
1651
|
+
out.contents = items.map((i) => ({ content_id: i.item_id, content_name: i.item_name, quantity: i.quantity ?? 1, price: i.price }));
|
|
1652
|
+
} else {
|
|
1653
|
+
out.contents = items.map((i) => ({ content_id: i.item_id, content_name: i.item_name, content_price: i.price, num_items: i.quantity ?? 1 }));
|
|
1654
|
+
}
|
|
1655
|
+
return out;
|
|
1656
|
+
}
|
|
1657
|
+
function unpriced(p) {
|
|
1658
|
+
const out = { ...p, value: 0 };
|
|
1659
|
+
if (Array.isArray(p.items)) out.items = p.items.map((i) => ({ ...i, price: 0 }));
|
|
1660
|
+
return out;
|
|
1661
|
+
}
|
|
1662
|
+
function mirror(name, params, id, to = reach()) {
|
|
1663
|
+
const p = page();
|
|
1664
|
+
const on = new Set(to.split(",").filter(Boolean));
|
|
1665
|
+
const ga4 = events.namesOn(name, "ga4");
|
|
1666
|
+
const test = params.test === true;
|
|
1667
|
+
if (test) params = unpriced(params);
|
|
1668
|
+
const transaction = typeof params.order_id === "string" ? { transaction_id: params.order_id } : {};
|
|
1669
|
+
for (const t of tags) {
|
|
1670
|
+
if (!on.has(t.type)) continue;
|
|
1671
|
+
const rule = t.events?.[name];
|
|
1672
|
+
if (t.type === "ga") {
|
|
1673
|
+
for (const n of ga4) {
|
|
1674
|
+
p.gtag?.("event", n, { ...params, ...transaction, event_id: id, transport_type: "beacon", ...test ? { debug_mode: true } : {} });
|
|
1675
|
+
}
|
|
1676
|
+
} else if (t.type === "gads" && rule) {
|
|
1677
|
+
p.gtag?.("event", "conversion", {
|
|
1678
|
+
send_to: rule,
|
|
1679
|
+
value: typeof params.value === "number" ? params.value : void 0,
|
|
1680
|
+
currency: typeof params.currency === "string" ? params.currency : "USD",
|
|
1681
|
+
...transaction
|
|
1682
|
+
});
|
|
1683
|
+
} else if (t.type === "meta") {
|
|
1684
|
+
for (const n of events.namesOn(name, "meta")) {
|
|
1685
|
+
p.fbq?.(META_STANDARD.has(n) ? "track" : "trackCustom", n, shape("meta", params), { eventID: id });
|
|
1686
|
+
}
|
|
1687
|
+
} else if (t.type === "tiktok") {
|
|
1688
|
+
for (const n of events.namesOn(name, "tiktok")) p.ttq?.track?.(n, shape("tiktok", params), { event_id: id });
|
|
1689
|
+
} else if (t.type === "linkedin" && rule && events.namesOn(name, "linkedin").length) {
|
|
1690
|
+
p.lintrk?.("track", { conversion_id: Number(rule) });
|
|
1691
|
+
} else if (t.type === "x" && rule && events.namesOn(name, "x").length) {
|
|
1692
|
+
p.twq?.("event", rule, { ...shape("x", params), conversion_id: id });
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
function track(stream, name, params = {}, only) {
|
|
1697
|
+
if (typeof window === "undefined") return;
|
|
1698
|
+
if (!leaving && !settled()) {
|
|
1699
|
+
held.push(() => track(stream, name, params, only));
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
const c = read2();
|
|
1703
|
+
const event_id = typeof params.event_id === "string" && params.event_id ? params.event_id : crypto.randomUUID();
|
|
1704
|
+
const to = reach();
|
|
1705
|
+
mirror(name, params, event_id, to);
|
|
1706
|
+
if (only === "tags") return;
|
|
1707
|
+
stream?.capture(name, {
|
|
1708
|
+
...params,
|
|
1709
|
+
...touch(c),
|
|
1710
|
+
event_id,
|
|
1711
|
+
consent: render(c),
|
|
1712
|
+
tags: to,
|
|
1713
|
+
userAgent: navigator.userAgent,
|
|
1714
|
+
url: window.location.href
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
function visit() {
|
|
1718
|
+
const c = read2();
|
|
1719
|
+
return { ...touch(c), consent: render(c), tags: reach(), userAgent: navigator.userAgent, url: window.location.href };
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
// src/items.ts
|
|
1723
|
+
function commerceItem(p) {
|
|
1724
|
+
const annual = /^(year|yearly|annual)$/i.test(p.interval);
|
|
1725
|
+
return {
|
|
1726
|
+
item_id: p.id,
|
|
1727
|
+
...p.name ? { item_name: p.name } : {},
|
|
1728
|
+
item_category: p.team ? "team" : "individual",
|
|
1729
|
+
item_variant: annual ? "annual" : "monthly",
|
|
1730
|
+
price: p.price ?? 0,
|
|
1731
|
+
quantity: p.quantity ?? 1
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
var worth = (i) => i.price * i.quantity;
|
|
1735
|
+
|
|
1287
1736
|
// src/goals.ts
|
|
1288
1737
|
var GOALS = {
|
|
1289
1738
|
// Signup: the conversion is signup_completed, along the site signup funnel.
|
|
@@ -1369,15 +1818,23 @@ Object.defineProperty(exports, "eventsOf", {
|
|
|
1369
1818
|
get: function () { return events.eventsOf; }
|
|
1370
1819
|
});
|
|
1371
1820
|
exports.Analytics = Analytics;
|
|
1821
|
+
exports.CLICK_IDS = CLICK_IDS;
|
|
1372
1822
|
exports.COHORTS = COHORTS;
|
|
1823
|
+
exports.CONSENT_COOKIE = CONSENT_COOKIE;
|
|
1824
|
+
exports.CONSENT_EVENT = CONSENT_EVENT;
|
|
1373
1825
|
exports.GOALS = GOALS;
|
|
1374
1826
|
exports.LINK_PARAMS = LINK_PARAMS;
|
|
1375
1827
|
exports.ORG_DOMAIN = ORG_DOMAIN;
|
|
1376
1828
|
exports.ORG_KEY = ORG_KEY;
|
|
1377
1829
|
exports.PRODUCT_PROJECT = PRODUCT_PROJECT;
|
|
1830
|
+
exports.SITE_KEY = SITE_KEY;
|
|
1378
1831
|
exports.VERSION = VERSION;
|
|
1832
|
+
exports.acceptAll = acceptAll;
|
|
1833
|
+
exports.asks = asks;
|
|
1379
1834
|
exports.buildEnvelope = buildEnvelope;
|
|
1380
1835
|
exports.buildSentryEvent = buildSentryEvent;
|
|
1836
|
+
exports.captureClick = capture;
|
|
1837
|
+
exports.commerceItem = commerceItem;
|
|
1381
1838
|
exports.createAnalytics = createAnalytics;
|
|
1382
1839
|
exports.deriveChannel = deriveChannel;
|
|
1383
1840
|
exports.digest = digest;
|
|
@@ -1388,22 +1845,37 @@ exports.fingerprint = fingerprint;
|
|
|
1388
1845
|
exports.framesFromStack = framesFromStack;
|
|
1389
1846
|
exports.getCohort = getCohort;
|
|
1390
1847
|
exports.getFirstTouch = getFirstTouch;
|
|
1848
|
+
exports.gpc = gpc;
|
|
1391
1849
|
exports.hasAttribution = hasAttribution;
|
|
1392
1850
|
exports.hostOf = hostOf;
|
|
1393
1851
|
exports.isoWeek = isoWeek;
|
|
1394
1852
|
exports.keyFor = keyFor;
|
|
1395
1853
|
exports.keyForPage = keyForPage;
|
|
1396
1854
|
exports.linkUrl = linkUrl;
|
|
1855
|
+
exports.mirror = mirror;
|
|
1397
1856
|
exports.orgOf = orgOf;
|
|
1398
1857
|
exports.parseAttribution = parseAttribution;
|
|
1399
1858
|
exports.parseDsn = parseDsn;
|
|
1859
|
+
exports.reach = reach;
|
|
1860
|
+
exports.readConsent = read2;
|
|
1400
1861
|
exports.readLink = readLink;
|
|
1401
1862
|
exports.redactSecrets = redactSecrets;
|
|
1863
|
+
exports.refused = refused;
|
|
1864
|
+
exports.region = region;
|
|
1865
|
+
exports.rejectAll = rejectAll;
|
|
1866
|
+
exports.renderConsent = render;
|
|
1402
1867
|
exports.resetClients = resetClients;
|
|
1868
|
+
exports.saveConsent = save;
|
|
1403
1869
|
exports.scrubPII = scrubPII;
|
|
1404
1870
|
exports.scrubText = scrubText;
|
|
1871
|
+
exports.startTags = start;
|
|
1872
|
+
exports.storedConsent = stored;
|
|
1405
1873
|
exports.stripLink = stripLink;
|
|
1874
|
+
exports.touch = touch;
|
|
1875
|
+
exports.track = track;
|
|
1406
1876
|
exports.uuidv7 = hzUuidv7;
|
|
1407
1877
|
exports.uuidv7Time = uuidv7Time;
|
|
1878
|
+
exports.visit = visit;
|
|
1879
|
+
exports.worth = worth;
|
|
1408
1880
|
//# sourceMappingURL=index.cjs.map
|
|
1409
1881
|
//# sourceMappingURL=index.cjs.map
|