@codefast/tracking 0.5.0-canary.5 → 0.5.0-canary.6

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.
Files changed (276) hide show
  1. package/CHANGELOG.md +467 -0
  2. package/README.md +176 -126
  3. package/dist/adapters/tanstack-start.d.ts +80 -0
  4. package/dist/adapters/tanstack-start.d.ts.map +1 -0
  5. package/dist/adapters/tanstack-start.js +74 -0
  6. package/dist/adapters/tanstack-start.js.map +1 -0
  7. package/dist/client/ad-framework-consent.d.ts +62 -0
  8. package/dist/client/ad-framework-consent.d.ts.map +1 -0
  9. package/dist/client/ad-framework-consent.js +40 -0
  10. package/dist/client/ad-framework-consent.js.map +1 -0
  11. package/dist/client/browser-cookie.d.ts +9 -0
  12. package/dist/client/browser-cookie.d.ts.map +1 -0
  13. package/dist/client/browser-cookie.js +15 -0
  14. package/dist/client/browser-cookie.js.map +1 -0
  15. package/dist/client/consent-runtime.d.ts +53 -0
  16. package/dist/client/consent-runtime.d.ts.map +1 -0
  17. package/dist/client/consent-runtime.js +33 -0
  18. package/dist/client/consent-runtime.js.map +1 -0
  19. package/dist/client/{consent-storage.d.mts → consent-storage.d.ts} +8 -6
  20. package/dist/client/consent-storage.d.ts.map +1 -0
  21. package/dist/client/consent-storage.js +109 -0
  22. package/dist/client/consent-storage.js.map +1 -0
  23. package/dist/client/consent-withdrawal.d.ts +18 -0
  24. package/dist/client/consent-withdrawal.d.ts.map +1 -0
  25. package/dist/client/consent-withdrawal.js +17 -0
  26. package/dist/client/consent-withdrawal.js.map +1 -0
  27. package/dist/client/cookie-anonymous-id.d.ts +41 -0
  28. package/dist/client/cookie-anonymous-id.d.ts.map +1 -0
  29. package/dist/client/cookie-anonymous-id.js +65 -0
  30. package/dist/client/cookie-anonymous-id.js.map +1 -0
  31. package/dist/client/create-client-tracker.d.ts +60 -0
  32. package/dist/client/create-client-tracker.d.ts.map +1 -0
  33. package/dist/client/create-client-tracker.js +91 -0
  34. package/dist/client/create-client-tracker.js.map +1 -0
  35. package/dist/client/gpc.d.ts +10 -0
  36. package/dist/client/gpc.d.ts.map +1 -0
  37. package/dist/client/gpc.js +12 -0
  38. package/dist/client/gpc.js.map +1 -0
  39. package/dist/client/initial-consent-store.d.ts +63 -0
  40. package/dist/client/initial-consent-store.d.ts.map +1 -0
  41. package/dist/client/initial-consent-store.js +138 -0
  42. package/dist/client/initial-consent-store.js.map +1 -0
  43. package/dist/client/is-analytics-allowed.d.ts +26 -0
  44. package/dist/client/is-analytics-allowed.d.ts.map +1 -0
  45. package/dist/client/is-analytics-allowed.js +22 -0
  46. package/dist/client/is-analytics-allowed.js.map +1 -0
  47. package/dist/client/server-persisted-anonymous-id.d.ts +30 -0
  48. package/dist/client/server-persisted-anonymous-id.d.ts.map +1 -0
  49. package/dist/client/server-persisted-anonymous-id.js +72 -0
  50. package/dist/client/server-persisted-anonymous-id.js.map +1 -0
  51. package/dist/core/consent-config.d.ts +24 -0
  52. package/dist/core/consent-config.d.ts.map +1 -0
  53. package/dist/core/consent-config.js +9 -0
  54. package/dist/core/consent-config.js.map +1 -0
  55. package/dist/core/consent-receipt.d.ts +71 -0
  56. package/dist/core/consent-receipt.d.ts.map +1 -0
  57. package/dist/core/consent-receipt.js +39 -0
  58. package/dist/core/consent-receipt.js.map +1 -0
  59. package/dist/core/consent.d.ts +182 -0
  60. package/dist/core/consent.d.ts.map +1 -0
  61. package/dist/core/consent.js +159 -0
  62. package/dist/core/consent.js.map +1 -0
  63. package/dist/core/cookie.d.ts +15 -0
  64. package/dist/core/cookie.d.ts.map +1 -0
  65. package/dist/core/cookie.js +26 -0
  66. package/dist/core/cookie.js.map +1 -0
  67. package/dist/core/destination.d.ts +29 -0
  68. package/dist/core/destination.d.ts.map +1 -0
  69. package/dist/core/destination.js +2 -0
  70. package/dist/core/destination.js.map +1 -0
  71. package/dist/core/event-catalog.d.ts +35 -0
  72. package/dist/core/event-catalog.d.ts.map +1 -0
  73. package/dist/core/event-catalog.js +30 -0
  74. package/dist/core/event-catalog.js.map +1 -0
  75. package/dist/core/event-id.d.ts +7 -0
  76. package/dist/core/event-id.d.ts.map +1 -0
  77. package/dist/core/event-id.js +9 -0
  78. package/dist/core/event-id.js.map +1 -0
  79. package/dist/core/tracked-event.d.ts +15 -0
  80. package/dist/core/tracked-event.d.ts.map +1 -0
  81. package/dist/core/tracked-event.js +2 -0
  82. package/dist/core/tracked-event.js.map +1 -0
  83. package/dist/destinations/ad-consent.d.ts +23 -0
  84. package/dist/destinations/ad-consent.d.ts.map +1 -0
  85. package/dist/destinations/ad-consent.js +12 -0
  86. package/dist/destinations/ad-consent.js.map +1 -0
  87. package/dist/destinations/google-analytics.d.ts +148 -0
  88. package/dist/destinations/google-analytics.d.ts.map +1 -0
  89. package/dist/destinations/google-analytics.js +156 -0
  90. package/dist/destinations/google-analytics.js.map +1 -0
  91. package/dist/destinations/google-consent.d.ts +62 -0
  92. package/dist/destinations/google-consent.d.ts.map +1 -0
  93. package/dist/destinations/google-consent.js +109 -0
  94. package/dist/destinations/google-consent.js.map +1 -0
  95. package/dist/destinations/meta.d.ts +63 -0
  96. package/dist/destinations/meta.d.ts.map +1 -0
  97. package/dist/destinations/meta.js +44 -0
  98. package/dist/destinations/meta.js.map +1 -0
  99. package/dist/destinations/microsoft-uet.d.ts +56 -0
  100. package/dist/destinations/microsoft-uet.d.ts.map +1 -0
  101. package/dist/destinations/microsoft-uet.js +41 -0
  102. package/dist/destinations/microsoft-uet.js.map +1 -0
  103. package/dist/destinations/shared.d.ts +18 -0
  104. package/dist/destinations/shared.d.ts.map +1 -0
  105. package/dist/destinations/shared.js +19 -0
  106. package/dist/destinations/shared.js.map +1 -0
  107. package/dist/destinations/tiktok.d.ts +55 -0
  108. package/dist/destinations/tiktok.d.ts.map +1 -0
  109. package/dist/destinations/tiktok.js +40 -0
  110. package/dist/destinations/tiktok.js.map +1 -0
  111. package/dist/destinations/vercel-analytics.d.ts +25 -0
  112. package/dist/destinations/vercel-analytics.d.ts.map +1 -0
  113. package/dist/destinations/vercel-analytics.js +23 -0
  114. package/dist/destinations/vercel-analytics.js.map +1 -0
  115. package/dist/index.d.ts +64 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +41 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/react/consent-banner.d.ts +155 -0
  120. package/dist/react/consent-banner.d.ts.map +1 -0
  121. package/dist/react/consent-banner.js +171 -0
  122. package/dist/react/consent-banner.js.map +1 -0
  123. package/dist/react/gtag-consent-bootstrap.d.ts +17 -0
  124. package/dist/react/gtag-consent-bootstrap.d.ts.map +1 -0
  125. package/dist/react/gtag-consent-bootstrap.js +22 -0
  126. package/dist/react/gtag-consent-bootstrap.js.map +1 -0
  127. package/dist/react/use-consent.d.ts +42 -0
  128. package/dist/react/use-consent.d.ts.map +1 -0
  129. package/dist/react/use-consent.js +60 -0
  130. package/dist/react/use-consent.js.map +1 -0
  131. package/dist/react/use-google-consent-sync.d.ts +20 -0
  132. package/dist/react/use-google-consent-sync.d.ts.map +1 -0
  133. package/dist/react/use-google-consent-sync.js +22 -0
  134. package/dist/react/use-google-consent-sync.js.map +1 -0
  135. package/dist/react/use-initial-consent.d.ts +11 -0
  136. package/dist/react/use-initial-consent.d.ts.map +1 -0
  137. package/dist/react/use-initial-consent.js +18 -0
  138. package/dist/react/use-initial-consent.js.map +1 -0
  139. package/dist/server/anonymous-id-cookie.d.ts +67 -0
  140. package/dist/server/anonymous-id-cookie.d.ts.map +1 -0
  141. package/dist/server/anonymous-id-cookie.js +71 -0
  142. package/dist/server/anonymous-id-cookie.js.map +1 -0
  143. package/dist/server/consent-receipt-store.d.ts +56 -0
  144. package/dist/server/consent-receipt-store.d.ts.map +1 -0
  145. package/dist/server/consent-receipt-store.js +44 -0
  146. package/dist/server/consent-receipt-store.js.map +1 -0
  147. package/dist/server/consent-receipt.d.ts +41 -0
  148. package/dist/server/consent-receipt.d.ts.map +1 -0
  149. package/dist/server/consent-receipt.js +60 -0
  150. package/dist/server/consent-receipt.js.map +1 -0
  151. package/dist/server/initial-consent.d.ts +26 -0
  152. package/dist/server/initial-consent.d.ts.map +1 -0
  153. package/dist/server/initial-consent.js +31 -0
  154. package/dist/server/initial-consent.js.map +1 -0
  155. package/dist/server/measurement-protocol.d.ts +69 -0
  156. package/dist/server/measurement-protocol.d.ts.map +1 -0
  157. package/dist/server/measurement-protocol.js +61 -0
  158. package/dist/server/measurement-protocol.js.map +1 -0
  159. package/dist/server/region.d.ts +27 -0
  160. package/dist/server/region.d.ts.map +1 -0
  161. package/dist/server/region.js +69 -0
  162. package/dist/server/region.js.map +1 -0
  163. package/dist/server/user-deletion.d.ts +64 -0
  164. package/dist/server/user-deletion.d.ts.map +1 -0
  165. package/dist/server/user-deletion.js +54 -0
  166. package/dist/server/user-deletion.js.map +1 -0
  167. package/dist/tooling/import-protection.d.ts +19 -0
  168. package/dist/tooling/import-protection.d.ts.map +1 -0
  169. package/dist/tooling/import-protection.js +23 -0
  170. package/dist/tooling/import-protection.js.map +1 -0
  171. package/package.json +201 -107
  172. package/src/adapters/tanstack-start.ts +135 -0
  173. package/src/client/ad-framework-consent.ts +86 -0
  174. package/src/client/browser-cookie.ts +16 -0
  175. package/src/client/consent-runtime.ts +80 -0
  176. package/src/client/consent-storage.ts +31 -1
  177. package/src/client/consent-withdrawal.ts +32 -0
  178. package/src/client/cookie-anonymous-id.ts +112 -0
  179. package/src/client/create-client-tracker.ts +128 -86
  180. package/src/client/gpc.ts +4 -2
  181. package/src/client/initial-consent-store.ts +218 -0
  182. package/src/client/is-analytics-allowed.ts +43 -0
  183. package/src/client/server-persisted-anonymous-id.ts +102 -0
  184. package/src/core/consent-config.ts +27 -0
  185. package/src/core/consent-receipt.ts +115 -0
  186. package/src/core/consent.ts +164 -10
  187. package/src/core/cookie.ts +29 -0
  188. package/src/core/destination.ts +17 -8
  189. package/src/core/event-catalog.ts +29 -15
  190. package/src/core/event-id.ts +1 -2
  191. package/src/core/tracked-event.ts +4 -4
  192. package/src/destinations/ad-consent.ts +29 -0
  193. package/src/destinations/google-analytics.ts +196 -133
  194. package/src/destinations/google-consent.ts +164 -0
  195. package/src/destinations/meta.ts +96 -0
  196. package/src/destinations/microsoft-uet.ts +86 -0
  197. package/src/destinations/shared.ts +45 -0
  198. package/src/destinations/tiktok.ts +85 -0
  199. package/src/destinations/vercel-analytics.ts +23 -24
  200. package/src/index.ts +165 -8
  201. package/src/react/consent-banner.tsx +40 -14
  202. package/src/react/gtag-consent-bootstrap.tsx +48 -0
  203. package/src/react/use-consent.ts +53 -45
  204. package/src/react/use-google-consent-sync.ts +38 -0
  205. package/src/react/use-initial-consent.ts +22 -0
  206. package/src/server/anonymous-id-cookie.ts +103 -0
  207. package/src/server/consent-receipt-store.ts +79 -0
  208. package/src/server/consent-receipt.ts +89 -0
  209. package/src/server/initial-consent.ts +46 -0
  210. package/src/server/measurement-protocol.ts +114 -0
  211. package/src/server/region.ts +22 -15
  212. package/src/server/user-deletion.ts +93 -0
  213. package/src/tooling/import-protection.ts +22 -0
  214. package/dist/client/consent-storage.mjs +0 -63
  215. package/dist/client/create-client-tracker.d.mts +0 -37
  216. package/dist/client/create-client-tracker.mjs +0 -66
  217. package/dist/client/gpc.d.mts +0 -10
  218. package/dist/client/gpc.mjs +0 -12
  219. package/dist/client/index.d.mts +0 -8
  220. package/dist/client/index.mjs +0 -8
  221. package/dist/client/lifecycle.d.mts +0 -23
  222. package/dist/client/lifecycle.mjs +0 -30
  223. package/dist/client/local-storage.d.mts +0 -13
  224. package/dist/client/local-storage.mjs +0 -31
  225. package/dist/client/queue.d.mts +0 -49
  226. package/dist/client/queue.mjs +0 -71
  227. package/dist/client/router.d.mts +0 -30
  228. package/dist/client/router.mjs +0 -17
  229. package/dist/core/consent.d.mts +0 -89
  230. package/dist/core/consent.mjs +0 -57
  231. package/dist/core/destination.d.mts +0 -23
  232. package/dist/core/destination.mjs +0 -1
  233. package/dist/core/event-catalog.d.mts +0 -36
  234. package/dist/core/event-catalog.mjs +0 -12
  235. package/dist/core/event-id.d.mts +0 -10
  236. package/dist/core/event-id.mjs +0 -12
  237. package/dist/core/index.d.mts +0 -6
  238. package/dist/core/index.mjs +0 -4
  239. package/dist/core/tracked-event.d.mts +0 -17
  240. package/dist/core/tracked-event.mjs +0 -1
  241. package/dist/destinations/ga4-measurement-protocol.d.mts +0 -54
  242. package/dist/destinations/ga4-measurement-protocol.mjs +0 -89
  243. package/dist/destinations/google-analytics.d.mts +0 -98
  244. package/dist/destinations/google-analytics.mjs +0 -126
  245. package/dist/destinations/http-destination.d.mts +0 -20
  246. package/dist/destinations/http-destination.mjs +0 -25
  247. package/dist/destinations/index.d.mts +0 -5
  248. package/dist/destinations/index.mjs +0 -5
  249. package/dist/destinations/vercel-analytics.d.mts +0 -13
  250. package/dist/destinations/vercel-analytics.mjs +0 -30
  251. package/dist/index.d.mts +0 -6
  252. package/dist/index.mjs +0 -4
  253. package/dist/react/consent-banner.d.mts +0 -163
  254. package/dist/react/consent-banner.mjs +0 -209
  255. package/dist/react/index.d.mts +0 -3
  256. package/dist/react/index.mjs +0 -3
  257. package/dist/react/use-consent.d.mts +0 -49
  258. package/dist/react/use-consent.mjs +0 -54
  259. package/dist/server/create-server-tracker.d.mts +0 -42
  260. package/dist/server/create-server-tracker.mjs +0 -67
  261. package/dist/server/index.d.mts +0 -3
  262. package/dist/server/index.mjs +0 -3
  263. package/dist/server/region.d.mts +0 -20
  264. package/dist/server/region.mjs +0 -56
  265. package/src/client/index.ts +0 -17
  266. package/src/client/lifecycle.ts +0 -50
  267. package/src/client/local-storage.ts +0 -44
  268. package/src/client/queue.ts +0 -117
  269. package/src/client/router.ts +0 -37
  270. package/src/core/index.ts +0 -24
  271. package/src/destinations/ga4-measurement-protocol.ts +0 -166
  272. package/src/destinations/http-destination.ts +0 -33
  273. package/src/destinations/index.ts +0 -20
  274. package/src/react/index.ts +0 -29
  275. package/src/server/create-server-tracker.ts +0 -128
  276. package/src/server/index.ts +0 -4
