@codefast/tracking 0.5.0-canary.5 → 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 +220 -0
- package/README.md +176 -126
- 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.ts +9 -0
- 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} +8 -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.ts +10 -0
- 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.ts +182 -0
- 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.ts +15 -0
- 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.ts +7 -0
- 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.ts +11 -0
- 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.ts +27 -0
- 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 +203 -108
- package/src/adapters/tanstack-start.ts +135 -0
- package/src/client/ad-framework-consent.ts +86 -0
- package/src/client/browser-cookie.ts +16 -0
- package/src/client/consent-runtime.ts +80 -0
- package/src/client/consent-storage.ts +31 -1
- package/src/client/consent-withdrawal.ts +32 -0
- package/src/client/cookie-anonymous-id.ts +112 -0
- package/src/client/create-client-tracker.ts +128 -86
- package/src/client/gpc.ts +4 -2
- package/src/client/initial-consent-store.ts +218 -0
- package/src/client/is-analytics-allowed.ts +43 -0
- package/src/client/server-persisted-anonymous-id.ts +102 -0
- package/src/core/consent-config.ts +27 -0
- package/src/core/consent-receipt.ts +115 -0
- package/src/core/consent.ts +164 -10
- package/src/core/cookie.ts +29 -0
- package/src/core/destination.ts +17 -8
- package/src/core/event-catalog.ts +29 -15
- package/src/core/event-id.ts +1 -2
- package/src/core/tracked-event.ts +4 -4
- package/src/destinations/ad-consent.ts +29 -0
- package/src/destinations/google-analytics.ts +196 -133
- package/src/destinations/google-consent.ts +164 -0
- package/src/destinations/meta.ts +96 -0
- package/src/destinations/microsoft-uet.ts +86 -0
- package/src/destinations/shared.ts +45 -0
- package/src/destinations/tiktok.ts +85 -0
- package/src/destinations/vercel-analytics.ts +23 -24
- package/src/index.ts +165 -8
- package/src/react/consent-banner.tsx +40 -14
- package/src/react/gtag-consent-bootstrap.tsx +48 -0
- package/src/react/use-consent.ts +53 -45
- package/src/react/use-google-consent-sync.ts +38 -0
- package/src/react/use-initial-consent.ts +22 -0
- package/src/server/anonymous-id-cookie.ts +103 -0
- package/src/server/consent-receipt-store.ts +79 -0
- package/src/server/consent-receipt.ts +89 -0
- package/src/server/initial-consent.ts +46 -0
- package/src/server/measurement-protocol.ts +114 -0
- package/src/server/region.ts +22 -15
- package/src/server/user-deletion.ts +93 -0
- package/src/tooling/import-protection.ts +22 -0
- package/dist/client/consent-storage.mjs +0 -63
- package/dist/client/create-client-tracker.d.mts +0 -37
- package/dist/client/create-client-tracker.mjs +0 -66
- package/dist/client/gpc.d.mts +0 -10
- package/dist/client/gpc.mjs +0 -12
- package/dist/client/index.d.mts +0 -8
- package/dist/client/index.mjs +0 -8
- package/dist/client/lifecycle.d.mts +0 -23
- package/dist/client/lifecycle.mjs +0 -30
- package/dist/client/local-storage.d.mts +0 -13
- package/dist/client/local-storage.mjs +0 -31
- package/dist/client/queue.d.mts +0 -49
- package/dist/client/queue.mjs +0 -71
- package/dist/client/router.d.mts +0 -30
- package/dist/client/router.mjs +0 -17
- package/dist/core/consent.d.mts +0 -89
- package/dist/core/consent.mjs +0 -57
- package/dist/core/destination.d.mts +0 -23
- package/dist/core/destination.mjs +0 -1
- package/dist/core/event-catalog.d.mts +0 -36
- package/dist/core/event-catalog.mjs +0 -12
- package/dist/core/event-id.d.mts +0 -10
- package/dist/core/event-id.mjs +0 -12
- package/dist/core/index.d.mts +0 -6
- package/dist/core/index.mjs +0 -4
- package/dist/core/tracked-event.d.mts +0 -17
- package/dist/core/tracked-event.mjs +0 -1
- package/dist/destinations/ga4-measurement-protocol.d.mts +0 -54
- package/dist/destinations/ga4-measurement-protocol.mjs +0 -89
- package/dist/destinations/google-analytics.d.mts +0 -98
- package/dist/destinations/google-analytics.mjs +0 -126
- package/dist/destinations/http-destination.d.mts +0 -20
- package/dist/destinations/http-destination.mjs +0 -25
- package/dist/destinations/index.d.mts +0 -5
- package/dist/destinations/index.mjs +0 -5
- package/dist/destinations/vercel-analytics.d.mts +0 -13
- package/dist/destinations/vercel-analytics.mjs +0 -30
- package/dist/index.d.mts +0 -6
- package/dist/index.mjs +0 -4
- package/dist/react/consent-banner.d.mts +0 -163
- package/dist/react/consent-banner.mjs +0 -209
- package/dist/react/index.d.mts +0 -3
- package/dist/react/index.mjs +0 -3
- package/dist/react/use-consent.d.mts +0 -49
- package/dist/react/use-consent.mjs +0 -54
- package/dist/server/create-server-tracker.d.mts +0 -42
- package/dist/server/create-server-tracker.mjs +0 -67
- package/dist/server/index.d.mts +0 -3
- package/dist/server/index.mjs +0 -3
- package/dist/server/region.d.mts +0 -20
- package/dist/server/region.mjs +0 -56
- package/src/client/index.ts +0 -17
- package/src/client/lifecycle.ts +0 -50
- package/src/client/local-storage.ts +0 -44
- package/src/client/queue.ts +0 -117
- package/src/client/router.ts +0 -37
- package/src/core/index.ts +0 -24
- package/src/destinations/ga4-measurement-protocol.ts +0 -166
- package/src/destinations/http-destination.ts +0 -33
- package/src/destinations/index.ts +0 -20
- package/src/react/index.ts +0 -29
- package/src/server/create-server-tracker.ts +0 -128
- package/src/server/index.ts +0 -4
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
2
|
+
import type { ConsentCategory } from "#/core/consent";
|
|
3
|
+
import type { UseConsentResult } from "#/react/use-consent";
|
|
4
|
+
/**
|
|
5
|
+
* @since 0.5.0-canary.4
|
|
6
|
+
*/
|
|
7
|
+
export interface ConsentBannerProps extends ComponentProps<"section"> {
|
|
8
|
+
consent: UseConsentResult;
|
|
9
|
+
/** Overrides the default `isPromptNeeded` gating — e.g. to reopen the banner as a settings panel. */
|
|
10
|
+
open?: boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Non-blocking opt-in prompt for GDPR/PDPL (VN) regions, as composable parts — the root owns
|
|
14
|
+
* the visibility gating and the preferences-layer state; the `Accept`/`Reject`/`Customize`/
|
|
15
|
+
* `Save` parts wire their own clicks to the consent hook, so any markup (including a
|
|
16
|
+
* design system's button styles via `className`) slots in. Renders nothing once a decision
|
|
17
|
+
* exists or the region defaults to opt-out (`consent.isPromptNeeded`), unless `open` says
|
|
18
|
+
* otherwise. Rendered as a labeled region, not a `<dialog>`: an open non-modal dialog
|
|
19
|
+
* neither traps focus nor blocks the page, so the dialog semantics would over-promise.
|
|
20
|
+
* Unstyled by default — style via `className`/`data-slot` selectors, or import the
|
|
21
|
+
* optional `@codefast/tracking/css/consent.css` theme. `data-state` on the root flips
|
|
22
|
+
* between `prompt` and `preferences` for state-dependent styling.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.5.0-canary.4
|
|
25
|
+
*/
|
|
26
|
+
export declare function ConsentBanner({ children, consent, open, ...props }: ConsentBannerProps): ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* @since 0.5.0-canary.5
|
|
29
|
+
*/
|
|
30
|
+
export interface ConsentBannerTitleProps extends ComponentProps<"h2"> {
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @since 0.5.0-canary.5
|
|
34
|
+
*/
|
|
35
|
+
export declare function ConsentBannerTitle({ children, ...props }: ConsentBannerTitleProps): ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* @since 0.5.0-canary.5
|
|
38
|
+
*/
|
|
39
|
+
export interface ConsentBannerDescriptionProps extends ComponentProps<"p"> {
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Hosts the message and the privacy-policy link informed consent requires.
|
|
43
|
+
*
|
|
44
|
+
* @since 0.5.0-canary.5
|
|
45
|
+
*/
|
|
46
|
+
export declare function ConsentBannerDescription(props: ConsentBannerDescriptionProps): ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* @since 0.5.0-canary.5
|
|
49
|
+
*/
|
|
50
|
+
export interface ConsentBannerActionsProps extends ComponentProps<"div"> {
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @since 0.5.0-canary.5
|
|
54
|
+
*/
|
|
55
|
+
export declare function ConsentBannerActions(props: ConsentBannerActionsProps): ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* @since 0.5.0-canary.5
|
|
58
|
+
*/
|
|
59
|
+
export interface ConsentBannerAcceptProps extends Omit<ComponentProps<"button">, "type"> {
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Grants the categories the app requested (`useConsent`'s `requestedCategories`) — never more.
|
|
63
|
+
*
|
|
64
|
+
* @since 0.5.0-canary.5
|
|
65
|
+
*/
|
|
66
|
+
export declare function ConsentBannerAccept({ onClick, ...props }: ConsentBannerAcceptProps): ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* @since 0.5.0-canary.5
|
|
69
|
+
*/
|
|
70
|
+
export interface ConsentBannerRejectProps extends Omit<ComponentProps<"button">, "type"> {
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @since 0.5.0-canary.5
|
|
74
|
+
*/
|
|
75
|
+
export declare function ConsentBannerReject({ onClick, ...props }: ConsentBannerRejectProps): ReactNode;
|
|
76
|
+
/**
|
|
77
|
+
* @since 0.5.0-canary.5
|
|
78
|
+
*/
|
|
79
|
+
export interface ConsentBannerCustomizeProps extends Omit<ComponentProps<"button">, "type"> {
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Opens the per-category preferences layer, starting from the current effective state so
|
|
83
|
+
* nothing arrives pre-ticked in an opt-in region (pre-ticked consent is invalid under
|
|
84
|
+
* GDPR). Hidden while the layer is open — `ConsentBannerSave` takes over.
|
|
85
|
+
*
|
|
86
|
+
* @since 0.5.0-canary.5
|
|
87
|
+
*/
|
|
88
|
+
export declare function ConsentBannerCustomize({ onClick, ...props }: ConsentBannerCustomizeProps): ReactNode;
|
|
89
|
+
/**
|
|
90
|
+
* @since 0.5.0-canary.5
|
|
91
|
+
*/
|
|
92
|
+
export interface ConsentBannerPreferencesProps extends ComponentProps<"div"> {
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Container for the per-category rows — renders only while the preferences layer is open.
|
|
96
|
+
*
|
|
97
|
+
* @since 0.5.0-canary.5
|
|
98
|
+
*/
|
|
99
|
+
export declare function ConsentBannerPreferences(props: ConsentBannerPreferencesProps): ReactNode;
|
|
100
|
+
/**
|
|
101
|
+
* @since 0.5.0-canary.5
|
|
102
|
+
*/
|
|
103
|
+
export interface ConsentBannerCategoryProps extends ComponentProps<"label"> {
|
|
104
|
+
category: ConsentCategory;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* One checkbox row of the preferences layer — `children` is the visitor-facing wording.
|
|
108
|
+
*
|
|
109
|
+
* @since 0.5.0-canary.5
|
|
110
|
+
*/
|
|
111
|
+
export declare function ConsentBannerCategory({ category, children, ...props }: ConsentBannerCategoryProps): ReactNode;
|
|
112
|
+
/**
|
|
113
|
+
* @since 0.5.0-canary.5
|
|
114
|
+
*/
|
|
115
|
+
export interface ConsentBannerSaveProps extends Omit<ComponentProps<"button">, "type"> {
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Persists the pending per-category selection — renders only while the preferences layer is open.
|
|
119
|
+
*
|
|
120
|
+
* @since 0.5.0-canary.5
|
|
121
|
+
*/
|
|
122
|
+
export declare function ConsentBannerSave({ onClick, ...props }: ConsentBannerSaveProps): ReactNode;
|
|
123
|
+
/**
|
|
124
|
+
* @since 0.5.0-canary.4
|
|
125
|
+
*/
|
|
126
|
+
export interface ConsentToggleProps extends Omit<ComponentProps<"button">, "children" | "onClick" | "type"> {
|
|
127
|
+
/**
|
|
128
|
+
* Label shown while the scoped categories are denied — clicking grants them. Defaults
|
|
129
|
+
* to "Allow tracking".
|
|
130
|
+
*/
|
|
131
|
+
allowLabel?: string | undefined;
|
|
132
|
+
consent: UseConsentResult;
|
|
133
|
+
/**
|
|
134
|
+
* Label shown while any scoped category is granted — clicking denies them. Defaults to
|
|
135
|
+
* CCPA/CPRA "Do Not Sell or Share My Personal Information".
|
|
136
|
+
*/
|
|
137
|
+
denyLabel?: string | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Purposes this control flips. Defaults to `["ads"]` — CCPA/CPRA "Do Not Sell or Share"
|
|
140
|
+
* mirrors GPC (ads denied, first-party analytics left alone). Pass `["analytics"]` (or
|
|
141
|
+
* both) for a broader opt-out. Distinct from `useConsent`'s `requestedCategories` (what the
|
|
142
|
+
* prompt asks about / `grantAll` grants).
|
|
143
|
+
*/
|
|
144
|
+
toggledCategories?: ReadonlyArray<ConsentCategory> | undefined;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Always-visible control for opt-out regions — CCPA/CPRA requires a persistent
|
|
148
|
+
* "Do Not Sell or Share My Personal Information" mechanism, not just a one-time prompt.
|
|
149
|
+
* By default it only flips `ads` (same scope as a GPC signal); pass `toggledCategories`
|
|
150
|
+
* to include analytics or both.
|
|
151
|
+
*
|
|
152
|
+
* @since 0.5.0-canary.4
|
|
153
|
+
*/
|
|
154
|
+
export declare function ConsentToggle({ allowLabel, consent, denyLabel, toggledCategories, ...props }: ConsentToggleProps): ReactNode;
|
|
155
|
+
//# sourceMappingURL=consent-banner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-banner.d.ts","sourceRoot":"","sources":["../../src/react/consent-banner.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAY,SAAS,EAAkB,MAAM,OAAO,CAAC;AAGjF,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAqB5D;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc,CAAC,SAAS,CAAC;IACnE,OAAO,EAAE,gBAAgB,CAAC;IAC1B,qGAAqG;IACrG,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,kBAAkB,GAAG,SAAS,CA4BlG;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc,CAAC,IAAI,CAAC;CAAG;AAEx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SAAS,CAQxF;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,cAAc,CAAC,OAAO,CAAC;IACzE,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,0BAA0B,GAAG,SAAS,CAoB7G;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAAG;AAEzF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,sBAAsB,GAAG,SAAS,CAqB1F;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;IACzG;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE,gBAAgB,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;CAChE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAC5B,UAA6B,EAC7B,OAAO,EACP,SAA0D,EAC1D,iBAA2B,EAC3B,GAAG,KAAK,EACT,EAAE,kBAAkB,GAAG,SAAS,CAsBhC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
const ConsentBannerContext = createContext(null);
|
|
5
|
+
function useConsentBannerContext(part) {
|
|
6
|
+
const context = useContext(ConsentBannerContext);
|
|
7
|
+
if (context === null) {
|
|
8
|
+
throw new Error(`\`${part}\` must be rendered inside \`ConsentBanner\``);
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Non-blocking opt-in prompt for GDPR/PDPL (VN) regions, as composable parts — the root owns
|
|
14
|
+
* the visibility gating and the preferences-layer state; the `Accept`/`Reject`/`Customize`/
|
|
15
|
+
* `Save` parts wire their own clicks to the consent hook, so any markup (including a
|
|
16
|
+
* design system's button styles via `className`) slots in. Renders nothing once a decision
|
|
17
|
+
* exists or the region defaults to opt-out (`consent.isPromptNeeded`), unless `open` says
|
|
18
|
+
* otherwise. Rendered as a labeled region, not a `<dialog>`: an open non-modal dialog
|
|
19
|
+
* neither traps focus nor blocks the page, so the dialog semantics would over-promise.
|
|
20
|
+
* Unstyled by default — style via `className`/`data-slot` selectors, or import the
|
|
21
|
+
* optional `@codefast/tracking/css/consent.css` theme. `data-state` on the root flips
|
|
22
|
+
* between `prompt` and `preferences` for state-dependent styling.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.5.0-canary.4
|
|
25
|
+
*/
|
|
26
|
+
export function ConsentBanner({ children, consent, open, ...props }) {
|
|
27
|
+
const [pending, setPending] = useState(undefined);
|
|
28
|
+
const isVisible = open ?? consent.isPromptNeeded;
|
|
29
|
+
// Closing must reset the layer — a reopened banner starts at the prompt, not mid-preferences.
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!isVisible) {
|
|
32
|
+
setPending(undefined);
|
|
33
|
+
}
|
|
34
|
+
}, [isVisible]);
|
|
35
|
+
if (!isVisible) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return (_jsx(ConsentBannerContext.Provider, { value: { consent, pending, setPending }, children: _jsx("section", { "aria-label": "Cookie consent", "data-slot": "consent-banner", "data-state": pending === undefined ? "prompt" : "preferences", ...props, children: children }) }));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @since 0.5.0-canary.5
|
|
42
|
+
*/
|
|
43
|
+
export function ConsentBannerTitle({ children, ...props }) {
|
|
44
|
+
return (_jsx("h2", { "data-slot": "consent-title", ...props, children: children }));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hosts the message and the privacy-policy link informed consent requires.
|
|
48
|
+
*
|
|
49
|
+
* @since 0.5.0-canary.5
|
|
50
|
+
*/
|
|
51
|
+
export function ConsentBannerDescription(props) {
|
|
52
|
+
return _jsx("p", { "data-slot": "consent-description", ...props });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @since 0.5.0-canary.5
|
|
56
|
+
*/
|
|
57
|
+
export function ConsentBannerActions(props) {
|
|
58
|
+
return _jsx("div", { "data-slot": "consent-actions", ...props });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Grants the categories the app requested (`useConsent`'s `requestedCategories`) — never more.
|
|
62
|
+
*
|
|
63
|
+
* @since 0.5.0-canary.5
|
|
64
|
+
*/
|
|
65
|
+
export function ConsentBannerAccept({ onClick, ...props }) {
|
|
66
|
+
const { consent, setPending } = useConsentBannerContext("ConsentBannerAccept");
|
|
67
|
+
return (_jsx("button", { "data-action": "accept", "data-slot": "consent-action", ...props,
|
|
68
|
+
// the part owns the decision — composed so a consumer onClick (e.g. closing a settings view) still runs
|
|
69
|
+
onClick: (event) => {
|
|
70
|
+
onClick?.(event);
|
|
71
|
+
consent.grantAll();
|
|
72
|
+
setPending(undefined);
|
|
73
|
+
}, type: "button" }));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @since 0.5.0-canary.5
|
|
77
|
+
*/
|
|
78
|
+
export function ConsentBannerReject({ onClick, ...props }) {
|
|
79
|
+
const { consent, setPending } = useConsentBannerContext("ConsentBannerReject");
|
|
80
|
+
return (_jsx("button", { "data-action": "reject", "data-slot": "consent-action", ...props,
|
|
81
|
+
// the part owns the decision — composed so a consumer onClick (e.g. closing a settings view) still runs
|
|
82
|
+
onClick: (event) => {
|
|
83
|
+
onClick?.(event);
|
|
84
|
+
consent.denyAll();
|
|
85
|
+
setPending(undefined);
|
|
86
|
+
}, type: "button" }));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Opens the per-category preferences layer, starting from the current effective state so
|
|
90
|
+
* nothing arrives pre-ticked in an opt-in region (pre-ticked consent is invalid under
|
|
91
|
+
* GDPR). Hidden while the layer is open — `ConsentBannerSave` takes over.
|
|
92
|
+
*
|
|
93
|
+
* @since 0.5.0-canary.5
|
|
94
|
+
*/
|
|
95
|
+
export function ConsentBannerCustomize({ onClick, ...props }) {
|
|
96
|
+
const { consent, pending, setPending } = useConsentBannerContext("ConsentBannerCustomize");
|
|
97
|
+
if (pending !== undefined) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return (_jsx("button", { "data-action": "customize", "data-slot": "consent-action", ...props,
|
|
101
|
+
// the part owns the layer toggle — composed so a consumer onClick still runs
|
|
102
|
+
onClick: (event) => {
|
|
103
|
+
onClick?.(event);
|
|
104
|
+
setPending(consent.effectiveConsent);
|
|
105
|
+
}, type: "button" }));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Container for the per-category rows — renders only while the preferences layer is open.
|
|
109
|
+
*
|
|
110
|
+
* @since 0.5.0-canary.5
|
|
111
|
+
*/
|
|
112
|
+
export function ConsentBannerPreferences(props) {
|
|
113
|
+
const { pending } = useConsentBannerContext("ConsentBannerPreferences");
|
|
114
|
+
if (pending === undefined) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return _jsx("div", { "data-slot": "consent-preferences", ...props });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* One checkbox row of the preferences layer — `children` is the visitor-facing wording.
|
|
121
|
+
*
|
|
122
|
+
* @since 0.5.0-canary.5
|
|
123
|
+
*/
|
|
124
|
+
export function ConsentBannerCategory({ category, children, ...props }) {
|
|
125
|
+
const { pending, setPending } = useConsentBannerContext("ConsentBannerCategory");
|
|
126
|
+
if (pending === undefined) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return (_jsxs("label", { "data-slot": "consent-category", ...props, children: [_jsx("input", { checked: pending[category], "data-slot": "consent-category-checkbox", onChange: (event) => {
|
|
130
|
+
setPending({ ...pending, [category]: event.target.checked });
|
|
131
|
+
}, type: "checkbox" }), children] }));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Persists the pending per-category selection — renders only while the preferences layer is open.
|
|
135
|
+
*
|
|
136
|
+
* @since 0.5.0-canary.5
|
|
137
|
+
*/
|
|
138
|
+
export function ConsentBannerSave({ onClick, ...props }) {
|
|
139
|
+
const { consent, pending, setPending } = useConsentBannerContext("ConsentBannerSave");
|
|
140
|
+
if (pending === undefined) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return (_jsx("button", { "data-action": "save", "data-slot": "consent-action", ...props,
|
|
144
|
+
// the part owns the decision — composed so a consumer onClick still runs
|
|
145
|
+
onClick: (event) => {
|
|
146
|
+
onClick?.(event);
|
|
147
|
+
consent.saveDecision(pending);
|
|
148
|
+
setPending(undefined);
|
|
149
|
+
}, type: "button" }));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Always-visible control for opt-out regions — CCPA/CPRA requires a persistent
|
|
153
|
+
* "Do Not Sell or Share My Personal Information" mechanism, not just a one-time prompt.
|
|
154
|
+
* By default it only flips `ads` (same scope as a GPC signal); pass `toggledCategories`
|
|
155
|
+
* to include analytics or both.
|
|
156
|
+
*
|
|
157
|
+
* @since 0.5.0-canary.4
|
|
158
|
+
*/
|
|
159
|
+
export function ConsentToggle({ allowLabel = "Allow tracking", consent, denyLabel = "Do Not Sell or Share My Personal Information", toggledCategories = ["ads"], ...props }) {
|
|
160
|
+
const isAnyCategoryGranted = toggledCategories.some((category) => consent.effectiveConsent[category]);
|
|
161
|
+
return (_jsx("button", { "data-slot": "consent-toggle", ...props,
|
|
162
|
+
// the toggle owns its click — flipping the scoped categories is its whole purpose
|
|
163
|
+
onClick: () => {
|
|
164
|
+
const next = { ...consent.effectiveConsent };
|
|
165
|
+
for (const category of toggledCategories) {
|
|
166
|
+
next[category] = !isAnyCategoryGranted;
|
|
167
|
+
}
|
|
168
|
+
consent.saveDecision(next);
|
|
169
|
+
}, type: "button", children: isAnyCategoryGranted ? denyLabel : allowLabel }));
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=consent-banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-banner.js","sourceRoot":"","sources":["../../src/react/consent-banner.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAYvE,MAAM,oBAAoB,GAAG,aAAa,CAAmC,IAAI,CAAC,CAAC;AAEnF,SAAS,uBAAuB,CAAC,IAAY;IAC3C,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEjD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,8CAA8C,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAWD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,EAAsB;IACrF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAA8B,SAAS,CAAC,CAAC;IAE/E,MAAM,SAAS,GAAG,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC;IAEjD,8FAA8F;IAC9F,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,UAAU,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,CAA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AU,GAAG,gBAAgB,EAC7B,OAAO,EACP,SAAS,GAAG,8CAA8C,EAC1D,iBAAiB,GAAG,CAAC,KAAK,CAAC,EAC3B,GAAG,KAAK,EACW;IACnB,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtG,OAAO,CACL,8BACY,gBAAgB,KACtB,KAAK;QACT,kFAAkF;QAClF,OAAO,EAAE,GAAG,EAAE;YACZ,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAE7C,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;gBACzC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,oBAAoB,CAAC;YACzC,CAAC;YAED,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,EACD,IAAI,EAAC,QAAQ,YAEZ,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GACvC,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
2
|
+
import type { GtagConsentBootstrapOptions } from "#/destinations/google-analytics";
|
|
3
|
+
/**
|
|
4
|
+
* @since 1.0.0-canary.6
|
|
5
|
+
*/
|
|
6
|
+
export interface GtagConsentBootstrapProps extends Omit<ComponentProps<"script">, "children" | "dangerouslySetInnerHTML" | "nonce" | "src" | "type">, GtagConsentBootstrapOptions {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Framework-agnostic inline `<script>` that runs `buildGtagConsentBootstrapScript` before
|
|
10
|
+
* hydration. Pass the same `nonce` here and in `loadGtagScript` for CSP; this component
|
|
11
|
+
* only sets the attribute on the host script — the generated source also stamps it onto
|
|
12
|
+
* the injected gtag.js tag when `nonce` is provided.
|
|
13
|
+
*
|
|
14
|
+
* @since 1.0.0-canary.6
|
|
15
|
+
*/
|
|
16
|
+
export declare function GtagConsentBootstrap({ config, dataLayerName, defaultConsent, debugMode, gaMeasurementId, nonce, ...props }: GtagConsentBootstrapProps): ReactNode;
|
|
17
|
+
//# sourceMappingURL=gtag-consent-bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtag-consent-bootstrap.d.ts","sourceRoot":"","sources":["../../src/react/gtag-consent-bootstrap.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAGnF;;GAEG;AACH,MAAM,WAAW,yBACf,SACE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,yBAAyB,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC,EACjG,2BAA2B;CAAG;AAElC;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,MAAM,EACN,aAAa,EACb,cAAc,EACd,SAAS,EACT,eAAe,EACf,KAAK,EACL,GAAG,KAAK,EACT,EAAE,yBAAyB,GAAG,SAAS,CAkBvC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { buildGtagConsentBootstrapScript } from "#/destinations/google-analytics";
|
|
3
|
+
/**
|
|
4
|
+
* Framework-agnostic inline `<script>` that runs `buildGtagConsentBootstrapScript` before
|
|
5
|
+
* hydration. Pass the same `nonce` here and in `loadGtagScript` for CSP; this component
|
|
6
|
+
* only sets the attribute on the host script — the generated source also stamps it onto
|
|
7
|
+
* the injected gtag.js tag when `nonce` is provided.
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0-canary.6
|
|
10
|
+
*/
|
|
11
|
+
export function GtagConsentBootstrap({ config, dataLayerName, defaultConsent, debugMode, gaMeasurementId, nonce, ...props }) {
|
|
12
|
+
const bootstrapOptions = {
|
|
13
|
+
config,
|
|
14
|
+
defaultConsent,
|
|
15
|
+
gaMeasurementId,
|
|
16
|
+
...(dataLayerName === undefined ? {} : { dataLayerName }),
|
|
17
|
+
...(debugMode === undefined ? {} : { debugMode }),
|
|
18
|
+
...(nonce === undefined ? {} : { nonce }),
|
|
19
|
+
};
|
|
20
|
+
return (_jsx("script", { ...props, dangerouslySetInnerHTML: { __html: buildGtagConsentBootstrapScript(bootstrapOptions) }, ...(nonce === undefined ? {} : { nonce }), suppressHydrationWarning: true }));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=gtag-consent-bootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtag-consent-bootstrap.js","sourceRoot":"","sources":["../../src/react/gtag-consent-bootstrap.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAUlF;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,EACnC,MAAM,EACN,aAAa,EACb,cAAc,EACd,SAAS,EACT,eAAe,EACf,KAAK,EACL,GAAG,KAAK,EACkB;IAC1B,MAAM,gBAAgB,GAAgC;QACpD,MAAM;QACN,cAAc;QACd,eAAe;QACf,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC;QACzD,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;QACjD,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;KAC1C,CAAC;IAEF,OAAO,CACL,oBACM,KAAK,EACT,uBAAuB,EAAE,EAAE,MAAM,EAAE,+BAA+B,CAAC,gBAAgB,CAAC,EAAE,KAClF,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAC1C,wBAAwB,SACxB,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ConsentDecision, ConsentMode, ConsentStorage } from "#/core/consent";
|
|
2
|
+
import type { ConsentConfig } from "#/core/consent-config";
|
|
3
|
+
/**
|
|
4
|
+
* @since 0.5.0-canary.4
|
|
5
|
+
*/
|
|
6
|
+
export interface UseConsentOptions {
|
|
7
|
+
/** Must be the same object the tracker gate and the tag bootstraps receive — one config, every surface. */
|
|
8
|
+
config: ConsentConfig;
|
|
9
|
+
hasGlobalPrivacyControlSignal?: boolean | undefined;
|
|
10
|
+
mode: ConsentMode;
|
|
11
|
+
onDecision?: ((decision: ConsentDecision) => void) | undefined;
|
|
12
|
+
/** Must be a stable reference (module-level or memoized) — a new object per render resubscribes every render. */
|
|
13
|
+
storage: ConsentStorage;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.5.0-canary.4
|
|
17
|
+
*/
|
|
18
|
+
export interface UseConsentResult {
|
|
19
|
+
/** The stored decision under the current policy version — `undefined` until the visitor makes one. */
|
|
20
|
+
decision: ConsentDecision | undefined;
|
|
21
|
+
denyAll: () => void;
|
|
22
|
+
/** What tags must obey right now — the stored decision, or the region default before one exists. */
|
|
23
|
+
effectiveConsent: ConsentDecision;
|
|
24
|
+
grantAll: () => void;
|
|
25
|
+
/** Effective `analytics` consent — gates this package's own tracker pipeline. */
|
|
26
|
+
isAnalyticsAllowed: boolean;
|
|
27
|
+
/** True only for opt-in regions with no stored decision yet — drives whether to render the banner. */
|
|
28
|
+
isPromptNeeded: boolean;
|
|
29
|
+
/** Persist a granular per-category choice, e.g. from a preferences panel. */
|
|
30
|
+
saveDecision: (decision: ConsentDecision) => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Bridges `resolveConsentMode`/`resolveDefaultConsent` (core, region-aware) to React via
|
|
34
|
+
* `useSyncExternalStore`: the stored record is the single source of truth, hydration is
|
|
35
|
+
* safe by construction (the server snapshot is always "no decision yet", matching what
|
|
36
|
+
* prerendered HTML could know), and a decision made in another tab syncs through the
|
|
37
|
+
* storage subscription.
|
|
38
|
+
*
|
|
39
|
+
* @since 0.5.0-canary.4
|
|
40
|
+
*/
|
|
41
|
+
export declare function useConsent(options: UseConsentOptions): UseConsentResult;
|
|
42
|
+
//# sourceMappingURL=use-consent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-consent.d.ts","sourceRoot":"","sources":["../../src/react/use-consent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2GAA2G;IAC3G,MAAM,EAAE,aAAa,CAAC;IACtB,6BAA6B,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpD,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC/D,iHAAiH;IACjH,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sGAAsG;IACtG,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAC;IACtC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,oGAAoG;IACpG,gBAAgB,EAAE,eAAe,CAAC;IAClC,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,iFAAiF;IACjF,kBAAkB,EAAE,OAAO,CAAC;IAC5B,sGAAsG;IACtG,cAAc,EAAE,OAAO,CAAC;IACxB,6EAA6E;IAC7E,YAAY,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;CACnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAsEvE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { CONSENT_CATEGORIES, createConsentDecision, readStoredDecision, resolveDefaultConsent } from "#/core/consent";
|
|
4
|
+
/**
|
|
5
|
+
* Bridges `resolveConsentMode`/`resolveDefaultConsent` (core, region-aware) to React via
|
|
6
|
+
* `useSyncExternalStore`: the stored record is the single source of truth, hydration is
|
|
7
|
+
* safe by construction (the server snapshot is always "no decision yet", matching what
|
|
8
|
+
* prerendered HTML could know), and a decision made in another tab syncs through the
|
|
9
|
+
* storage subscription.
|
|
10
|
+
*
|
|
11
|
+
* @since 0.5.0-canary.4
|
|
12
|
+
*/
|
|
13
|
+
export function useConsent(options) {
|
|
14
|
+
const { mode, onDecision, storage } = options;
|
|
15
|
+
const { policyVersion, requestedCategories } = options.config;
|
|
16
|
+
const hasGlobalPrivacyControlSignal = options.hasGlobalPrivacyControlSignal ?? false;
|
|
17
|
+
// useSyncExternalStore needs a referentially stable snapshot, but JSON-backed storages
|
|
18
|
+
// parse a fresh record per load — so the last valid decision is cached by value.
|
|
19
|
+
const cachedDecision = useRef(undefined);
|
|
20
|
+
const decision = useSyncExternalStore(storage.subscribe, () => {
|
|
21
|
+
// Only a well-formed decision under the current policy version counts — the store
|
|
22
|
+
// is tamperable plain JSON, and a garbage value must re-prompt, not silently deny.
|
|
23
|
+
const stored = readStoredDecision(storage, policyVersion);
|
|
24
|
+
if (stored === undefined) {
|
|
25
|
+
cachedDecision.current = undefined;
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const cached = cachedDecision.current;
|
|
29
|
+
if (cached !== undefined && CONSENT_CATEGORIES.every((category) => cached[category] === stored[category])) {
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
cachedDecision.current = stored;
|
|
33
|
+
return cachedDecision.current;
|
|
34
|
+
}, () => undefined);
|
|
35
|
+
// Kept stable across renders (when their own inputs don't change) so a consumer that
|
|
36
|
+
// passes this hook's result down as a prop/effect-dep doesn't get a fresh identity —
|
|
37
|
+
// and therefore an unnecessary re-render/effect-rerun — every render.
|
|
38
|
+
const saveDecision = useCallback((next) => {
|
|
39
|
+
// No local state — the save notifies the subscription, which re-renders with the new snapshot.
|
|
40
|
+
storage.save({ decision: next, policyVersion, timestamp: Date.now() });
|
|
41
|
+
onDecision?.(next);
|
|
42
|
+
}, [onDecision, policyVersion, storage]);
|
|
43
|
+
const denyAll = useCallback(() => {
|
|
44
|
+
saveDecision(createConsentDecision([]));
|
|
45
|
+
}, [saveDecision]);
|
|
46
|
+
const grantAll = useCallback(() => {
|
|
47
|
+
saveDecision(createConsentDecision(requestedCategories));
|
|
48
|
+
}, [requestedCategories, saveDecision]);
|
|
49
|
+
const effectiveConsent = decision ?? resolveDefaultConsent({ hasGlobalPrivacyControlSignal, mode, requestedCategories });
|
|
50
|
+
return useMemo(() => ({
|
|
51
|
+
decision,
|
|
52
|
+
denyAll,
|
|
53
|
+
effectiveConsent,
|
|
54
|
+
grantAll,
|
|
55
|
+
isAnalyticsAllowed: effectiveConsent.analytics,
|
|
56
|
+
isPromptNeeded: mode === "opt-in" && decision === undefined,
|
|
57
|
+
saveDecision,
|
|
58
|
+
}), [decision, denyAll, effectiveConsent, grantAll, mode, saveDecision]);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=use-consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-consent.js","sourceRoot":"","sources":["../../src/react/use-consent.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE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{
|
|
6
|
+
/**
|
|
7
|
+
* Idempotent gtag.js load — advanced Consent Mode already injects the tag from a
|
|
8
|
+
* bootstrap; pass a loader as a safety net after a runtime grant.
|
|
9
|
+
*/
|
|
10
|
+
loadGtagScript?: (() => void) | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Keeps Google Consent Mode v2 in sync with `useConsent`: emits `update` when a stored
|
|
14
|
+
* decision exists (including cross-tab / privacy-page saves), and optionally loads gtag
|
|
15
|
+
* when analytics is effective. Mount once on a page-wide surface (e.g. the footer gate).
|
|
16
|
+
*
|
|
17
|
+
* @since 1.0.0-canary.6
|
|
18
|
+
*/
|
|
19
|
+
export declare function useGoogleConsentSync(consent: UseConsentResult, options?: UseGoogleConsentSyncOptions): void;
|
|
20
|
+
//# sourceMappingURL=use-google-consent-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-google-consent-sync.d.ts","sourceRoot":"","sources":["../../src/react/use-google-consent-sync.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CAC3C;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,GAAE,2BAAgC,GAAG,IAAI,CAY/G"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { updateGoogleConsent } from "#/destinations/google-analytics";
|
|
4
|
+
/**
|
|
5
|
+
* Keeps Google Consent Mode v2 in sync with `useConsent`: emits `update` when a stored
|
|
6
|
+
* decision exists (including cross-tab / privacy-page saves), and optionally loads gtag
|
|
7
|
+
* when analytics is effective. Mount once on a page-wide surface (e.g. the footer gate).
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0-canary.6
|
|
10
|
+
*/
|
|
11
|
+
export function useGoogleConsentSync(consent, options = {}) {
|
|
12
|
+
const { loadGtagScript } = options;
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (consent.decision !== undefined) {
|
|
15
|
+
updateGoogleConsent(consent.decision);
|
|
16
|
+
}
|
|
17
|
+
if (consent.effectiveConsent.analytics) {
|
|
18
|
+
loadGtagScript?.();
|
|
19
|
+
}
|
|
20
|
+
}, [consent.decision, consent.effectiveConsent.analytics, loadGtagScript]);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=use-google-consent-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-google-consent-sync.js","sourceRoot":"","sources":["../../src/react/use-google-consent-sync.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AActE;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAyB,EAAE,OAAO,GAAgC,EAAE;IACvG,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACnC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC;YACvC,cAAc,EAAE,EAAE,CAAC;QACrB,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InitialConsentSnapshot, InitialConsentStore } from "#/client/initial-consent-store";
|
|
2
|
+
/**
|
|
3
|
+
* Reactive view of a `createInitialConsentStore` — kicks off resolution on mount (a no-op
|
|
4
|
+
* when the app already did so at router creation) and re-renders once the server lane
|
|
5
|
+
* answers. SSR and the first client render read the strictest snapshot, so hydration can
|
|
6
|
+
* never mismatch on region.
|
|
7
|
+
*
|
|
8
|
+
* @since 1.0.0-canary.6
|
|
9
|
+
*/
|
|
10
|
+
export declare function useInitialConsent(store: InitialConsentStore): InitialConsentSnapshot;
|
|
11
|
+
//# sourceMappingURL=use-initial-consent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-initial-consent.d.ts","sourceRoot":"","sources":["../../src/react/use-initial-consent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAElG;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,sBAAsB,CAOpF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useSyncExternalStore } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Reactive view of a `createInitialConsentStore` — kicks off resolution on mount (a no-op
|
|
5
|
+
* when the app already did so at router creation) and re-renders once the server lane
|
|
6
|
+
* answers. SSR and the first client render read the strictest snapshot, so hydration can
|
|
7
|
+
* never mismatch on region.
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0-canary.6
|
|
10
|
+
*/
|
|
11
|
+
export function useInitialConsent(store) {
|
|
12
|
+
// Post-hydration safety net — idempotent with an earlier, pre-hydration kick.
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
store.ensureResolved();
|
|
15
|
+
}, [store]);
|
|
16
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getServerSnapshot);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=use-initial-consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-initial-consent.js","sourceRoot":"","sources":["../../src/react/use-initial-consent.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAIxD;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA0B;IAC1D,8EAA8E;IAC9E,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,cAAc,EAAE,CAAC;IACzB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAC3F,CAAC"}
|