@hanzo/event 0.3.49 → 0.3.52

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/org.d.ts CHANGED
@@ -57,6 +57,16 @@ export declare const ORG_DOMAIN: Readonly<Record<string, readonly string[]>>;
57
57
  * recreate a project, move BOTH.
58
58
  */
59
59
  export declare const ORG_KEY: Keyring;
60
+ /**
61
+ * The publishable key of each site's project, which is how cloud finds the site's
62
+ * tag set and the project its events are filed under. Each site is ONE project with its
63
+ * own key. A `pk-` is public by design (it ships in every page); it names a site,
64
+ * never a platform id. A host absent here falls back to its org's key for events and
65
+ * has no tag config unless `start` is given a key.
66
+ */
67
+ export declare const SITE_KEY: Readonly<Record<string, string>>;
68
+ /** The project key of the site a host is: its own entry, `www.` stripped, a `*.hanzo.app` site under hanzo.app. */
69
+ export declare function siteKey(host: string): string | undefined;
60
70
  /**
61
71
  * The org that owns a host, or undefined when no brand claims it.
62
72
  *
package/dist/org.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"org.d.ts","sourceRoot":"","sources":["../src/org.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,mCAAmC;AACnC,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtD;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAiCjE,CAAA;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,EAAE,OAIpB,CAAA;AAWF;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CActD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAiB,GAAG,MAAM,GAAG,SAAS,CAOnF;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,OAAO,GAAE,OAAiB,GAAG,MAAM,GAAG,SAAS,CAGzE"}
1
+ {"version":3,"file":"org.d.ts","sourceRoot":"","sources":["../src/org.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,mCAAmC;AACnC,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtD;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAiCjE,CAAA;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,EAAE,OAIpB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBpD,CAAA;AAEF,mHAAmH;AACnH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGxD;AAWD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CActD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAiB,GAAG,MAAM,GAAG,SAAS,CAWnF;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,OAAO,GAAE,OAAiB,GAAG,MAAM,GAAG,SAAS,CAGzE"}
package/dist/react.cjs CHANGED
@@ -106,10 +106,34 @@ var ORG_DOMAIN = Object.freeze({
106
106
  zoo: Object.freeze(["zoo.ngo", "zoo.network", "zoolabs.id", "zoolabs.io"])
107
107
  });
108
108
  var ORG_KEY = Object.freeze({
109
- hanzo: "pk-rM_CdaF2MQckGCrla113SrR1oH4zvqN8xh2I95Z9tY8",
109
+ hanzo: "pk-CmfLA2K6kvsPflrS9DSkt06H_kSoQB_21sjedt6VJdc",
110
110
  lux: "pk-gUZp6ZVfhJzSwK-rb4oLbVkpCnMBx5uSCpxf_5yEhQk",
111
111
  zoo: "pk-3TKpKnERV9AQSsBUERWkZejC1O1mUxc1jRzsP3MPbs4"
112
112
  });
113
+ var SITE_KEY = Object.freeze({
114
+ "hanzo.ai": "pk-CmfLA2K6kvsPflrS9DSkt06H_kSoQB_21sjedt6VJdc",
115
+ "www.hanzo.ai": "pk-CmfLA2K6kvsPflrS9DSkt06H_kSoQB_21sjedt6VJdc",
116
+ "hanzo.app": "pk-wlnXN2a9_vmCm60yTFtQ629Q8TyuaxBNZbY1RWT72gQ",
117
+ "hanzo.team": "pk-NCzD2FiHpZv8KUpkCX4olT1LJOJsMxBC_Z8NkiQsOFQ",
118
+ "pay.hanzo.ai": "pk-eX6kv7JZNoiYn1WkeJH3tT_8OvkVYScmCXnLMwxTKf8",
119
+ "platform.hanzo.ai": "pk-My1RpZLEUnTj8vAdPbWKYdDUuhxZJ4dVjHcwjZN4rZ8",
120
+ "docs.hanzo.ai": "pk-jukhtjMT2ymoeBDAeFjINQWlBv-v9sNn1TPztiCrrwk",
121
+ "hanzo.bot": "pk-W5d7Mn7ZukT7igyscIy6Pqe8JpA0Ge604Yn4xNR4JCU",
122
+ "hanzo.chat": "pk-ATxWeB2jNyRSxDgqnkGoDj3CCbzrmTxSktUh9zlrO-E",
123
+ "hanzo.id": "pk-_GVF3KlaqprlPHDumBMRFeFU1lIGOaarQfgimNVDIo8",
124
+ "hanzo.industries": "pk-Vh1wvL2HqIAv9qpVvmrznTI9uMHrTD-jyIC-vnlBsgY",
125
+ "hanzo.market": "pk-DN3xQFa0H61epUVg9OkiOYLzCdteNt9hE6f-S-ednjQ",
126
+ "hanzo.network": "pk-YJ2eiA_7ckLStMPte8Ar8FsmRp_ycmeIeRbpGprZYmM",
127
+ "hanzo.agency": "pk-26a2clOaJFe24aKJZ0PkI-GWR9F4EEa8rthHzgy_Efw",
128
+ "console.hanzo.ai": "pk-oFNXoiO1wOD8PqGdHYyiSq6jaNCdrd7TpztGpwM2ZiQ",
129
+ "admin.hanzo.ai": "pk-RYZwxkomW-tlAnEu2DKo_kAzcxFbSF2YiYcsUY48QL0",
130
+ "bot.hanzo.ai": "pk-W5d7Mn7ZukT7igyscIy6Pqe8JpA0Ge604Yn4xNR4JCU",
131
+ "cloud.hanzo.ai": "pk-RAfEGHPoNdCEU9fnA_cPd_Xo9Tci44rlYQV9xuJ1Ob0"
132
+ });
133
+ function siteKey(host) {
134
+ const h = normalize(host).replace(/^www\./, "");
135
+ return SITE_KEY[h] ?? (h.endsWith(".hanzo.app") ? SITE_KEY["hanzo.app"] : void 0);
136
+ }
113
137
  var PUBLISHABLE = "pk-";
114
138
  var normalize = (host) => host.trim().toLowerCase().replace(/\.$/, "").split(":")[0] ?? "";
115
139
  function orgOf(host) {
@@ -128,6 +152,10 @@ function orgOf(host) {
128
152
  return best;
129
153
  }
130
154
  function keyFor(host, keyring = ORG_KEY) {
155
+ if (keyring === ORG_KEY) {
156
+ const site = siteKey(host);
157
+ if (site) return site;
158
+ }
131
159
  const org = orgOf(host);
132
160
  if (!org) return void 0;
133
161
  const key = keyring[org];
@@ -623,7 +651,7 @@ function stripLink(href) {
623
651
  }
624
652
 
625
653
  // package.json
626
- var version = "0.3.49";
654
+ var version = "0.3.52";
627
655
 
628
656
  // src/version.ts
629
657
  var VERSION = version;
@@ -647,6 +675,7 @@ function normalizeError2(err) {
647
675
  const frames = framesFromStack(n.stack).slice(-50).map((f) => ({ function: f.function, file: f.filename, line: f.lineno, column: f.colno }));
648
676
  return { type: n.name, message: n.message, stack: n.stack, frames };
649
677
  }
678
+ var viewport = () => isBrowser() ? { screen: `${window.screen?.width ?? 0}x${window.screen?.height ?? 0}`, language: navigator.language || "" } : {};
650
679
  var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
651
680
  function serializeBatch(batch) {
652
681
  try {
@@ -681,13 +710,13 @@ var DefaultTransport = class {
681
710
  }
682
711
  }
683
712
  if (typeof fetch !== "function") return;
684
- const simple = opts.ingestKey !== void 0 && opts.contentType === void 0;
713
+ const simple = opts.ingestKey !== void 0 && opts.token === void 0 && opts.contentType === void 0;
685
714
  const headers = {
686
715
  "Content-Type": simple ? BEACON_CONTENT_TYPE : opts.contentType ?? "application/json"
687
716
  };
688
- const bearer = simple ? void 0 : opts.ingestKey ?? opts.token;
717
+ const bearer = simple ? void 0 : opts.token ?? opts.ingestKey;
689
718
  if (bearer) headers.Authorization = `Bearer ${bearer}`;
690
- void fetch(simple ? appendQuery(url, "ingest_key", opts.ingestKey) : url, {
719
+ void fetch(opts.ingestKey ? appendQuery(url, "ingest_key", opts.ingestKey) : url, {
691
720
  method: "POST",
692
721
  headers,
693
722
  body,
@@ -827,7 +856,7 @@ var Analytics = class {
827
856
  const view = (p ?? "") + "\0" + (isBrowser() ? window.location.href : "");
828
857
  if (view === this.counted) return;
829
858
  this.counted = view;
830
- this.enqueue("pageview", events.PAGEVIEW, { path: p, properties });
859
+ this.enqueue("pageview", events.PAGEVIEW, { path: p, properties: { ...viewport(), ...properties } });
831
860
  }
832
861
  /** capture records a named product event with optional properties. Commerce
833
862
  * fields (productId/quantity/revenue/currency) may be passed for order events. */
