@hanzo/event 0.3.44 → 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/index.cjs +37 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +35 -7
- 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 +14 -1
- package/dist/tags.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/items.test.ts +22 -0
- package/src/items.ts +44 -0
- package/src/react.tsx +22 -0
- package/src/tags.test.ts +18 -0
- package/src/tags.ts +38 -5
package/dist/react.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
2
2
|
import { Analytics } from './core';
|
|
3
3
|
import type { AnalyticsConfig } from './types';
|
|
4
|
+
import { type Choice } from './consent';
|
|
4
5
|
declare const Ctx: import("react").Context<Analytics | null>;
|
|
5
6
|
export interface AnalyticsProviderProps {
|
|
6
7
|
/** Provide a pre-built client, or a config to build one. */
|
|
@@ -41,5 +42,12 @@ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBo
|
|
|
41
42
|
private reset;
|
|
42
43
|
render(): ReactNode;
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The visitor's consent, live: what a region presumes until they choose, then
|
|
47
|
+
* what they chose, re-rendering the moment they do. `enabled: choice.analytics`
|
|
48
|
+
* on the provider's config is how a stream that started silent for an EU visitor
|
|
49
|
+
* starts on Accept, with no reload.
|
|
50
|
+
*/
|
|
51
|
+
export declare function useConsent(): Choice;
|
|
44
52
|
export {};
|
|
45
53
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
2
2
|
import { Analytics } from './core';
|
|
3
3
|
import type { AnalyticsConfig } from './types';
|
|
4
|
+
import { type Choice } from './consent';
|
|
4
5
|
declare const Ctx: import("react").Context<Analytics | null>;
|
|
5
6
|
export interface AnalyticsProviderProps {
|
|
6
7
|
/** Provide a pre-built client, or a config to build one. */
|
|
@@ -41,5 +42,12 @@ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBo
|
|
|
41
42
|
private reset;
|
|
42
43
|
render(): ReactNode;
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The visitor's consent, live: what a region presumes until they choose, then
|
|
47
|
+
* what they chose, re-rendering the moment they do. `enabled: choice.analytics`
|
|
48
|
+
* on the provider's config is how a stream that started silent for an EU visitor
|
|
49
|
+
* starts on Accept, with no reload.
|
|
50
|
+
*/
|
|
51
|
+
export declare function useConsent(): Choice;
|
|
44
52
|
export {};
|
|
45
53
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAWA,OAAO,EACL,SAAS,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAWA,OAAO,EACL,SAAS,EAOT,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,SAAS,EAAmB,MAAM,QAAQ,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAA+B,KAAK,MAAM,EAAE,MAAM,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;;GAKG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAOnC"}
|
package/dist/react.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, Component, useEffect, createElement, useContext, useRef } from 'react';
|
|
1
|
+
import { createContext, Component, useEffect, createElement, useContext, useRef, useSyncExternalStore } from 'react';
|
|
2
2
|
import { PAGEVIEW, EXCEPTION } from '@hanzo/events';
|
|
3
3
|
|
|
4
4
|
// src/react.tsx
|
|
@@ -20,20 +20,20 @@ var SOCIAL_HOSTS = [
|
|
|
20
20
|
var SEARCH_HOSTS = ["google.", "bing.", "duckduckgo.", "yahoo.", "baidu.", "ecosia."];
|
|
21
21
|
function parseAttribution(search, referrer) {
|
|
22
22
|
const q = new URLSearchParams(search || "");
|
|
23
|
-
const
|
|
23
|
+
const get2 = (k) => {
|
|
24
24
|
const v = q.get(k);
|
|
25
25
|
return v ? v.trim() : void 0;
|
|
26
26
|
};
|
|
27
27
|
const a = {
|
|
28
28
|
utm: {
|
|
29
|
-
source:
|
|
30
|
-
medium:
|
|
31
|
-
campaign:
|
|
32
|
-
term:
|
|
33
|
-
content:
|
|
29
|
+
source: get2("utm_source"),
|
|
30
|
+
medium: get2("utm_medium"),
|
|
31
|
+
campaign: get2("utm_campaign"),
|
|
32
|
+
term: get2("utm_term"),
|
|
33
|
+
content: get2("utm_content")
|
|
34
34
|
},
|
|
35
35
|
referrer: referrer ? referrer.trim() : void 0,
|
|
36
|
-
refCode:
|
|
36
|
+
refCode: get2("ref") || get2("refCode") || get2("ref_code") || void 0
|
|
37
37
|
};
|
|
38
38
|
a.channel = deriveChannel(a);
|
|
39
39
|
return a;
|
|
@@ -395,7 +395,7 @@ function hzAnonAdopt(id) {
|
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
// package.json
|
|
398
|
-
var version = "0.3.
|
|
398
|
+
var version = "0.3.48";
|
|
399
399
|
|
|
400
400
|
// src/version.ts
|
|
401
401
|
var VERSION = version;
|
|
@@ -803,10 +803,10 @@ function linkUrl(url, state, fromHost, base) {
|
|
|
803
803
|
}
|
|
804
804
|
if (u.protocol !== "https:" && u.protocol !== "http:") return url;
|
|
805
805
|
if (!orgOf(u.hostname) || u.hostname === fromHost) return url;
|
|
806
|
-
const
|
|
807
|
-
if (isId(state.anonId))
|
|
808
|
-
if (isId(state.sessionId))
|
|
809
|
-
if (state.firstTouch)
|
|
806
|
+
const set2 = (k, v) => v && u.searchParams.set(k, v);
|
|
807
|
+
if (isId(state.anonId)) set2(LINK_PARAMS.anon, state.anonId);
|
|
808
|
+
if (isId(state.sessionId)) set2(LINK_PARAMS.session, state.sessionId);
|
|
809
|
+
if (state.firstTouch) set2(LINK_PARAMS.firstTouch, encodeFirstTouch(state.firstTouch));
|
|
810
810
|
return u.toString();
|
|
811
811
|
}
|
|
812
812
|
function readLink(search) {
|
|
@@ -1268,6 +1268,45 @@ function createAnalytics(config) {
|
|
|
1268
1268
|
return fresh;
|
|
1269
1269
|
}
|
|
1270
1270
|
|
|
1271
|
+
// src/cookie.ts
|
|
1272
|
+
function get(name) {
|
|
1273
|
+
if (typeof document === "undefined") return void 0;
|
|
1274
|
+
const hit = document.cookie.split("; ").find((c) => c.startsWith(`${name}=`));
|
|
1275
|
+
return hit ? decodeURIComponent(hit.slice(name.length + 1)) : void 0;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
// src/consent.ts
|
|
1279
|
+
var CONSENT_COOKIE = "hz_consent";
|
|
1280
|
+
var CONSENT_EVENT = "hzconsent";
|
|
1281
|
+
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\/.*)$/;
|
|
1282
|
+
function gpc() {
|
|
1283
|
+
if (typeof navigator === "undefined") return false;
|
|
1284
|
+
return navigator.globalPrivacyControl === true;
|
|
1285
|
+
}
|
|
1286
|
+
function refused() {
|
|
1287
|
+
if (typeof window === "undefined") return false;
|
|
1288
|
+
const n = navigator;
|
|
1289
|
+
const dnt = n.doNotTrack ?? window.doNotTrack ?? n.msDoNotTrack;
|
|
1290
|
+
return gpc() || dnt === "1" || dnt === "yes";
|
|
1291
|
+
}
|
|
1292
|
+
function region() {
|
|
1293
|
+
try {
|
|
1294
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
|
|
1295
|
+
return US.test(zone) ? "opt-out" : "opt-in";
|
|
1296
|
+
} catch {
|
|
1297
|
+
return "opt-in";
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
function read2() {
|
|
1301
|
+
const kept = get(CONSENT_COOKIE);
|
|
1302
|
+
const on = kept !== void 0 ? kept.split(",") : region() === "opt-in" || refused() ? [] : ["analytics", "marketing", "ads"];
|
|
1303
|
+
const has = (k) => on.includes(k);
|
|
1304
|
+
return { analytics: has("analytics"), marketing: has("marketing") && !gpc(), ads: has("ads") && !gpc() };
|
|
1305
|
+
}
|
|
1306
|
+
function render(c) {
|
|
1307
|
+
return ["analytics", "marketing", "ads"].filter((k) => c[k]).join(",");
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1271
1310
|
// src/react.tsx
|
|
1272
1311
|
var Ctx = createContext(null);
|
|
1273
1312
|
function AnalyticsProvider(props) {
|
|
@@ -1322,6 +1361,18 @@ var ErrorBoundary = class extends Component {
|
|
|
1322
1361
|
}
|
|
1323
1362
|
};
|
|
1324
1363
|
ErrorBoundary.contextType = Ctx;
|
|
1364
|
+
var listen = (on) => {
|
|
1365
|
+
window.addEventListener(CONSENT_EVENT, on);
|
|
1366
|
+
return () => window.removeEventListener(CONSENT_EVENT, on);
|
|
1367
|
+
};
|
|
1368
|
+
function useConsent() {
|
|
1369
|
+
const kept = useSyncExternalStore(listen, () => render(read2()), () => "");
|
|
1370
|
+
return {
|
|
1371
|
+
analytics: kept.includes("analytics"),
|
|
1372
|
+
marketing: kept.includes("marketing"),
|
|
1373
|
+
ads: kept.includes("ads")
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1325
1376
|
/*! anon.js — THE anonymous-identity chain. ONE implementation, two distributions.
|
|
1326
1377
|
*
|
|
1327
1378
|
* One browser is ONE person on every Hanzo surface, whichever client a page
|
|
@@ -1344,6 +1395,6 @@ ErrorBoundary.contextType = Ctx;
|
|
|
1344
1395
|
* curl -fsSL https://unpkg.com/@hanzo/event/src/anon.js -o apps/analytics/anon.js
|
|
1345
1396
|
*/
|
|
1346
1397
|
|
|
1347
|
-
export { AnalyticsProvider, ErrorBoundary, useAnalytics, usePageview };
|
|
1398
|
+
export { AnalyticsProvider, ErrorBoundary, useAnalytics, useConsent, usePageview };
|
|
1348
1399
|
//# sourceMappingURL=react.mjs.map
|
|
1349
1400
|
//# sourceMappingURL=react.mjs.map
|