@codefast/tracking 0.6.2 → 0.7.1

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 (159) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/tanstack-start.d.ts +11 -7
  4. package/dist/adapters/tanstack-start.d.ts.map +1 -1
  5. package/dist/adapters/tanstack-start.js +4 -4
  6. package/dist/adapters/tanstack-start.js.map +1 -1
  7. package/dist/client/ad-framework-consent.d.ts +8 -6
  8. package/dist/client/ad-framework-consent.d.ts.map +1 -1
  9. package/dist/client/ad-framework-consent.js +3 -3
  10. package/dist/client/ad-framework-consent.js.map +1 -1
  11. package/dist/client/browser-cookie.d.ts +1 -1
  12. package/dist/client/browser-cookie.js +1 -1
  13. package/dist/client/consent-runtime.d.ts +5 -3
  14. package/dist/client/consent-runtime.d.ts.map +1 -1
  15. package/dist/client/consent-runtime.js +1 -1
  16. package/dist/client/consent-runtime.js.map +1 -1
  17. package/dist/client/consent-withdrawal.d.ts +4 -2
  18. package/dist/client/consent-withdrawal.d.ts.map +1 -1
  19. package/dist/client/consent-withdrawal.js +1 -1
  20. package/dist/client/consent-withdrawal.js.map +1 -1
  21. package/dist/client/cookie-anonymous-id.d.ts +7 -3
  22. package/dist/client/cookie-anonymous-id.d.ts.map +1 -1
  23. package/dist/client/cookie-anonymous-id.js +1 -1
  24. package/dist/client/cookie-anonymous-id.js.map +1 -1
  25. package/dist/client/create-client-tracker.d.ts +7 -1
  26. package/dist/client/create-client-tracker.d.ts.map +1 -1
  27. package/dist/client/create-client-tracker.js +2 -0
  28. package/dist/client/create-client-tracker.js.map +1 -1
  29. package/dist/client/initial-consent-store.d.ts +6 -4
  30. package/dist/client/initial-consent-store.d.ts.map +1 -1
  31. package/dist/client/initial-consent-store.js +1 -1
  32. package/dist/client/initial-consent-store.js.map +1 -1
  33. package/dist/client/is-analytics-allowed.d.ts +4 -2
  34. package/dist/client/is-analytics-allowed.d.ts.map +1 -1
  35. package/dist/client/is-analytics-allowed.js +1 -1
  36. package/dist/client/is-analytics-allowed.js.map +1 -1
  37. package/dist/client/server-persisted-anonymous-id.d.ts +4 -2
  38. package/dist/client/server-persisted-anonymous-id.d.ts.map +1 -1
  39. package/dist/client/server-persisted-anonymous-id.js +1 -1
  40. package/dist/client/server-persisted-anonymous-id.js.map +1 -1
  41. package/dist/core/consent-config.d.ts +2 -2
  42. package/dist/core/consent-config.js +1 -1
  43. package/dist/core/consent-receipt.d.ts +6 -6
  44. package/dist/core/consent-receipt.js +1 -1
  45. package/dist/core/consent.d.ts +23 -11
  46. package/dist/core/consent.d.ts.map +1 -1
  47. package/dist/core/consent.js +12 -8
  48. package/dist/core/consent.js.map +1 -1
  49. package/dist/core/cookie.d.ts +2 -2
  50. package/dist/core/cookie.js +2 -2
  51. package/dist/core/event-catalog.d.ts +1 -1
  52. package/dist/core/event-catalog.js +1 -1
  53. package/dist/destinations/ad-consent.d.ts +2 -2
  54. package/dist/destinations/ad-consent.js +1 -1
  55. package/dist/destinations/google-analytics.d.ts +16 -8
  56. package/dist/destinations/google-analytics.d.ts.map +1 -1
  57. package/dist/destinations/google-analytics.js +4 -4
  58. package/dist/destinations/google-analytics.js.map +1 -1
  59. package/dist/destinations/google-consent.d.ts +9 -7
  60. package/dist/destinations/google-consent.d.ts.map +1 -1
  61. package/dist/destinations/google-consent.js +5 -5
  62. package/dist/destinations/google-consent.js.map +1 -1
  63. package/dist/destinations/meta.d.ts +7 -5
  64. package/dist/destinations/meta.d.ts.map +1 -1
  65. package/dist/destinations/meta.js +2 -2
  66. package/dist/destinations/meta.js.map +1 -1
  67. package/dist/destinations/microsoft-uet.d.ts +7 -5
  68. package/dist/destinations/microsoft-uet.d.ts.map +1 -1
  69. package/dist/destinations/microsoft-uet.js +2 -2
  70. package/dist/destinations/microsoft-uet.js.map +1 -1
  71. package/dist/destinations/shared.d.ts +7 -3
  72. package/dist/destinations/shared.d.ts.map +1 -1
  73. package/dist/destinations/shared.js +3 -1
  74. package/dist/destinations/shared.js.map +1 -1
  75. package/dist/destinations/tiktok.d.ts +7 -5
  76. package/dist/destinations/tiktok.d.ts.map +1 -1
  77. package/dist/destinations/tiktok.js +2 -2
  78. package/dist/destinations/tiktok.js.map +1 -1
  79. package/dist/destinations/vercel-analytics.d.ts +3 -1
  80. package/dist/destinations/vercel-analytics.d.ts.map +1 -1
  81. package/dist/destinations/vercel-analytics.js.map +1 -1
  82. package/dist/react/consent-banner.d.ts +28 -0
  83. package/dist/react/consent-banner.d.ts.map +1 -1
  84. package/dist/react/consent-banner.js +11 -7
  85. package/dist/react/consent-banner.js.map +1 -1
  86. package/dist/react/gtag-consent-bootstrap.d.ts +4 -2
  87. package/dist/react/gtag-consent-bootstrap.d.ts.map +1 -1
  88. package/dist/react/gtag-consent-bootstrap.js +1 -1
  89. package/dist/react/gtag-consent-bootstrap.js.map +1 -1
  90. package/dist/react/use-consent.d.ts +4 -0
  91. package/dist/react/use-consent.d.ts.map +1 -1
  92. package/dist/react/use-consent.js.map +1 -1
  93. package/dist/react/use-google-consent-sync.d.ts +4 -2
  94. package/dist/react/use-google-consent-sync.d.ts.map +1 -1
  95. package/dist/react/use-google-consent-sync.js +1 -1
  96. package/dist/react/use-google-consent-sync.js.map +1 -1
  97. package/dist/react/use-initial-consent.d.ts +1 -1
  98. package/dist/react/use-initial-consent.js +1 -1
  99. package/dist/server/anonymous-id-cookie.d.ts +7 -5
  100. package/dist/server/anonymous-id-cookie.d.ts.map +1 -1
  101. package/dist/server/anonymous-id-cookie.js +4 -4
  102. package/dist/server/anonymous-id-cookie.js.map +1 -1
  103. package/dist/server/consent-receipt-store.d.ts +4 -4
  104. package/dist/server/consent-receipt-store.js +2 -2
  105. package/dist/server/consent-receipt.d.ts +4 -4
  106. package/dist/server/consent-receipt.js +3 -3
  107. package/dist/server/initial-consent.d.ts +4 -2
  108. package/dist/server/initial-consent.d.ts.map +1 -1
  109. package/dist/server/initial-consent.js +1 -1
  110. package/dist/server/initial-consent.js.map +1 -1
  111. package/dist/server/measurement-protocol.d.ts +9 -7
  112. package/dist/server/measurement-protocol.d.ts.map +1 -1
  113. package/dist/server/measurement-protocol.js +3 -3
  114. package/dist/server/measurement-protocol.js.map +1 -1
  115. package/dist/server/region.d.ts +2 -2
  116. package/dist/server/region.js +2 -2
  117. package/dist/server/user-deletion.d.ts +9 -5
  118. package/dist/server/user-deletion.d.ts.map +1 -1
  119. package/dist/server/user-deletion.js +2 -2
  120. package/dist/server/user-deletion.js.map +1 -1
  121. package/dist/tooling/import-protection.d.ts +1 -1
  122. package/dist/tooling/import-protection.js +1 -1
  123. package/package.json +7 -7
  124. package/src/adapters/tanstack-start.ts +11 -7
  125. package/src/client/ad-framework-consent.ts +8 -6
  126. package/src/client/browser-cookie.ts +1 -1
  127. package/src/client/consent-runtime.ts +5 -3
  128. package/src/client/consent-withdrawal.ts +4 -2
  129. package/src/client/cookie-anonymous-id.ts +7 -3
  130. package/src/client/create-client-tracker.ts +7 -1
  131. package/src/client/initial-consent-store.ts +6 -4
  132. package/src/client/is-analytics-allowed.ts +4 -2
  133. package/src/client/server-persisted-anonymous-id.ts +4 -2
  134. package/src/core/consent-config.ts +2 -2
  135. package/src/core/consent-receipt.ts +6 -6
  136. package/src/core/consent.ts +23 -11
  137. package/src/core/cookie.ts +2 -2
  138. package/src/core/event-catalog.ts +1 -1
  139. package/src/destinations/ad-consent.ts +2 -2
  140. package/src/destinations/google-analytics.ts +16 -8
  141. package/src/destinations/google-consent.ts +9 -7
  142. package/src/destinations/meta.ts +7 -5
  143. package/src/destinations/microsoft-uet.ts +7 -5
  144. package/src/destinations/shared.ts +10 -4
  145. package/src/destinations/tiktok.ts +7 -5
  146. package/src/destinations/vercel-analytics.ts +3 -1
  147. package/src/react/consent-banner.tsx +34 -8
  148. package/src/react/gtag-consent-bootstrap.tsx +4 -2
  149. package/src/react/use-consent.ts +4 -0
  150. package/src/react/use-google-consent-sync.ts +4 -2
  151. package/src/react/use-initial-consent.ts +1 -1
  152. package/src/server/anonymous-id-cookie.ts +7 -5
  153. package/src/server/consent-receipt-store.ts +4 -4
  154. package/src/server/consent-receipt.ts +4 -4
  155. package/src/server/initial-consent.ts +4 -2
  156. package/src/server/measurement-protocol.ts +9 -7
  157. package/src/server/region.ts +2 -2
  158. package/src/server/user-deletion.ts +9 -5
  159. package/src/tooling/import-protection.ts +1 -1