@@ -883,7 +912,7 @@ var Analytics = class {
883
912
  this.queue = [];
884
913
  this.clearTimer();
885
914
  const token = this.cfg.getToken?.() ?? void 0;
886
- const key = token ? void 0 : this.cfg.ingestKey?.trim() || void 0;
915
+ const key = this.cfg.ingestKey?.trim() || void 0;
887
916
  const useBeacon = beacon && !token;
888
917
  const body = serializeBatch(batch);
889
918
  if (body === null) {
@@ -993,18 +1022,13 @@ function get(name) {
993
1022
 
994
1023
  // src/consent.ts
995
1024
  var CONSENT_COOKIE = "hz_consent";
1025
+ var POLICY_EVENT = "hzpolicy";
996
1026
  var CONSENT_EVENT = "hzconsent";
997
1027
  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\/.*)$/;
998
1028
  function gpc() {
999
1029
  if (typeof navigator === "undefined") return false;
1000
1030
  return navigator.globalPrivacyControl === true;
1001
1031
  }
1002
- function refused() {
1003
- if (typeof window === "undefined") return false;
1004
- const n = navigator;
1005
- const dnt = n.doNotTrack ?? window.doNotTrack ?? n.msDoNotTrack;
1006
- return gpc() || dnt === "1" || dnt === "yes";
1007
- }
1008
1032
  function region() {
1009
1033
  try {
1010
1034
  const zone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
@@ -1013,9 +1037,13 @@ function region() {
1013
1037
  return "opt-in";
1014
1038
  }
1015
1039
  }
1040
+ function stored() {
1041
+ if (get(CONSENT_COOKIE) === void 0) return false;
1042
+ return true;
1043
+ }
1016
1044
  function read2() {
1017
- const kept = get(CONSENT_COOKIE);
1018
- const on = kept !== void 0 ? kept.split(",") : region() === "opt-in" || refused() ? [] : ["analytics", "marketing", "ads"];
1045
+ const kept = stored() ? get(CONSENT_COOKIE) : void 0;
1046
+ const on = kept !== void 0 ? kept.split(",") : region() === "opt-in" ? [] : gpc() ? ["analytics"] : ["analytics", "marketing", "ads"];
1019
1047
  const has = (k) => on.includes(k);
1020
1048
  return { analytics: has("analytics"), marketing: has("marketing") && !gpc(), ads: has("ads") && !gpc() };
1021
1049
  }
@@ -1079,7 +1107,11 @@ var ErrorBoundary = class extends react.Component {
1079
1107
  ErrorBoundary.contextType = Ctx;
1080
1108
  var listen = (on) => {
1081
1109
  window.addEventListener(CONSENT_EVENT, on);
1082
- return () => window.removeEventListener(CONSENT_EVENT, on);
1110
+ window.addEventListener(POLICY_EVENT, on);
1111
+ return () => {
1112
+ window.removeEventListener(CONSENT_EVENT, on);
1113
+ window.removeEventListener(POLICY_EVENT, on);
1114
+ };
1083
1115
  };
1084
1116
  function useConsent() {
1085
1117
  const kept = react.useSyncExternalStore(listen, () => render(read2()), () => "");