@codefast/tracking 0.7.0 → 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.
- package/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/adapters/tanstack-start.d.ts +11 -7
- package/dist/adapters/tanstack-start.d.ts.map +1 -1
- package/dist/adapters/tanstack-start.js +4 -4
- package/dist/adapters/tanstack-start.js.map +1 -1
- package/dist/client/ad-framework-consent.d.ts +8 -6
- package/dist/client/ad-framework-consent.d.ts.map +1 -1
- package/dist/client/ad-framework-consent.js +3 -3
- package/dist/client/ad-framework-consent.js.map +1 -1
- package/dist/client/browser-cookie.d.ts +1 -1
- package/dist/client/browser-cookie.js +1 -1
- package/dist/client/consent-runtime.d.ts +5 -3
- package/dist/client/consent-runtime.d.ts.map +1 -1
- package/dist/client/consent-runtime.js +1 -1
- package/dist/client/consent-runtime.js.map +1 -1
- package/dist/client/consent-withdrawal.d.ts +4 -2
- package/dist/client/consent-withdrawal.d.ts.map +1 -1
- package/dist/client/consent-withdrawal.js +1 -1
- package/dist/client/consent-withdrawal.js.map +1 -1
- package/dist/client/cookie-anonymous-id.d.ts +7 -3
- package/dist/client/cookie-anonymous-id.d.ts.map +1 -1
- package/dist/client/cookie-anonymous-id.js +1 -1
- package/dist/client/cookie-anonymous-id.js.map +1 -1
- package/dist/client/create-client-tracker.d.ts +7 -1
- package/dist/client/create-client-tracker.d.ts.map +1 -1
- package/dist/client/create-client-tracker.js +2 -0
- package/dist/client/create-client-tracker.js.map +1 -1
- package/dist/client/initial-consent-store.d.ts +6 -4
- package/dist/client/initial-consent-store.d.ts.map +1 -1
- package/dist/client/initial-consent-store.js +1 -1
- package/dist/client/initial-consent-store.js.map +1 -1
- package/dist/client/is-analytics-allowed.d.ts +4 -2
- package/dist/client/is-analytics-allowed.d.ts.map +1 -1
- package/dist/client/is-analytics-allowed.js +1 -1
- package/dist/client/is-analytics-allowed.js.map +1 -1
- package/dist/client/server-persisted-anonymous-id.d.ts +4 -2
- package/dist/client/server-persisted-anonymous-id.d.ts.map +1 -1
- package/dist/client/server-persisted-anonymous-id.js +1 -1
- package/dist/client/server-persisted-anonymous-id.js.map +1 -1
- package/dist/core/consent-config.d.ts +2 -2
- package/dist/core/consent-config.js +1 -1
- package/dist/core/consent-receipt.d.ts +6 -6
- package/dist/core/consent-receipt.js +1 -1
- package/dist/core/consent.d.ts +23 -11
- package/dist/core/consent.d.ts.map +1 -1
- package/dist/core/consent.js +12 -8
- package/dist/core/consent.js.map +1 -1
- package/dist/core/cookie.d.ts +2 -2
- package/dist/core/cookie.js +2 -2
- package/dist/core/event-catalog.d.ts +1 -1
- package/dist/core/event-catalog.js +1 -1
- package/dist/destinations/ad-consent.d.ts +2 -2
- package/dist/destinations/ad-consent.js +1 -1
- package/dist/destinations/google-analytics.d.ts +16 -8
- package/dist/destinations/google-analytics.d.ts.map +1 -1
- package/dist/destinations/google-analytics.js +4 -4
- package/dist/destinations/google-analytics.js.map +1 -1
- package/dist/destinations/google-consent.d.ts +9 -7
- package/dist/destinations/google-consent.d.ts.map +1 -1
- package/dist/destinations/google-consent.js +5 -5
- package/dist/destinations/google-consent.js.map +1 -1
- package/dist/destinations/meta.d.ts +7 -5
- package/dist/destinations/meta.d.ts.map +1 -1
- package/dist/destinations/meta.js +2 -2
- package/dist/destinations/meta.js.map +1 -1
- package/dist/destinations/microsoft-uet.d.ts +7 -5
- package/dist/destinations/microsoft-uet.d.ts.map +1 -1
- package/dist/destinations/microsoft-uet.js +2 -2
- package/dist/destinations/microsoft-uet.js.map +1 -1
- package/dist/destinations/shared.d.ts +7 -3
- package/dist/destinations/shared.d.ts.map +1 -1
- package/dist/destinations/shared.js +3 -1
- package/dist/destinations/shared.js.map +1 -1
- package/dist/destinations/tiktok.d.ts +7 -5
- package/dist/destinations/tiktok.d.ts.map +1 -1
- package/dist/destinations/tiktok.js +2 -2
- package/dist/destinations/tiktok.js.map +1 -1
- package/dist/destinations/vercel-analytics.d.ts +3 -1
- package/dist/destinations/vercel-analytics.d.ts.map +1 -1
- package/dist/destinations/vercel-analytics.js.map +1 -1
- package/dist/react/consent-banner.d.ts +28 -0
- package/dist/react/consent-banner.d.ts.map +1 -1
- package/dist/react/consent-banner.js +11 -7
- package/dist/react/consent-banner.js.map +1 -1
- package/dist/react/gtag-consent-bootstrap.d.ts +4 -2
- package/dist/react/gtag-consent-bootstrap.d.ts.map +1 -1
- package/dist/react/gtag-consent-bootstrap.js +1 -1
- package/dist/react/gtag-consent-bootstrap.js.map +1 -1
- package/dist/react/use-consent.d.ts +4 -0
- package/dist/react/use-consent.d.ts.map +1 -1
- package/dist/react/use-consent.js.map +1 -1
- package/dist/react/use-google-consent-sync.d.ts +4 -2
- package/dist/react/use-google-consent-sync.d.ts.map +1 -1
- package/dist/react/use-google-consent-sync.js +1 -1
- package/dist/react/use-google-consent-sync.js.map +1 -1
- package/dist/react/use-initial-consent.d.ts +1 -1
- package/dist/react/use-initial-consent.js +1 -1
- package/dist/server/anonymous-id-cookie.d.ts +7 -5
- package/dist/server/anonymous-id-cookie.d.ts.map +1 -1
- package/dist/server/anonymous-id-cookie.js +4 -4
- package/dist/server/anonymous-id-cookie.js.map +1 -1
- package/dist/server/consent-receipt-store.d.ts +4 -4
- package/dist/server/consent-receipt-store.js +2 -2
- package/dist/server/consent-receipt.d.ts +4 -4
- package/dist/server/consent-receipt.js +3 -3
- package/dist/server/initial-consent.d.ts +4 -2
- package/dist/server/initial-consent.d.ts.map +1 -1
- package/dist/server/initial-consent.js +1 -1
- package/dist/server/initial-consent.js.map +1 -1
- package/dist/server/measurement-protocol.d.ts +9 -7
- package/dist/server/measurement-protocol.d.ts.map +1 -1
- package/dist/server/measurement-protocol.js +3 -3
- package/dist/server/measurement-protocol.js.map +1 -1
- package/dist/server/region.d.ts +2 -2
- package/dist/server/region.js +2 -2
- package/dist/server/user-deletion.d.ts +9 -5
- package/dist/server/user-deletion.d.ts.map +1 -1
- package/dist/server/user-deletion.js +2 -2
- package/dist/server/user-deletion.js.map +1 -1
- package/dist/tooling/import-protection.d.ts +1 -1
- package/dist/tooling/import-protection.js +1 -1
- package/package.json +7 -7
- package/src/adapters/tanstack-start.ts +11 -7
- package/src/client/ad-framework-consent.ts +8 -6
- package/src/client/browser-cookie.ts +1 -1
- package/src/client/consent-runtime.ts +5 -3
- package/src/client/consent-withdrawal.ts +4 -2
- package/src/client/cookie-anonymous-id.ts +7 -3
- package/src/client/create-client-tracker.ts +7 -1
- package/src/client/initial-consent-store.ts +6 -4
- package/src/client/is-analytics-allowed.ts +4 -2
- package/src/client/server-persisted-anonymous-id.ts +4 -2
- package/src/core/consent-config.ts +2 -2
- package/src/core/consent-receipt.ts +6 -6
- package/src/core/consent.ts +23 -11
- package/src/core/cookie.ts +2 -2
- package/src/core/event-catalog.ts +1 -1
- package/src/destinations/ad-consent.ts +2 -2
- package/src/destinations/google-analytics.ts +16 -8
- package/src/destinations/google-consent.ts +9 -7
- package/src/destinations/meta.ts +7 -5
- package/src/destinations/microsoft-uet.ts +7 -5
- package/src/destinations/shared.ts +10 -4
- package/src/destinations/tiktok.ts +7 -5
- package/src/destinations/vercel-analytics.ts +3 -1
- package/src/react/consent-banner.tsx +34 -8
- package/src/react/gtag-consent-bootstrap.tsx +4 -2
- package/src/react/use-consent.ts +4 -0
- package/src/react/use-google-consent-sync.ts +4 -2
- package/src/react/use-initial-consent.ts +1 -1
- package/src/server/anonymous-id-cookie.ts +7 -5
- package/src/server/consent-receipt-store.ts +4 -4
- package/src/server/consent-receipt.ts +4 -4
- package/src/server/initial-consent.ts +4 -2
- package/src/server/measurement-protocol.ts +9 -7
- package/src/server/region.ts +2 -2
- package/src/server/user-deletion.ts +9 -5
- 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
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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;
|
package/src/server/region.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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 });
|