@@ -3,7 +3,9 @@ import { resolveConsentMode, resolveDefaultConsent, STRICTEST_INITIAL_CONSENT }
3
3
  import { resolveRegionFromCountryCode } from "#/server/region";
4
4
 
5
5
  /**
6
- * @since 1.0.0-canary.6
6
+ * Options for `resolveInitialConsent`.
7
+ *
8
+ * @since 0.5.0-canary.6
7
9
  */
8
10
  export interface InitialConsentOptions {
9
11
  /** ISO 3166-1 alpha-2 from the geo header; missing → the strictest opt-in default. */
@@ -24,7 +26,7 @@ export interface InitialConsentOptions {
24
26
  * {@link STRICTEST_INITIAL_CONSENT} instead of `"other"`'s opt-out. Conflating the two
25
27
  * would grant analytics by default to every visitor, EU included, on a geo-less host.
26
28
  *
27
- * @since 1.0.0-canary.6
29
+ * @since 0.5.0-canary.6
28
30
  */
29
31
  export function resolveInitialConsent(options: InitialConsentOptions): InitialConsent {
30
32
  if (!options.countryCode) {
@@ -3,7 +3,7 @@ import type { ConsentDecision } from "#/core/consent";
3
3
  /**
4
4
  * A GA4 event for the Measurement Protocol. `params` are flat scalars — GA4 rejects nested values and booleans.
5
5
  *
6
- * @since 1.0.0-canary.7
6
+ * @since 0.5.0-canary.6
7
7
  */
8
8
  export interface MeasurementProtocolEvent {
9
9
  name: string;
@@ -13,7 +13,7 @@ export interface MeasurementProtocolEvent {
13
13
  /**
14
14
  * The GA4 MP `consent` object — the two ad-consent signals the payload accepts.
15
15
  *
16
- * @since 1.0.0-canary.7
16
+ * @since 0.5.0-canary.6
17
17
  */
18
18
  export interface MeasurementProtocolConsent {
19
19
  ad_personalization: "DENIED" | "GRANTED";
@@ -23,7 +23,7 @@ export interface MeasurementProtocolConsent {
23
23
  /**
24
24
  * Maps the package `ConsentDecision` to GA4 MP consent signals — `ads` drives both ad fields.
25
25
  *
26
- * @since 1.0.0-canary.7
26
+ * @since 0.5.0-canary.6
27
27
  */
28
28
  export function toMeasurementProtocolConsent(decision: ConsentDecision): MeasurementProtocolConsent {
29
29
  const state = decision.ads ? "GRANTED" : "DENIED";
@@ -38,7 +38,7 @@ export function toMeasurementProtocolConsent(decision: ConsentDecision): Measure
38
38
  * Measurement Protocol reference, so anything that doesn't parse returns `undefined` rather
39
39
  * than sending a malformed id.
40
40
  *
41
- * @since 1.0.0-canary.7
41
+ * @since 0.5.0-canary.6
42
42
  */
43
43
  export function extractGaClientId(gaCookieValue: string | undefined): string | undefined {
44
44
  if (!gaCookieValue) {
@@ -57,7 +57,7 @@ export function extractGaClientId(gaCookieValue: string | undefined): string | u
57
57
  /**
58
58
  * The one network primitive the sender needs — injected so the package ships no HTTP client.
59
59
  *
60
- * @since 1.0.0-canary.7
60
+ * @since 0.5.0-canary.6
61
61
  */
62
62
  export type MeasurementProtocolTransport = (request: { body: string; url: string }) => Promise<void>;
63
63
 
@@ -78,7 +78,9 @@ async function defaultTransport(request: { body: string; url: string }): Promise
78
78
  }
79
79
 
80
80
  /**
81
- * @since 1.0.0-canary.7
81
+ * Options for `sendMeasurementProtocolEvents`.
82
+ *
83
+ * @since 0.5.0-canary.6
82
84
  */
83
85
  export interface SendMeasurementProtocolEventsOptions {
84
86
  /** GA4 **API Secret** — read server-side from config, never a client-exposed var. */
@@ -99,7 +101,7 @@ export interface SendMeasurementProtocolEventsOptions {
99
101
  *
100
102
  * @see https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events
101
103
  *
102
- * @since 1.0.0-canary.7
104
+ * @since 0.5.0-canary.6
103
105
  */
104
106
  export async function sendMeasurementProtocolEvents(options: SendMeasurementProtocolEventsOptions): Promise<void> {
105
107
  const origin = options.endpointOrigin ?? DEFAULT_ENDPOINT_ORIGIN;
@@ -3,7 +3,7 @@ import type { ConsentRegion } from "#/core/consent";
3
3
  /**
4
4
  * EU member states — GDPR opt-in via `resolveConsentMode("eu")`.
5
5
  *
6
- * @since 1.0.0-canary.6
6
+ * @since 0.5.0-canary.6
7
7
  */
8
8
  export const EU_COUNTRY_CODES: ReadonlySet<string> = new Set([
9
9
  "AT",
@@ -42,7 +42,7 @@ export const EU_COUNTRY_CODES: ReadonlySet<string> = new Set([
42
42
  * Restricted edge runtimes that cannot import this package should duplicate these codes
43
43
  * and keep a sync test against this export.
44
44
  *
45
- * @since 1.0.0-canary.6
45
+ * @since 0.5.0-canary.6
46
46
  */
47
47
  export const OPT_IN_EQUIVALENT_COUNTRY_CODES: ReadonlySet<string> = new Set(["GB", "IS", "LI", "NO"]);
48
48
 
@@ -12,7 +12,9 @@
12
12
  const ADMIN_API_ORIGIN = "https://analyticsadmin.googleapis.com";
13
13
 
14
14
  /**
15
- * @since 1.0.0-canary.7
15
+ * The URL and body of an Admin API `submitUserDeletion` call, ready for an authenticated transport.
16
+ *
17
+ * @since 0.5.0-canary.6
16
18
  */
17
19
  export interface Ga4UserDeletionRequest {
18
20
  body: { clientId: string };
@@ -27,7 +29,7 @@ export interface Ga4UserDeletionRequest {
27
29
  *
28
30
  * @param options - `propertyId` is the numeric GA4 property (no `properties/` prefix).
29
31
  *
30
- * @since 1.0.0-canary.7
32
+ * @since 0.5.0-canary.6
31
33
  */
32
34
  export function buildGa4UserDeletionRequest(options: { clientId: string; propertyId: string }): Ga4UserDeletionRequest {
33
35
  return {
@@ -39,7 +41,7 @@ export function buildGa4UserDeletionRequest(options: { clientId: string; propert
39
41
  /**
40
42
  * The one network primitive the sender needs — injected so the package ships no HTTP client.
41
43
  *
42
- * @since 1.0.0-canary.7
44
+ * @since 0.5.0-canary.6
43
45
  */
44
46
  export type Ga4UserDeletionTransport = (request: {
45
47
  body: string;
@@ -60,7 +62,9 @@ async function defaultTransport(request: {
60
62
  }
61
63
 
62
64
  /**
63
- * @since 1.0.0-canary.7
65
+ * Options for `submitGa4UserDeletion`.
66
+ *
67
+ * @since 0.5.0-canary.6
64
68
  */
65
69
  export interface SubmitGa4UserDeletionOptions {
66
70
  /** A bearer token for the `https://www.googleapis.com/auth/analytics.edit` scope — the caller owns OAuth. */
@@ -77,7 +81,7 @@ export interface SubmitGa4UserDeletionOptions {
77
81
  * next run; it does **not** reach previously-aggregated reports or BigQuery exports
78
82
  * (spec-data-subject-rights §3).
79
83
  *
80
- * @since 1.0.0-canary.7
84
+ * @since 0.5.0-canary.6
81
85
  */
82
86
  export async function submitGa4UserDeletion(options: SubmitGa4UserDeletionOptions): Promise<void> {
83
87
  const request = buildGa4UserDeletionRequest({ clientId: options.clientId, propertyId: options.propertyId });
@@ -13,7 +13,7 @@
13
13
  * });
14
14
  * ```
15
15
  *
16
- * @since 1.0.0-canary.6
16
+ * @since 0.5.0-canary.6
17
17
  */
18
18
  export const SERVER_ONLY_SUBPATHS: ReadonlyArray<string> = [
19
19
  "@codefast/tracking/server",