@codefast/tracking 1.0.0-canary.6 → 1.0.0-canary.7
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/CHANGELOG.md +55 -0
- package/README.md +72 -17
- package/dist/adapters/tanstack-start.d.ts +80 -0
- package/dist/adapters/tanstack-start.d.ts.map +1 -0
- package/dist/adapters/tanstack-start.js +74 -0
- package/dist/adapters/tanstack-start.js.map +1 -0
- package/dist/client/ad-framework-consent.d.ts +62 -0
- package/dist/client/ad-framework-consent.d.ts.map +1 -0
- package/dist/client/ad-framework-consent.js +40 -0
- package/dist/client/ad-framework-consent.js.map +1 -0
- package/dist/client/{browser-cookie.d.mts → browser-cookie.d.ts} +2 -4
- package/dist/client/browser-cookie.d.ts.map +1 -0
- package/dist/client/browser-cookie.js +15 -0
- package/dist/client/browser-cookie.js.map +1 -0
- package/dist/client/consent-runtime.d.ts +53 -0
- package/dist/client/consent-runtime.d.ts.map +1 -0
- package/dist/client/consent-runtime.js +33 -0
- package/dist/client/consent-runtime.js.map +1 -0
- package/dist/client/{consent-storage.d.mts → consent-storage.d.ts} +3 -6
- package/dist/client/consent-storage.d.ts.map +1 -0
- package/dist/client/consent-storage.js +109 -0
- package/dist/client/consent-storage.js.map +1 -0
- package/dist/client/consent-withdrawal.d.ts +18 -0
- package/dist/client/consent-withdrawal.d.ts.map +1 -0
- package/dist/client/consent-withdrawal.js +17 -0
- package/dist/client/consent-withdrawal.js.map +1 -0
- package/dist/client/cookie-anonymous-id.d.ts +41 -0
- package/dist/client/cookie-anonymous-id.d.ts.map +1 -0
- package/dist/client/cookie-anonymous-id.js +65 -0
- package/dist/client/cookie-anonymous-id.js.map +1 -0
- package/dist/client/create-client-tracker.d.ts +60 -0
- package/dist/client/create-client-tracker.d.ts.map +1 -0
- package/dist/client/create-client-tracker.js +91 -0
- package/dist/client/create-client-tracker.js.map +1 -0
- package/dist/client/{gpc.d.mts → gpc.d.ts} +2 -4
- package/dist/client/gpc.d.ts.map +1 -0
- package/dist/client/gpc.js +12 -0
- package/dist/client/gpc.js.map +1 -0
- package/dist/client/initial-consent-store.d.ts +63 -0
- package/dist/client/initial-consent-store.d.ts.map +1 -0
- package/dist/client/initial-consent-store.js +138 -0
- package/dist/client/initial-consent-store.js.map +1 -0
- package/dist/client/is-analytics-allowed.d.ts +26 -0
- package/dist/client/is-analytics-allowed.d.ts.map +1 -0
- package/dist/client/is-analytics-allowed.js +22 -0
- package/dist/client/is-analytics-allowed.js.map +1 -0
- package/dist/client/server-persisted-anonymous-id.d.ts +30 -0
- package/dist/client/server-persisted-anonymous-id.d.ts.map +1 -0
- package/dist/client/server-persisted-anonymous-id.js +72 -0
- package/dist/client/server-persisted-anonymous-id.js.map +1 -0
- package/dist/core/consent-config.d.ts +24 -0
- package/dist/core/consent-config.d.ts.map +1 -0
- package/dist/core/consent-config.js +9 -0
- package/dist/core/consent-config.js.map +1 -0
- package/dist/core/consent-receipt.d.ts +71 -0
- package/dist/core/consent-receipt.d.ts.map +1 -0
- package/dist/core/consent-receipt.js +39 -0
- package/dist/core/consent-receipt.js.map +1 -0
- package/dist/core/{consent.d.mts → consent.d.ts} +49 -51
- package/dist/core/consent.d.ts.map +1 -0
- package/dist/core/consent.js +159 -0
- package/dist/core/consent.js.map +1 -0
- package/dist/core/{cookie.d.mts → cookie.d.ts} +3 -5
- package/dist/core/cookie.d.ts.map +1 -0
- package/dist/core/cookie.js +26 -0
- package/dist/core/cookie.js.map +1 -0
- package/dist/core/destination.d.ts +29 -0
- package/dist/core/destination.d.ts.map +1 -0
- package/dist/core/destination.js +2 -0
- package/dist/core/destination.js.map +1 -0
- package/dist/core/event-catalog.d.ts +35 -0
- package/dist/core/event-catalog.d.ts.map +1 -0
- package/dist/core/event-catalog.js +30 -0
- package/dist/core/event-catalog.js.map +1 -0
- package/dist/core/{event-id.d.mts → event-id.d.ts} +2 -4
- package/dist/core/event-id.d.ts.map +1 -0
- package/dist/core/event-id.js +9 -0
- package/dist/core/event-id.js.map +1 -0
- package/dist/core/tracked-event.d.ts +15 -0
- package/dist/core/tracked-event.d.ts.map +1 -0
- package/dist/core/tracked-event.js +2 -0
- package/dist/core/tracked-event.js.map +1 -0
- package/dist/destinations/ad-consent.d.ts +23 -0
- package/dist/destinations/ad-consent.d.ts.map +1 -0
- package/dist/destinations/ad-consent.js +12 -0
- package/dist/destinations/ad-consent.js.map +1 -0
- package/dist/destinations/google-analytics.d.ts +148 -0
- package/dist/destinations/google-analytics.d.ts.map +1 -0
- package/dist/destinations/google-analytics.js +156 -0
- package/dist/destinations/google-analytics.js.map +1 -0
- package/dist/destinations/google-consent.d.ts +62 -0
- package/dist/destinations/google-consent.d.ts.map +1 -0
- package/dist/destinations/google-consent.js +109 -0
- package/dist/destinations/google-consent.js.map +1 -0
- package/dist/destinations/meta.d.ts +63 -0
- package/dist/destinations/meta.d.ts.map +1 -0
- package/dist/destinations/meta.js +44 -0
- package/dist/destinations/meta.js.map +1 -0
- package/dist/destinations/microsoft-uet.d.ts +56 -0
- package/dist/destinations/microsoft-uet.d.ts.map +1 -0
- package/dist/destinations/microsoft-uet.js +41 -0
- package/dist/destinations/microsoft-uet.js.map +1 -0
- package/dist/destinations/shared.d.ts +18 -0
- package/dist/destinations/shared.d.ts.map +1 -0
- package/dist/destinations/shared.js +19 -0
- package/dist/destinations/shared.js.map +1 -0
- package/dist/destinations/tiktok.d.ts +55 -0
- package/dist/destinations/tiktok.d.ts.map +1 -0
- package/dist/destinations/tiktok.js +40 -0
- package/dist/destinations/tiktok.js.map +1 -0
- package/dist/destinations/vercel-analytics.d.ts +25 -0
- package/dist/destinations/vercel-analytics.d.ts.map +1 -0
- package/dist/destinations/vercel-analytics.js +23 -0
- package/dist/destinations/vercel-analytics.js.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/react/consent-banner.d.ts +155 -0
- package/dist/react/consent-banner.d.ts.map +1 -0
- package/dist/react/consent-banner.js +171 -0
- package/dist/react/consent-banner.js.map +1 -0
- package/dist/react/gtag-consent-bootstrap.d.ts +17 -0
- package/dist/react/gtag-consent-bootstrap.d.ts.map +1 -0
- package/dist/react/gtag-consent-bootstrap.js +22 -0
- package/dist/react/gtag-consent-bootstrap.js.map +1 -0
- package/dist/react/use-consent.d.ts +42 -0
- package/dist/react/use-consent.d.ts.map +1 -0
- package/dist/react/use-consent.js +60 -0
- package/dist/react/use-consent.js.map +1 -0
- package/dist/react/use-google-consent-sync.d.ts +20 -0
- package/dist/react/use-google-consent-sync.d.ts.map +1 -0
- package/dist/react/use-google-consent-sync.js +22 -0
- package/dist/react/use-google-consent-sync.js.map +1 -0
- package/dist/react/{use-initial-consent.d.mts → use-initial-consent.d.ts} +3 -6
- package/dist/react/use-initial-consent.d.ts.map +1 -0
- package/dist/react/use-initial-consent.js +18 -0
- package/dist/react/use-initial-consent.js.map +1 -0
- package/dist/server/anonymous-id-cookie.d.ts +67 -0
- package/dist/server/anonymous-id-cookie.d.ts.map +1 -0
- package/dist/server/anonymous-id-cookie.js +71 -0
- package/dist/server/anonymous-id-cookie.js.map +1 -0
- package/dist/server/consent-receipt-store.d.ts +56 -0
- package/dist/server/consent-receipt-store.d.ts.map +1 -0
- package/dist/server/consent-receipt-store.js +44 -0
- package/dist/server/consent-receipt-store.js.map +1 -0
- package/dist/server/consent-receipt.d.ts +41 -0
- package/dist/server/consent-receipt.d.ts.map +1 -0
- package/dist/server/consent-receipt.js +60 -0
- package/dist/server/consent-receipt.js.map +1 -0
- package/dist/server/initial-consent.d.ts +26 -0
- package/dist/server/initial-consent.d.ts.map +1 -0
- package/dist/server/initial-consent.js +31 -0
- package/dist/server/initial-consent.js.map +1 -0
- package/dist/server/measurement-protocol.d.ts +69 -0
- package/dist/server/measurement-protocol.d.ts.map +1 -0
- package/dist/server/measurement-protocol.js +61 -0
- package/dist/server/measurement-protocol.js.map +1 -0
- package/dist/server/{region.d.mts → region.d.ts} +5 -15
- package/dist/server/region.d.ts.map +1 -0
- package/dist/server/region.js +69 -0
- package/dist/server/region.js.map +1 -0
- package/dist/server/user-deletion.d.ts +64 -0
- package/dist/server/user-deletion.d.ts.map +1 -0
- package/dist/server/user-deletion.js +54 -0
- package/dist/server/user-deletion.js.map +1 -0
- package/dist/tooling/import-protection.d.ts +19 -0
- package/dist/tooling/import-protection.d.ts.map +1 -0
- package/dist/tooling/import-protection.js +23 -0
- package/dist/tooling/import-protection.js.map +1 -0
- package/package.json +238 -59
- package/src/adapters/tanstack-start.ts +135 -0
- package/src/client/ad-framework-consent.ts +86 -0
- package/src/client/cookie-anonymous-id.ts +19 -0
- package/src/client/create-client-tracker.ts +81 -10
- package/src/client/server-persisted-anonymous-id.ts +4 -1
- package/src/core/consent-receipt.ts +115 -0
- package/src/core/consent.ts +2 -2
- package/src/core/destination.ts +7 -0
- package/src/core/event-catalog.ts +5 -4
- package/src/core/tracked-event.ts +5 -20
- package/src/destinations/ad-consent.ts +29 -0
- package/src/destinations/meta.ts +96 -0
- package/src/destinations/microsoft-uet.ts +86 -0
- package/src/destinations/tiktok.ts +85 -0
- package/src/index.ts +138 -19
- package/src/server/anonymous-id-cookie.ts +49 -22
- package/src/server/consent-receipt-store.ts +79 -0
- package/src/server/consent-receipt.ts +89 -0
- package/src/server/initial-consent.ts +0 -2
- package/src/server/measurement-protocol.ts +114 -0
- package/src/server/region.ts +0 -10
- package/src/server/user-deletion.ts +93 -0
- package/src/tooling/import-protection.ts +22 -0
- package/dist/client/browser-cookie.mjs +0 -15
- package/dist/client/consent-runtime.d.mts +0 -56
- package/dist/client/consent-runtime.mjs +0 -35
- package/dist/client/consent-storage.mjs +0 -82
- package/dist/client/consent-withdrawal.d.mts +0 -21
- package/dist/client/consent-withdrawal.mjs +0 -17
- package/dist/client/cookie-anonymous-id.d.mts +0 -37
- package/dist/client/cookie-anonymous-id.mjs +0 -46
- package/dist/client/create-client-tracker.d.mts +0 -32
- package/dist/client/create-client-tracker.mjs +0 -40
- package/dist/client/gpc.mjs +0 -14
- package/dist/client/index.d.mts +0 -10
- package/dist/client/index.mjs +0 -10
- package/dist/client/initial-consent-store.d.mts +0 -66
- package/dist/client/initial-consent-store.mjs +0 -119
- package/dist/client/is-analytics-allowed.d.mts +0 -29
- package/dist/client/is-analytics-allowed.mjs +0 -23
- package/dist/client/server-persisted-anonymous-id.d.mts +0 -33
- package/dist/client/server-persisted-anonymous-id.mjs +0 -50
- package/dist/core/consent-config.d.mts +0 -27
- package/dist/core/consent-config.mjs +0 -11
- package/dist/core/consent.mjs +0 -152
- package/dist/core/cookie.mjs +0 -23
- package/dist/core/destination.d.mts +0 -25
- package/dist/core/destination.mjs +0 -1
- package/dist/core/event-catalog.d.mts +0 -39
- package/dist/core/event-catalog.mjs +0 -30
- package/dist/core/event-id.mjs +0 -11
- package/dist/core/index.d.mts +0 -8
- package/dist/core/index.mjs +0 -6
- package/dist/core/tracked-event.d.mts +0 -30
- package/dist/core/tracked-event.mjs +0 -1
- package/dist/destinations/google-analytics.d.mts +0 -150
- package/dist/destinations/google-analytics.mjs +0 -130
- package/dist/destinations/google-consent.d.mts +0 -64
- package/dist/destinations/google-consent.mjs +0 -102
- package/dist/destinations/index.d.mts +0 -2
- package/dist/destinations/index.mjs +0 -2
- package/dist/destinations/shared.d.mts +0 -20
- package/dist/destinations/shared.mjs +0 -13
- package/dist/destinations/vercel-analytics.d.mts +0 -28
- package/dist/destinations/vercel-analytics.mjs +0 -23
- package/dist/import-protection.d.mts +0 -19
- package/dist/import-protection.mjs +0 -23
- package/dist/index.d.mts +0 -8
- package/dist/index.mjs +0 -6
- package/dist/react/consent-banner.d.mts +0 -180
- package/dist/react/consent-banner.mjs +0 -214
- package/dist/react/gtag-consent-bootstrap.d.mts +0 -27
- package/dist/react/gtag-consent-bootstrap.mjs +0 -29
- package/dist/react/index.d.mts +0 -6
- package/dist/react/index.mjs +0 -6
- package/dist/react/use-consent.d.mts +0 -45
- package/dist/react/use-consent.mjs +0 -71
- package/dist/react/use-google-consent-sync.d.mts +0 -23
- package/dist/react/use-google-consent-sync.mjs +0 -24
- package/dist/react/use-initial-consent.mjs +0 -19
- package/dist/server/anonymous-id-cookie.d.mts +0 -46
- package/dist/server/anonymous-id-cookie.mjs +0 -51
- package/dist/server/index.d.mts +0 -5
- package/dist/server/index.mjs +0 -4
- package/dist/server/initial-consent.d.mts +0 -29
- package/dist/server/initial-consent.mjs +0 -31
- package/dist/server/region.mjs +0 -77
- package/dist/tanstack-start/index.d.mts +0 -58
- package/dist/tanstack-start/index.mjs +0 -45
- package/src/client/index.ts +0 -28
- package/src/core/index.ts +0 -40
- package/src/destinations/index.ts +0 -19
- package/src/import-protection.ts +0 -20
- package/src/react/index.ts +0 -37
- package/src/server/index.ts +0 -16
- package/src/tanstack-start/index.ts +0 -83
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { ConsentCategory } from "../core/consent.mjs";
|
|
2
|
-
import { UseConsentResult } from "./use-consent.mjs";
|
|
3
|
-
import { ComponentProps, ReactNode } from "react";
|
|
4
|
-
|
|
5
|
-
//#region src/react/consent-banner.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* @since 0.5.0-canary.4
|
|
8
|
-
*/
|
|
9
|
-
interface ConsentBannerProps extends ComponentProps<"section"> {
|
|
10
|
-
consent: UseConsentResult;
|
|
11
|
-
/** Overrides the default `isPromptNeeded` gating — e.g. to reopen the banner as a settings panel. */
|
|
12
|
-
open?: boolean | undefined;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Non-blocking opt-in prompt for GDPR/PDPL (VN) regions, as composable parts — the root owns
|
|
16
|
-
* the visibility gating and the preferences-layer state; the `Accept`/`Reject`/`Customize`/
|
|
17
|
-
* `Save` parts wire their own clicks to the consent hook, so any markup (including a
|
|
18
|
-
* design system's button styles via `className`) slots in. Renders nothing once a decision
|
|
19
|
-
* exists or the region defaults to opt-out (`consent.isPromptNeeded`), unless `open` says
|
|
20
|
-
* otherwise. Rendered as a labeled region, not a `<dialog>`: an open non-modal dialog
|
|
21
|
-
* neither traps focus nor blocks the page, so the dialog semantics would over-promise.
|
|
22
|
-
* Unstyled by default — style via `className`/`data-slot` selectors, or import the
|
|
23
|
-
* optional `@codefast/tracking/css/consent.css` theme. `data-state` on the root flips
|
|
24
|
-
* between `prompt` and `preferences` for state-dependent styling.
|
|
25
|
-
*
|
|
26
|
-
* @since 0.5.0-canary.4
|
|
27
|
-
*/
|
|
28
|
-
declare function ConsentBanner({
|
|
29
|
-
children,
|
|
30
|
-
consent,
|
|
31
|
-
open,
|
|
32
|
-
...props
|
|
33
|
-
}: ConsentBannerProps): ReactNode;
|
|
34
|
-
/**
|
|
35
|
-
* @since 0.5.0-canary.5
|
|
36
|
-
*/
|
|
37
|
-
interface ConsentBannerTitleProps extends ComponentProps<"h2"> {}
|
|
38
|
-
/**
|
|
39
|
-
* @since 0.5.0-canary.5
|
|
40
|
-
*/
|
|
41
|
-
declare function ConsentBannerTitle({
|
|
42
|
-
children,
|
|
43
|
-
...props
|
|
44
|
-
}: ConsentBannerTitleProps): ReactNode;
|
|
45
|
-
/**
|
|
46
|
-
* @since 0.5.0-canary.5
|
|
47
|
-
*/
|
|
48
|
-
interface ConsentBannerDescriptionProps extends ComponentProps<"p"> {}
|
|
49
|
-
/**
|
|
50
|
-
* Hosts the message and the privacy-policy link informed consent requires.
|
|
51
|
-
*
|
|
52
|
-
* @since 0.5.0-canary.5
|
|
53
|
-
*/
|
|
54
|
-
declare function ConsentBannerDescription(props: ConsentBannerDescriptionProps): ReactNode;
|
|
55
|
-
/**
|
|
56
|
-
* @since 0.5.0-canary.5
|
|
57
|
-
*/
|
|
58
|
-
interface ConsentBannerActionsProps extends ComponentProps<"div"> {}
|
|
59
|
-
/**
|
|
60
|
-
* @since 0.5.0-canary.5
|
|
61
|
-
*/
|
|
62
|
-
declare function ConsentBannerActions(props: ConsentBannerActionsProps): ReactNode;
|
|
63
|
-
/**
|
|
64
|
-
* @since 0.5.0-canary.5
|
|
65
|
-
*/
|
|
66
|
-
interface ConsentBannerAcceptProps extends Omit<ComponentProps<"button">, "type"> {}
|
|
67
|
-
/**
|
|
68
|
-
* Grants the categories the app requested (`useConsent`'s `requestedCategories`) — never more.
|
|
69
|
-
*
|
|
70
|
-
* @since 0.5.0-canary.5
|
|
71
|
-
*/
|
|
72
|
-
declare function ConsentBannerAccept({
|
|
73
|
-
onClick,
|
|
74
|
-
...props
|
|
75
|
-
}: ConsentBannerAcceptProps): ReactNode;
|
|
76
|
-
/**
|
|
77
|
-
* @since 0.5.0-canary.5
|
|
78
|
-
*/
|
|
79
|
-
interface ConsentBannerRejectProps extends Omit<ComponentProps<"button">, "type"> {}
|
|
80
|
-
/**
|
|
81
|
-
* @since 0.5.0-canary.5
|
|
82
|
-
*/
|
|
83
|
-
declare function ConsentBannerReject({
|
|
84
|
-
onClick,
|
|
85
|
-
...props
|
|
86
|
-
}: ConsentBannerRejectProps): ReactNode;
|
|
87
|
-
/**
|
|
88
|
-
* @since 0.5.0-canary.5
|
|
89
|
-
*/
|
|
90
|
-
interface ConsentBannerCustomizeProps extends Omit<ComponentProps<"button">, "type"> {}
|
|
91
|
-
/**
|
|
92
|
-
* Opens the per-category preferences layer, starting from the current effective state so
|
|
93
|
-
* nothing arrives pre-ticked in an opt-in region (pre-ticked consent is invalid under
|
|
94
|
-
* GDPR). Hidden while the layer is open — `ConsentBannerSave` takes over.
|
|
95
|
-
*
|
|
96
|
-
* @since 0.5.0-canary.5
|
|
97
|
-
*/
|
|
98
|
-
declare function ConsentBannerCustomize({
|
|
99
|
-
onClick,
|
|
100
|
-
...props
|
|
101
|
-
}: ConsentBannerCustomizeProps): ReactNode;
|
|
102
|
-
/**
|
|
103
|
-
* @since 0.5.0-canary.5
|
|
104
|
-
*/
|
|
105
|
-
interface ConsentBannerPreferencesProps extends ComponentProps<"div"> {}
|
|
106
|
-
/**
|
|
107
|
-
* Container for the per-category rows — renders only while the preferences layer is open.
|
|
108
|
-
*
|
|
109
|
-
* @since 0.5.0-canary.5
|
|
110
|
-
*/
|
|
111
|
-
declare function ConsentBannerPreferences(props: ConsentBannerPreferencesProps): ReactNode;
|
|
112
|
-
/**
|
|
113
|
-
* @since 0.5.0-canary.5
|
|
114
|
-
*/
|
|
115
|
-
interface ConsentBannerCategoryProps extends ComponentProps<"label"> {
|
|
116
|
-
category: ConsentCategory;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* One checkbox row of the preferences layer — `children` is the visitor-facing wording.
|
|
120
|
-
*
|
|
121
|
-
* @since 0.5.0-canary.5
|
|
122
|
-
*/
|
|
123
|
-
declare function ConsentBannerCategory({
|
|
124
|
-
category,
|
|
125
|
-
children,
|
|
126
|
-
...props
|
|
127
|
-
}: ConsentBannerCategoryProps): ReactNode;
|
|
128
|
-
/**
|
|
129
|
-
* @since 0.5.0-canary.5
|
|
130
|
-
*/
|
|
131
|
-
interface ConsentBannerSaveProps extends Omit<ComponentProps<"button">, "type"> {}
|
|
132
|
-
/**
|
|
133
|
-
* Persists the pending per-category selection — renders only while the preferences layer is open.
|
|
134
|
-
*
|
|
135
|
-
* @since 0.5.0-canary.5
|
|
136
|
-
*/
|
|
137
|
-
declare function ConsentBannerSave({
|
|
138
|
-
onClick,
|
|
139
|
-
...props
|
|
140
|
-
}: ConsentBannerSaveProps): ReactNode;
|
|
141
|
-
/**
|
|
142
|
-
* @since 0.5.0-canary.4
|
|
143
|
-
*/
|
|
144
|
-
interface ConsentToggleProps extends Omit<ComponentProps<"button">, "children" | "onClick" | "type"> {
|
|
145
|
-
/**
|
|
146
|
-
* Label shown while the scoped categories are denied — clicking grants them. Defaults
|
|
147
|
-
* to "Allow tracking".
|
|
148
|
-
*/
|
|
149
|
-
allowLabel?: string | undefined;
|
|
150
|
-
consent: UseConsentResult;
|
|
151
|
-
/**
|
|
152
|
-
* Label shown while any scoped category is granted — clicking denies them. Defaults to
|
|
153
|
-
* CCPA/CPRA "Do Not Sell or Share My Personal Information".
|
|
154
|
-
*/
|
|
155
|
-
denyLabel?: string | undefined;
|
|
156
|
-
/**
|
|
157
|
-
* Purposes this control flips. Defaults to `["ads"]` — CCPA/CPRA "Do Not Sell or Share"
|
|
158
|
-
* mirrors GPC (ads denied, first-party analytics left alone). Pass `["analytics"]` (or
|
|
159
|
-
* both) for a broader opt-out. Distinct from `useConsent`'s `requestedCategories` (what the
|
|
160
|
-
* prompt asks about / `grantAll` grants).
|
|
161
|
-
*/
|
|
162
|
-
toggledCategories?: ReadonlyArray<ConsentCategory> | undefined;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Always-visible control for opt-out regions — CCPA/CPRA requires a persistent
|
|
166
|
-
* "Do Not Sell or Share My Personal Information" mechanism, not just a one-time prompt.
|
|
167
|
-
* By default it only flips `ads` (same scope as a GPC signal); pass `toggledCategories`
|
|
168
|
-
* to include analytics or both.
|
|
169
|
-
*
|
|
170
|
-
* @since 0.5.0-canary.4
|
|
171
|
-
*/
|
|
172
|
-
declare function ConsentToggle({
|
|
173
|
-
allowLabel,
|
|
174
|
-
consent,
|
|
175
|
-
denyLabel,
|
|
176
|
-
toggledCategories,
|
|
177
|
-
...props
|
|
178
|
-
}: ConsentToggleProps): ReactNode;
|
|
179
|
-
//#endregion
|
|
180
|
-
export { ConsentBanner, ConsentBannerAccept, ConsentBannerAcceptProps, ConsentBannerActions, ConsentBannerActionsProps, ConsentBannerCategory, ConsentBannerCategoryProps, ConsentBannerCustomize, ConsentBannerCustomizeProps, ConsentBannerDescription, ConsentBannerDescriptionProps, ConsentBannerPreferences, ConsentBannerPreferencesProps, ConsentBannerProps, ConsentBannerReject, ConsentBannerRejectProps, ConsentBannerSave, ConsentBannerSaveProps, ConsentBannerTitle, ConsentBannerTitleProps, ConsentToggle, ConsentToggleProps };
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
//#region src/react/consent-banner.tsx
|
|
5
|
-
const ConsentBannerContext = createContext(null);
|
|
6
|
-
function useConsentBannerContext(part) {
|
|
7
|
-
const context = useContext(ConsentBannerContext);
|
|
8
|
-
if (context === null) throw new Error(`\`${part}\` must be rendered inside \`ConsentBanner\``);
|
|
9
|
-
return context;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Non-blocking opt-in prompt for GDPR/PDPL (VN) regions, as composable parts — the root owns
|
|
13
|
-
* the visibility gating and the preferences-layer state; the `Accept`/`Reject`/`Customize`/
|
|
14
|
-
* `Save` parts wire their own clicks to the consent hook, so any markup (including a
|
|
15
|
-
* design system's button styles via `className`) slots in. Renders nothing once a decision
|
|
16
|
-
* exists or the region defaults to opt-out (`consent.isPromptNeeded`), unless `open` says
|
|
17
|
-
* otherwise. Rendered as a labeled region, not a `<dialog>`: an open non-modal dialog
|
|
18
|
-
* neither traps focus nor blocks the page, so the dialog semantics would over-promise.
|
|
19
|
-
* Unstyled by default — style via `className`/`data-slot` selectors, or import the
|
|
20
|
-
* optional `@codefast/tracking/css/consent.css` theme. `data-state` on the root flips
|
|
21
|
-
* between `prompt` and `preferences` for state-dependent styling.
|
|
22
|
-
*
|
|
23
|
-
* @since 0.5.0-canary.4
|
|
24
|
-
*/
|
|
25
|
-
function ConsentBanner({ children, consent, open, ...props }) {
|
|
26
|
-
const [pending, setPending] = useState(void 0);
|
|
27
|
-
const isVisible = open ?? consent.isPromptNeeded;
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!isVisible) setPending(void 0);
|
|
30
|
-
}, [isVisible]);
|
|
31
|
-
if (!isVisible) return null;
|
|
32
|
-
return /* @__PURE__ */ jsx(ConsentBannerContext.Provider, {
|
|
33
|
-
value: {
|
|
34
|
-
consent,
|
|
35
|
-
pending,
|
|
36
|
-
setPending
|
|
37
|
-
},
|
|
38
|
-
children: /* @__PURE__ */ jsx("section", {
|
|
39
|
-
"aria-label": "Cookie consent",
|
|
40
|
-
"data-slot": "consent-banner",
|
|
41
|
-
"data-state": pending === void 0 ? "prompt" : "preferences",
|
|
42
|
-
...props,
|
|
43
|
-
children
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @since 0.5.0-canary.5
|
|
49
|
-
*/
|
|
50
|
-
function ConsentBannerTitle({ children, ...props }) {
|
|
51
|
-
return /* @__PURE__ */ jsx("h2", {
|
|
52
|
-
"data-slot": "consent-title",
|
|
53
|
-
...props,
|
|
54
|
-
children
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Hosts the message and the privacy-policy link informed consent requires.
|
|
59
|
-
*
|
|
60
|
-
* @since 0.5.0-canary.5
|
|
61
|
-
*/
|
|
62
|
-
function ConsentBannerDescription(props) {
|
|
63
|
-
return /* @__PURE__ */ jsx("p", {
|
|
64
|
-
"data-slot": "consent-description",
|
|
65
|
-
...props
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @since 0.5.0-canary.5
|
|
70
|
-
*/
|
|
71
|
-
function ConsentBannerActions(props) {
|
|
72
|
-
return /* @__PURE__ */ jsx("div", {
|
|
73
|
-
"data-slot": "consent-actions",
|
|
74
|
-
...props
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Grants the categories the app requested (`useConsent`'s `requestedCategories`) — never more.
|
|
79
|
-
*
|
|
80
|
-
* @since 0.5.0-canary.5
|
|
81
|
-
*/
|
|
82
|
-
function ConsentBannerAccept({ onClick, ...props }) {
|
|
83
|
-
const { consent, setPending } = useConsentBannerContext("ConsentBannerAccept");
|
|
84
|
-
return /* @__PURE__ */ jsx("button", {
|
|
85
|
-
"data-action": "accept",
|
|
86
|
-
"data-slot": "consent-action",
|
|
87
|
-
...props,
|
|
88
|
-
onClick: (event) => {
|
|
89
|
-
onClick?.(event);
|
|
90
|
-
consent.grantAll();
|
|
91
|
-
setPending(void 0);
|
|
92
|
-
},
|
|
93
|
-
type: "button"
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* @since 0.5.0-canary.5
|
|
98
|
-
*/
|
|
99
|
-
function ConsentBannerReject({ onClick, ...props }) {
|
|
100
|
-
const { consent, setPending } = useConsentBannerContext("ConsentBannerReject");
|
|
101
|
-
return /* @__PURE__ */ jsx("button", {
|
|
102
|
-
"data-action": "reject",
|
|
103
|
-
"data-slot": "consent-action",
|
|
104
|
-
...props,
|
|
105
|
-
onClick: (event) => {
|
|
106
|
-
onClick?.(event);
|
|
107
|
-
consent.denyAll();
|
|
108
|
-
setPending(void 0);
|
|
109
|
-
},
|
|
110
|
-
type: "button"
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Opens the per-category preferences layer, starting from the current effective state so
|
|
115
|
-
* nothing arrives pre-ticked in an opt-in region (pre-ticked consent is invalid under
|
|
116
|
-
* GDPR). Hidden while the layer is open — `ConsentBannerSave` takes over.
|
|
117
|
-
*
|
|
118
|
-
* @since 0.5.0-canary.5
|
|
119
|
-
*/
|
|
120
|
-
function ConsentBannerCustomize({ onClick, ...props }) {
|
|
121
|
-
const { consent, pending, setPending } = useConsentBannerContext("ConsentBannerCustomize");
|
|
122
|
-
if (pending !== void 0) return null;
|
|
123
|
-
return /* @__PURE__ */ jsx("button", {
|
|
124
|
-
"data-action": "customize",
|
|
125
|
-
"data-slot": "consent-action",
|
|
126
|
-
...props,
|
|
127
|
-
onClick: (event) => {
|
|
128
|
-
onClick?.(event);
|
|
129
|
-
setPending(consent.effectiveConsent);
|
|
130
|
-
},
|
|
131
|
-
type: "button"
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Container for the per-category rows — renders only while the preferences layer is open.
|
|
136
|
-
*
|
|
137
|
-
* @since 0.5.0-canary.5
|
|
138
|
-
*/
|
|
139
|
-
function ConsentBannerPreferences(props) {
|
|
140
|
-
const { pending } = useConsentBannerContext("ConsentBannerPreferences");
|
|
141
|
-
if (pending === void 0) return null;
|
|
142
|
-
return /* @__PURE__ */ jsx("div", {
|
|
143
|
-
"data-slot": "consent-preferences",
|
|
144
|
-
...props
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* One checkbox row of the preferences layer — `children` is the visitor-facing wording.
|
|
149
|
-
*
|
|
150
|
-
* @since 0.5.0-canary.5
|
|
151
|
-
*/
|
|
152
|
-
function ConsentBannerCategory({ category, children, ...props }) {
|
|
153
|
-
const { pending, setPending } = useConsentBannerContext("ConsentBannerCategory");
|
|
154
|
-
if (pending === void 0) return null;
|
|
155
|
-
return /* @__PURE__ */ jsxs("label", {
|
|
156
|
-
"data-slot": "consent-category",
|
|
157
|
-
...props,
|
|
158
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
159
|
-
checked: pending[category],
|
|
160
|
-
"data-slot": "consent-category-checkbox",
|
|
161
|
-
onChange: (event) => {
|
|
162
|
-
setPending({
|
|
163
|
-
...pending,
|
|
164
|
-
[category]: event.target.checked
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
type: "checkbox"
|
|
168
|
-
}), children]
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Persists the pending per-category selection — renders only while the preferences layer is open.
|
|
173
|
-
*
|
|
174
|
-
* @since 0.5.0-canary.5
|
|
175
|
-
*/
|
|
176
|
-
function ConsentBannerSave({ onClick, ...props }) {
|
|
177
|
-
const { consent, pending, setPending } = useConsentBannerContext("ConsentBannerSave");
|
|
178
|
-
if (pending === void 0) return null;
|
|
179
|
-
return /* @__PURE__ */ jsx("button", {
|
|
180
|
-
"data-action": "save",
|
|
181
|
-
"data-slot": "consent-action",
|
|
182
|
-
...props,
|
|
183
|
-
onClick: (event) => {
|
|
184
|
-
onClick?.(event);
|
|
185
|
-
consent.saveDecision(pending);
|
|
186
|
-
setPending(void 0);
|
|
187
|
-
},
|
|
188
|
-
type: "button"
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Always-visible control for opt-out regions — CCPA/CPRA requires a persistent
|
|
193
|
-
* "Do Not Sell or Share My Personal Information" mechanism, not just a one-time prompt.
|
|
194
|
-
* By default it only flips `ads` (same scope as a GPC signal); pass `toggledCategories`
|
|
195
|
-
* to include analytics or both.
|
|
196
|
-
*
|
|
197
|
-
* @since 0.5.0-canary.4
|
|
198
|
-
*/
|
|
199
|
-
function ConsentToggle({ allowLabel = "Allow tracking", consent, denyLabel = "Do Not Sell or Share My Personal Information", toggledCategories = ["ads"], ...props }) {
|
|
200
|
-
const isAnyCategoryGranted = toggledCategories.some((category) => consent.effectiveConsent[category]);
|
|
201
|
-
return /* @__PURE__ */ jsx("button", {
|
|
202
|
-
"data-slot": "consent-toggle",
|
|
203
|
-
...props,
|
|
204
|
-
onClick: () => {
|
|
205
|
-
const next = { ...consent.effectiveConsent };
|
|
206
|
-
for (const category of toggledCategories) next[category] = !isAnyCategoryGranted;
|
|
207
|
-
consent.saveDecision(next);
|
|
208
|
-
},
|
|
209
|
-
type: "button",
|
|
210
|
-
children: isAnyCategoryGranted ? denyLabel : allowLabel
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
//#endregion
|
|
214
|
-
export { ConsentBanner, ConsentBannerAccept, ConsentBannerActions, ConsentBannerCategory, ConsentBannerCustomize, ConsentBannerDescription, ConsentBannerPreferences, ConsentBannerReject, ConsentBannerSave, ConsentBannerTitle, ConsentToggle };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { GtagConsentBootstrapOptions } from "../destinations/google-analytics.mjs";
|
|
2
|
-
import { ComponentProps, ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
//#region src/react/gtag-consent-bootstrap.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* @since 1.0.0-canary.6
|
|
7
|
-
*/
|
|
8
|
-
interface GtagConsentBootstrapProps extends Omit<ComponentProps<"script">, "children" | "dangerouslySetInnerHTML" | "nonce" | "src" | "type">, GtagConsentBootstrapOptions {}
|
|
9
|
-
/**
|
|
10
|
-
* Framework-agnostic inline `<script>` that runs `buildGtagConsentBootstrapScript` before
|
|
11
|
-
* hydration. Pass the same `nonce` here and in `loadGtagScript` for CSP; this component
|
|
12
|
-
* only sets the attribute on the host script — the generated source also stamps it onto
|
|
13
|
-
* the injected gtag.js tag when `nonce` is provided.
|
|
14
|
-
*
|
|
15
|
-
* @since 1.0.0-canary.6
|
|
16
|
-
*/
|
|
17
|
-
declare function GtagConsentBootstrap({
|
|
18
|
-
config,
|
|
19
|
-
dataLayerName,
|
|
20
|
-
defaultConsent,
|
|
21
|
-
debugMode,
|
|
22
|
-
gaMeasurementId,
|
|
23
|
-
nonce,
|
|
24
|
-
...props
|
|
25
|
-
}: GtagConsentBootstrapProps): ReactNode;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { GtagConsentBootstrap, GtagConsentBootstrapProps };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { buildGtagConsentBootstrapScript } from "../destinations/google-analytics.mjs";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
//#region src/react/gtag-consent-bootstrap.tsx
|
|
4
|
-
/**
|
|
5
|
-
* Framework-agnostic inline `<script>` that runs `buildGtagConsentBootstrapScript` before
|
|
6
|
-
* hydration. Pass the same `nonce` here and in `loadGtagScript` for CSP; this component
|
|
7
|
-
* only sets the attribute on the host script — the generated source also stamps it onto
|
|
8
|
-
* the injected gtag.js tag when `nonce` is provided.
|
|
9
|
-
*
|
|
10
|
-
* @since 1.0.0-canary.6
|
|
11
|
-
*/
|
|
12
|
-
function GtagConsentBootstrap({ config, dataLayerName, defaultConsent, debugMode, gaMeasurementId, nonce, ...props }) {
|
|
13
|
-
const bootstrapOptions = {
|
|
14
|
-
config,
|
|
15
|
-
defaultConsent,
|
|
16
|
-
gaMeasurementId,
|
|
17
|
-
...dataLayerName === void 0 ? {} : { dataLayerName },
|
|
18
|
-
...debugMode === void 0 ? {} : { debugMode },
|
|
19
|
-
...nonce === void 0 ? {} : { nonce }
|
|
20
|
-
};
|
|
21
|
-
return /* @__PURE__ */ jsx("script", {
|
|
22
|
-
...props,
|
|
23
|
-
dangerouslySetInnerHTML: { __html: buildGtagConsentBootstrapScript(bootstrapOptions) },
|
|
24
|
-
...nonce === void 0 ? {} : { nonce },
|
|
25
|
-
suppressHydrationWarning: true
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
export { GtagConsentBootstrap };
|
package/dist/react/index.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { UseConsentOptions, UseConsentResult, useConsent } from "./use-consent.mjs";
|
|
2
|
-
import { ConsentBanner, ConsentBannerAccept, ConsentBannerAcceptProps, ConsentBannerActions, ConsentBannerActionsProps, ConsentBannerCategory, ConsentBannerCategoryProps, ConsentBannerCustomize, ConsentBannerCustomizeProps, ConsentBannerDescription, ConsentBannerDescriptionProps, ConsentBannerPreferences, ConsentBannerPreferencesProps, ConsentBannerProps, ConsentBannerReject, ConsentBannerRejectProps, ConsentBannerSave, ConsentBannerSaveProps, ConsentBannerTitle, ConsentBannerTitleProps, ConsentToggle, ConsentToggleProps } from "./consent-banner.mjs";
|
|
3
|
-
import { GtagConsentBootstrap, GtagConsentBootstrapProps } from "./gtag-consent-bootstrap.mjs";
|
|
4
|
-
import { useInitialConsent } from "./use-initial-consent.mjs";
|
|
5
|
-
import { UseGoogleConsentSyncOptions, useGoogleConsentSync } from "./use-google-consent-sync.mjs";
|
|
6
|
-
export { ConsentBanner, ConsentBannerAccept, type ConsentBannerAcceptProps, ConsentBannerActions, type ConsentBannerActionsProps, ConsentBannerCategory, type ConsentBannerCategoryProps, ConsentBannerCustomize, type ConsentBannerCustomizeProps, ConsentBannerDescription, type ConsentBannerDescriptionProps, ConsentBannerPreferences, type ConsentBannerPreferencesProps, type ConsentBannerProps, ConsentBannerReject, type ConsentBannerRejectProps, ConsentBannerSave, type ConsentBannerSaveProps, ConsentBannerTitle, type ConsentBannerTitleProps, ConsentToggle, type ConsentToggleProps, GtagConsentBootstrap, type GtagConsentBootstrapProps, type UseConsentOptions, type UseConsentResult, type UseGoogleConsentSyncOptions, useConsent, useGoogleConsentSync, useInitialConsent };
|
package/dist/react/index.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ConsentBanner, ConsentBannerAccept, ConsentBannerActions, ConsentBannerCategory, ConsentBannerCustomize, ConsentBannerDescription, ConsentBannerPreferences, ConsentBannerReject, ConsentBannerSave, ConsentBannerTitle, ConsentToggle } from "./consent-banner.mjs";
|
|
2
|
-
import { GtagConsentBootstrap } from "./gtag-consent-bootstrap.mjs";
|
|
3
|
-
import { useConsent } from "./use-consent.mjs";
|
|
4
|
-
import { useInitialConsent } from "./use-initial-consent.mjs";
|
|
5
|
-
import { useGoogleConsentSync } from "./use-google-consent-sync.mjs";
|
|
6
|
-
export { ConsentBanner, ConsentBannerAccept, ConsentBannerActions, ConsentBannerCategory, ConsentBannerCustomize, ConsentBannerDescription, ConsentBannerPreferences, ConsentBannerReject, ConsentBannerSave, ConsentBannerTitle, ConsentToggle, GtagConsentBootstrap, useConsent, useGoogleConsentSync, useInitialConsent };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ConsentDecision, ConsentMode, ConsentStorage } from "../core/consent.mjs";
|
|
2
|
-
import { ConsentConfig } from "../core/consent-config.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/react/use-consent.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* @since 0.5.0-canary.4
|
|
7
|
-
*/
|
|
8
|
-
interface UseConsentOptions {
|
|
9
|
-
/** Must be the same object the tracker gate and the tag bootstraps receive — one config, every surface. */
|
|
10
|
-
config: ConsentConfig;
|
|
11
|
-
hasGlobalPrivacyControlSignal?: boolean | undefined;
|
|
12
|
-
mode: ConsentMode;
|
|
13
|
-
onDecision?: ((decision: ConsentDecision) => void) | undefined;
|
|
14
|
-
/** Must be a stable reference (module-level or memoized) — a new object per render resubscribes every render. */
|
|
15
|
-
storage: ConsentStorage;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @since 0.5.0-canary.4
|
|
19
|
-
*/
|
|
20
|
-
interface UseConsentResult {
|
|
21
|
-
/** The stored decision under the current policy version — `undefined` until the visitor makes one. */
|
|
22
|
-
decision: ConsentDecision | undefined;
|
|
23
|
-
denyAll: () => void;
|
|
24
|
-
/** What tags must obey right now — the stored decision, or the region default before one exists. */
|
|
25
|
-
effectiveConsent: ConsentDecision;
|
|
26
|
-
grantAll: () => void;
|
|
27
|
-
/** Effective `analytics` consent — gates this package's own tracker pipeline. */
|
|
28
|
-
isAnalyticsAllowed: boolean;
|
|
29
|
-
/** True only for opt-in regions with no stored decision yet — drives whether to render the banner. */
|
|
30
|
-
isPromptNeeded: boolean;
|
|
31
|
-
/** Persist a granular per-category choice, e.g. from a preferences panel. */
|
|
32
|
-
saveDecision: (decision: ConsentDecision) => void;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Bridges `resolveConsentMode`/`resolveDefaultConsent` (core, region-aware) to React via
|
|
36
|
-
* `useSyncExternalStore`: the stored record is the single source of truth, hydration is
|
|
37
|
-
* safe by construction (the server snapshot is always "no decision yet", matching what
|
|
38
|
-
* prerendered HTML could know), and a decision made in another tab syncs through the
|
|
39
|
-
* storage subscription.
|
|
40
|
-
*
|
|
41
|
-
* @since 0.5.0-canary.4
|
|
42
|
-
*/
|
|
43
|
-
declare function useConsent(options: UseConsentOptions): UseConsentResult;
|
|
44
|
-
//#endregion
|
|
45
|
-
export { UseConsentOptions, UseConsentResult, useConsent };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { CONSENT_CATEGORIES, createConsentDecision, readStoredDecision, resolveDefaultConsent } from "../core/consent.mjs";
|
|
3
|
-
import { useCallback, useMemo, useRef, useSyncExternalStore } from "react";
|
|
4
|
-
//#region src/react/use-consent.ts
|
|
5
|
-
/**
|
|
6
|
-
* Bridges `resolveConsentMode`/`resolveDefaultConsent` (core, region-aware) to React via
|
|
7
|
-
* `useSyncExternalStore`: the stored record is the single source of truth, hydration is
|
|
8
|
-
* safe by construction (the server snapshot is always "no decision yet", matching what
|
|
9
|
-
* prerendered HTML could know), and a decision made in another tab syncs through the
|
|
10
|
-
* storage subscription.
|
|
11
|
-
*
|
|
12
|
-
* @since 0.5.0-canary.4
|
|
13
|
-
*/
|
|
14
|
-
function useConsent(options) {
|
|
15
|
-
const { mode, onDecision, storage } = options;
|
|
16
|
-
const { policyVersion, requestedCategories } = options.config;
|
|
17
|
-
const hasGlobalPrivacyControlSignal = options.hasGlobalPrivacyControlSignal ?? false;
|
|
18
|
-
const cachedDecision = useRef(void 0);
|
|
19
|
-
const decision = useSyncExternalStore(storage.subscribe, () => {
|
|
20
|
-
const stored = readStoredDecision(storage, policyVersion);
|
|
21
|
-
if (stored === void 0) {
|
|
22
|
-
cachedDecision.current = void 0;
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const cached = cachedDecision.current;
|
|
26
|
-
if (cached !== void 0 && CONSENT_CATEGORIES.every((category) => cached[category] === stored[category])) return cached;
|
|
27
|
-
cachedDecision.current = stored;
|
|
28
|
-
return cachedDecision.current;
|
|
29
|
-
}, () => void 0);
|
|
30
|
-
const saveDecision = useCallback((next) => {
|
|
31
|
-
storage.save({
|
|
32
|
-
decision: next,
|
|
33
|
-
policyVersion,
|
|
34
|
-
timestamp: Date.now()
|
|
35
|
-
});
|
|
36
|
-
onDecision?.(next);
|
|
37
|
-
}, [
|
|
38
|
-
onDecision,
|
|
39
|
-
policyVersion,
|
|
40
|
-
storage
|
|
41
|
-
]);
|
|
42
|
-
const denyAll = useCallback(() => {
|
|
43
|
-
saveDecision(createConsentDecision([]));
|
|
44
|
-
}, [saveDecision]);
|
|
45
|
-
const grantAll = useCallback(() => {
|
|
46
|
-
saveDecision(createConsentDecision(requestedCategories));
|
|
47
|
-
}, [requestedCategories, saveDecision]);
|
|
48
|
-
const effectiveConsent = decision ?? resolveDefaultConsent({
|
|
49
|
-
hasGlobalPrivacyControlSignal,
|
|
50
|
-
mode,
|
|
51
|
-
requestedCategories
|
|
52
|
-
});
|
|
53
|
-
return useMemo(() => ({
|
|
54
|
-
decision,
|
|
55
|
-
denyAll,
|
|
56
|
-
effectiveConsent,
|
|
57
|
-
grantAll,
|
|
58
|
-
isAnalyticsAllowed: effectiveConsent.analytics,
|
|
59
|
-
isPromptNeeded: mode === "opt-in" && decision === void 0,
|
|
60
|
-
saveDecision
|
|
61
|
-
}), [
|
|
62
|
-
decision,
|
|
63
|
-
denyAll,
|
|
64
|
-
effectiveConsent,
|
|
65
|
-
grantAll,
|
|
66
|
-
mode,
|
|
67
|
-
saveDecision
|
|
68
|
-
]);
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
|
-
export { useConsent };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { UseConsentResult } from "./use-consent.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/react/use-google-consent-sync.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* @since 1.0.0-canary.6
|
|
6
|
-
*/
|
|
7
|
-
interface UseGoogleConsentSyncOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Idempotent gtag.js load — advanced Consent Mode already injects the tag from a
|
|
10
|
-
* bootstrap; pass a loader as a safety net after a runtime grant.
|
|
11
|
-
*/
|
|
12
|
-
loadGtagScript?: (() => void) | undefined;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Keeps Google Consent Mode v2 in sync with `useConsent`: emits `update` when a stored
|
|
16
|
-
* decision exists (including cross-tab / privacy-page saves), and optionally loads gtag
|
|
17
|
-
* when analytics is effective. Mount once on a page-wide surface (e.g. the footer gate).
|
|
18
|
-
*
|
|
19
|
-
* @since 1.0.0-canary.6
|
|
20
|
-
*/
|
|
21
|
-
declare function useGoogleConsentSync(consent: UseConsentResult, options?: UseGoogleConsentSyncOptions): void;
|
|
22
|
-
//#endregion
|
|
23
|
-
export { UseGoogleConsentSyncOptions, useGoogleConsentSync };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { updateGoogleConsent } from "../destinations/google-analytics.mjs";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
-
//#region src/react/use-google-consent-sync.ts
|
|
5
|
-
/**
|
|
6
|
-
* Keeps Google Consent Mode v2 in sync with `useConsent`: emits `update` when a stored
|
|
7
|
-
* decision exists (including cross-tab / privacy-page saves), and optionally loads gtag
|
|
8
|
-
* when analytics is effective. Mount once on a page-wide surface (e.g. the footer gate).
|
|
9
|
-
*
|
|
10
|
-
* @since 1.0.0-canary.6
|
|
11
|
-
*/
|
|
12
|
-
function useGoogleConsentSync(consent, options = {}) {
|
|
13
|
-
const { loadGtagScript } = options;
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (consent.decision !== void 0) updateGoogleConsent(consent.decision);
|
|
16
|
-
if (consent.effectiveConsent.analytics) loadGtagScript?.();
|
|
17
|
-
}, [
|
|
18
|
-
consent.decision,
|
|
19
|
-
consent.effectiveConsent.analytics,
|
|
20
|
-
loadGtagScript
|
|
21
|
-
]);
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { useGoogleConsentSync };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useSyncExternalStore } from "react";
|
|
3
|
-
//#region src/react/use-initial-consent.ts
|
|
4
|
-
/**
|
|
5
|
-
* Reactive view of a `createInitialConsentStore` — kicks off resolution on mount (a no-op
|
|
6
|
-
* when the app already did so at router creation) and re-renders once the server lane
|
|
7
|
-
* answers. SSR and the first client render read the strictest snapshot, so hydration can
|
|
8
|
-
* never mismatch on region.
|
|
9
|
-
*
|
|
10
|
-
* @since 1.0.0-canary.6
|
|
11
|
-
*/
|
|
12
|
-
function useInitialConsent(store) {
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
store.ensureResolved();
|
|
15
|
-
}, [store]);
|
|
16
|
-
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
export { useInitialConsent };
|