@@ -1,98 +0,0 @@
1
- import { ConsentDecision } from "../core/consent.mjs";
2
- import { Destination } from "../core/destination.mjs";
3
-
4
- //#region src/destinations/google-analytics.d.ts
5
- type GtagPropertyValue = boolean | number | string;
6
- type GoogleConsentState = "denied" | "granted";
7
- interface GoogleConsentParams {
8
- ad_personalization: GoogleConsentState;
9
- ad_storage: GoogleConsentState;
10
- ad_user_data: GoogleConsentState;
11
- analytics_storage: GoogleConsentState;
12
- region?: ReadonlyArray<string>;
13
- wait_for_update?: number;
14
- }
15
- /**
16
- * All signatures share one `gtag` global, so they must live in a single overloaded type —
17
- * two separate `declare global` augmentations with different signatures for the same
18
- * property is a TS error, not a merge.
19
- */
20
- type GtagFunction = {
21
- (command: "consent", action: "default" | "update", params: GoogleConsentParams): void;
22
- (command: "event", eventName: string, params?: Record<string, GtagPropertyValue>): void;
23
- (command: "set", params: Record<string, GtagPropertyValue>): void;
24
- (command: "set", key: string, value: boolean): void;
25
- };
26
- declare global {
27
- interface Window {
28
- dataLayer?: Array<unknown>;
29
- gtag?: GtagFunction;
30
- }
31
- }
32
- /**
33
- * @since 0.5.0-canary.4
34
- */
35
- interface GoogleConsentDefaultOptions {
36
- /** Restrict the default to these ISO 3166-2 codes (gtag's `region` param); omit for a global default. */
37
- region?: ReadonlyArray<string>;
38
- /** Consent Mode's `wait_for_update` — how long tags hold hits so a stored decision can arrive as an update first. */
39
- waitForUpdateMs?: number;
40
- }
41
- /**
42
- * Google Consent Mode v2's "default" signal — call before the gtag.js script tag loads
43
- * (this defines the queueing stub itself, so no snippet has to run first) with the
44
- * region-resolved default, so GA4/Ads never fire a hit ahead of it.
45
- *
46
- * @since 0.5.0-canary.4
47
- */
48
- declare function setGoogleConsentDefault(decision: ConsentDecision, options?: GoogleConsentDefaultOptions): void;
49
- /**
50
- * Google Consent Mode v2's "update" signal — call whenever the visitor's effective
51
- * consent changes (a banner decision, or one synced from another tab), so already-loaded
52
- * GA4/Ads tags pick up the change without a page reload.
53
- *
54
- * @since 0.5.0-canary.4
55
- */
56
- declare function updateGoogleConsent(decision: ConsentDecision): void;
57
- /**
58
- * Consent Mode's `ads_data_redaction` flag — with `ad_storage` denied, gtag further
59
- * redacts ad click identifiers (gclid/dclid) from its cookieless pings. Set alongside
60
- * the consent default.
61
- *
62
- * @since 0.5.0-canary.4
63
- */
64
- declare function setGoogleAdsDataRedaction(enabled: boolean): void;
65
- /**
66
- * Consent Mode's `url_passthrough` flag — carries ad click info through page URLs while
67
- * storage is denied, preserving conversion attribution without cookies.
68
- *
69
- * @since 0.5.0-canary.4
70
- */
71
- declare function setGoogleUrlPassthrough(enabled: boolean): void;
72
- /**
73
- * @since 0.5.0-canary.4
74
- */
75
- interface GoogleAnalyticsDestinationOptions {
76
- name?: string;
77
- /**
78
- * Forward `$page_viewed` as GA4's `page_view`. Off by default: `gtag('config', ...)`
79
- * sends the initial page_view and GA4's Enhanced Measurement (on by default in admin)
80
- * tracks SPA history changes, so forwarding here would double-count. Enable only after
81
- * setting `send_page_view: false` on config and disabling Enhanced Measurement's
82
- * history-based page views.
83
- */
84
- trackPageViews?: boolean;
85
- }
86
- /**
87
- * Forwards events to `window.gtag`, translating this package's `$`-prefixed built-ins to
88
- * GA4's vocabulary — `$identify` sets `user_id`, `$group` becomes the recommended
89
- * `join_group` event, `$page_viewed` maps to `page_view` (opt-in, see `trackPageViews`).
90
- * Requires the gtag.js snippet plus `gtag('config', measurementId)` mounted once by the
91
- * app. Marked `delivery: "immediate"` — gtag.js has its own batching and unload delivery,
92
- * so queueing in front of it only delays events and replays stale ones next session.
93
- *
94
- * @since 0.5.0-canary.4
95
- */
96
- declare function createGoogleAnalyticsDestination(options?: GoogleAnalyticsDestinationOptions): Destination;
97
- //#endregion
98
- export { GoogleAnalyticsDestinationOptions, GoogleConsentDefaultOptions, createGoogleAnalyticsDestination, setGoogleAdsDataRedaction, setGoogleConsentDefault, setGoogleUrlPassthrough, updateGoogleConsent };
@@ -1,126 +0,0 @@
1
- //#region src/destinations/google-analytics.ts
2
- /**
3
- * The visitor's per-category decision maps onto Consent Mode v2's signals: `analytics`
4
- * drives `analytics_storage`; `ads` drives all three ads signals together — a banner
5
- * that got ads consent got it for storage, sharing, and personalization alike.
6
- */
7
- function toGoogleConsentParams(decision) {
8
- const ads = decision.ads ? "granted" : "denied";
9
- return {
10
- ad_personalization: ads,
11
- ad_storage: ads,
12
- ad_user_data: ads,
13
- analytics_storage: decision.analytics ? "granted" : "denied"
14
- };
15
- }
16
- /**
17
- * Ensures the standard gtag.js queueing stub exists so consent commands can be issued
18
- * before the tag itself loads — gtag.js replays the queue in order once it boots.
19
- */
20
- function ensureGtag() {
21
- if (typeof window === "undefined") return;
22
- window.dataLayer ??= [];
23
- window.gtag ??= function gtag() {
24
- window.dataLayer?.push(arguments);
25
- };
26
- return window.gtag;
27
- }
28
- /**
29
- * Google Consent Mode v2's "default" signal — call before the gtag.js script tag loads
30
- * (this defines the queueing stub itself, so no snippet has to run first) with the
31
- * region-resolved default, so GA4/Ads never fire a hit ahead of it.
32
- *
33
- * @since 0.5.0-canary.4
34
- */
35
- function setGoogleConsentDefault(decision, options = {}) {
36
- const params = toGoogleConsentParams(decision);
37
- if (options.region !== void 0) params.region = options.region;
38
- if (options.waitForUpdateMs !== void 0) params.wait_for_update = options.waitForUpdateMs;
39
- ensureGtag()?.("consent", "default", params);
40
- }
41
- /**
42
- * Google Consent Mode v2's "update" signal — call whenever the visitor's effective
43
- * consent changes (a banner decision, or one synced from another tab), so already-loaded
44
- * GA4/Ads tags pick up the change without a page reload.
45
- *
46
- * @since 0.5.0-canary.4
47
- */
48
- function updateGoogleConsent(decision) {
49
- ensureGtag()?.("consent", "update", toGoogleConsentParams(decision));
50
- }
51
- /**
52
- * Consent Mode's `ads_data_redaction` flag — with `ad_storage` denied, gtag further
53
- * redacts ad click identifiers (gclid/dclid) from its cookieless pings. Set alongside
54
- * the consent default.
55
- *
56
- * @since 0.5.0-canary.4
57
- */
58
- function setGoogleAdsDataRedaction(enabled) {
59
- ensureGtag()?.("set", "ads_data_redaction", enabled);
60
- }
61
- /**
62
- * Consent Mode's `url_passthrough` flag — carries ad click info through page URLs while
63
- * storage is denied, preserving conversion attribution without cookies.
64
- *
65
- * @since 0.5.0-canary.4
66
- */
67
- function setGoogleUrlPassthrough(enabled) {
68
- ensureGtag()?.("set", "url_passthrough", enabled);
69
- }
70
- /**
71
- * gtag.js event params must be flat string/number/boolean — stringify anything else
72
- * instead of letting GA4 silently drop it.
73
- */
74
- function toGtagParams(props) {
75
- const result = {};
76
- for (const [key, value] of Object.entries(props)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") result[key] = value;
77
- else if (value !== void 0 && value !== null) result[key] = JSON.stringify(value);
78
- return result;
79
- }
80
- const GA4_EVENT_NAME_PATTERN = /^[A-Za-z][\w]{0,39}$/;
81
- /**
82
- * Forwards events to `window.gtag`, translating this package's `$`-prefixed built-ins to
83
- * GA4's vocabulary — `$identify` sets `user_id`, `$group` becomes the recommended
84
- * `join_group` event, `$page_viewed` maps to `page_view` (opt-in, see `trackPageViews`).
85
- * Requires the gtag.js snippet plus `gtag('config', measurementId)` mounted once by the
86
- * app. Marked `delivery: "immediate"` — gtag.js has its own batching and unload delivery,
87
- * so queueing in front of it only delays events and replays stale ones next session.
88
- *
89
- * @since 0.5.0-canary.4
90
- */
91
- function createGoogleAnalyticsDestination(options = {}) {
92
- const name = options.name ?? "google-analytics";
93
- return {
94
- delivery: "immediate",
95
- name,
96
- send(event) {
97
- if (typeof window === "undefined" || typeof window.gtag !== "function") return;
98
- if (event.name === "$identify") {
99
- if (event.userId !== void 0) window.gtag("set", { user_id: event.userId });
100
- return;
101
- }
102
- if (event.name === "$page_viewed") {
103
- if (options.trackPageViews === true) {
104
- const { href: _href, name: _name, ...extras } = event.props;
105
- window.gtag("event", "page_view", toGtagParams(extras));
106
- }
107
- return;
108
- }
109
- if (event.name === "$group") {
110
- const { groupId, ...traits } = event.props;
111
- window.gtag("event", "join_group", toGtagParams({
112
- group_id: groupId,
113
- ...traits
114
- }));
115
- return;
116
- }
117
- if (!GA4_EVENT_NAME_PATTERN.test(event.name)) {
118
- console.warn(`[tracking] "${name}" dropped event "${event.name}" — GA4 event names must start with a letter and contain only letters, digits, or underscores (max 40 chars)`);
119
- return;
120
- }
121
- window.gtag("event", event.name, toGtagParams(event.props));
122
- }
123
- };
124
- }
125
- //#endregion
126
- export { createGoogleAnalyticsDestination, setGoogleAdsDataRedaction, setGoogleConsentDefault, setGoogleUrlPassthrough, updateGoogleConsent };
@@ -1,20 +0,0 @@
1
- import { Destination } from "../core/destination.mjs";
2
-
3
- //#region src/destinations/http-destination.d.ts
4
- /**
5
- * @since 0.5.0-canary.4
6
- */
7
- interface HttpDestinationOptions {
8
- endpoint: string;
9
- headers?: Record<string, string>;
10
- name: string;
11
- }
12
- /**
13
- * Generic fetch-based `Destination` — the building block for a real provider adapter
14
- * (PostHog, GA4, ...); those ship their own payload shape and aren't implemented here.
15
- *
16
- * @since 0.5.0-canary.4
17
- */
18
- declare function createHttpDestination(options: HttpDestinationOptions): Destination;
19
- //#endregion
20
- export { HttpDestinationOptions, createHttpDestination };
@@ -1,25 +0,0 @@
1
- //#region src/destinations/http-destination.ts
2
- /**
3
- * Generic fetch-based `Destination` — the building block for a real provider adapter
4
- * (PostHog, GA4, ...); those ship their own payload shape and aren't implemented here.
5
- *
6
- * @since 0.5.0-canary.4
7
- */
8
- function createHttpDestination(options) {
9
- return {
10
- name: options.name,
11
- async send(event) {
12
- const response = await fetch(options.endpoint, {
13
- body: JSON.stringify(event),
14
- headers: {
15
- "content-type": "application/json",
16
- ...options.headers
17
- },
18
- method: "POST"
19
- });
20
- if (!response.ok) throw new Error(`"${options.name}" destination responded with ${String(response.status)}`);
21
- }
22
- };
23
- }
24
- //#endregion
25
- export { createHttpDestination };
@@ -1,5 +0,0 @@
1
- import { Ga4MeasurementProtocolDestinationOptions, createGa4MeasurementProtocolDestination, extractGa4ClientId, extractGa4SessionId } from "./ga4-measurement-protocol.mjs";
2
- import { GoogleAnalyticsDestinationOptions, GoogleConsentDefaultOptions, createGoogleAnalyticsDestination, setGoogleAdsDataRedaction, setGoogleConsentDefault, setGoogleUrlPassthrough, updateGoogleConsent } from "./google-analytics.mjs";
3
- import { HttpDestinationOptions, createHttpDestination } from "./http-destination.mjs";
4
- import { createVercelAnalyticsDestination } from "./vercel-analytics.mjs";
5
- export { type Ga4MeasurementProtocolDestinationOptions, type GoogleAnalyticsDestinationOptions, type GoogleConsentDefaultOptions, type HttpDestinationOptions, createGa4MeasurementProtocolDestination, createGoogleAnalyticsDestination, createHttpDestination, createVercelAnalyticsDestination, extractGa4ClientId, extractGa4SessionId, setGoogleAdsDataRedaction, setGoogleConsentDefault, setGoogleUrlPassthrough, updateGoogleConsent };
@@ -1,5 +0,0 @@
1
- import { createGa4MeasurementProtocolDestination, extractGa4ClientId, extractGa4SessionId } from "./ga4-measurement-protocol.mjs";
2
- import { createGoogleAnalyticsDestination, setGoogleAdsDataRedaction, setGoogleConsentDefault, setGoogleUrlPassthrough, updateGoogleConsent } from "./google-analytics.mjs";
3
- import { createHttpDestination } from "./http-destination.mjs";
4
- import { createVercelAnalyticsDestination } from "./vercel-analytics.mjs";
5
- export { createGa4MeasurementProtocolDestination, createGoogleAnalyticsDestination, createHttpDestination, createVercelAnalyticsDestination, extractGa4ClientId, extractGa4SessionId, setGoogleAdsDataRedaction, setGoogleConsentDefault, setGoogleUrlPassthrough, updateGoogleConsent };
@@ -1,13 +0,0 @@
1
- import { Destination } from "../core/destination.mjs";
2
-
3
- //#region src/destinations/vercel-analytics.d.ts
4
- /**
5
- * `track()` only pushes onto Vercel's own in-page queue (`window.va`/`window.vaq`), which
6
- * handles batching and unload delivery itself — hence `delivery: "immediate"`. Requires
7
- * `<Analytics />` from `@vercel/analytics/react` to be mounted once in the app.
8
- *
9
- * @since 0.5.0-canary.4
10
- */
11
- declare function createVercelAnalyticsDestination(name?: string): Destination;
12
- //#endregion
13
- export { createVercelAnalyticsDestination };
@@ -1,30 +0,0 @@
1
- import { track } from "@vercel/analytics/react";
2
- //#region src/destinations/vercel-analytics.ts
3
- /**
4
- * Vercel's `track()` rejects nested objects/arrays outright — flatten anything else
5
- * to a string instead of silently dropping it.
6
- */
7
- function toVercelAnalyticsProps(props) {
8
- const result = {};
9
- for (const [key, value] of Object.entries(props)) if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") result[key] = value;
10
- else if (value !== void 0) result[key] = JSON.stringify(value);
11
- return result;
12
- }
13
- /**
14
- * `track()` only pushes onto Vercel's own in-page queue (`window.va`/`window.vaq`), which
15
- * handles batching and unload delivery itself — hence `delivery: "immediate"`. Requires
16
- * `<Analytics />` from `@vercel/analytics/react` to be mounted once in the app.
17
- *
18
- * @since 0.5.0-canary.4
19
- */
20
- function createVercelAnalyticsDestination(name = "vercel-analytics") {
21
- return {
22
- delivery: "immediate",
23
- name,
24
- send(event) {
25
- track(event.name, toVercelAnalyticsProps(event.props));
26
- }
27
- };
28
- }
29
- //#endregion
30
- export { createVercelAnalyticsDestination };
package/dist/index.d.mts DELETED
@@ -1,6 +0,0 @@
1
- import { CONSENT_CATEGORIES, ConsentCategory, ConsentDecision, ConsentMode, ConsentRecord, ConsentRegion, ConsentStorage, createConsentDecision, isConsentDecision, resolveConsentMode, resolveDefaultConsent } from "./core/consent.mjs";
2
- import { TrackedEvent } from "./core/tracked-event.mjs";
3
- import { Destination } from "./core/destination.mjs";
4
- import { EventCatalog, EventDefinition, EventsOf, defineEventCatalog } from "./core/event-catalog.mjs";
5
- import { generateEventId } from "./core/event-id.mjs";
6
- export { CONSENT_CATEGORIES, type ConsentCategory, type ConsentDecision, type ConsentMode, type ConsentRecord, type ConsentRegion, type ConsentStorage, type Destination, type EventCatalog, type EventDefinition, type EventsOf, type TrackedEvent, createConsentDecision, defineEventCatalog, generateEventId, isConsentDecision, resolveConsentMode, resolveDefaultConsent };
package/dist/index.mjs DELETED
@@ -1,4 +0,0 @@
1
- import { CONSENT_CATEGORIES, createConsentDecision, isConsentDecision, resolveConsentMode, resolveDefaultConsent } from "./core/consent.mjs";
2
- import { defineEventCatalog } from "./core/event-catalog.mjs";
3
- import { generateEventId } from "./core/event-id.mjs";
4
- export { CONSENT_CATEGORIES, createConsentDecision, defineEventCatalog, generateEventId, isConsentDecision, resolveConsentMode, resolveDefaultConsent };
@@ -1,163 +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 `needsPrompt` 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/NĐ 13 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.needsPrompt`), 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 `categories`) — 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
- allowLabel?: string;
146
- consent: UseConsentResult;
147
- denyLabel?: string;
148
- }
149
- /**
150
- * Always-visible control for opt-out regions — CCPA/CPRA requires a persistent
151
- * "Do Not Sell or Share My Personal Information" mechanism, not just a one-time prompt.
152
- * Flips between denying everything and re-granting the app's requested categories.
153
- *
154
- * @since 0.5.0-canary.4
155
- */
156
- declare function ConsentToggle({
157
- allowLabel,
158
- consent,
159
- denyLabel,
160
- ...props
161
- }: ConsentToggleProps): ReactNode;
162
- //#endregion
163
- export { ConsentBanner, ConsentBannerAccept, ConsentBannerAcceptProps, ConsentBannerActions, ConsentBannerActionsProps, ConsentBannerCategory, ConsentBannerCategoryProps, ConsentBannerCustomize, ConsentBannerCustomizeProps, ConsentBannerDescription, ConsentBannerDescriptionProps, ConsentBannerPreferences, ConsentBannerPreferencesProps, ConsentBannerProps, ConsentBannerReject, ConsentBannerRejectProps, ConsentBannerSave, ConsentBannerSaveProps, ConsentBannerTitle, ConsentBannerTitleProps, ConsentToggle, ConsentToggleProps };