@codefast/tracking 0.7.0 → 0.7.2
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 +21 -0
- package/README.md +235 -105
- package/dist/adapters/tanstack-start.d.ts +12 -9
- package/dist/adapters/tanstack-start.js +5 -6
- package/dist/client/ad-framework-consent.d.ts +9 -8
- package/dist/client/ad-framework-consent.js +4 -5
- package/dist/client/browser-cookie.d.ts +2 -3
- package/dist/client/browser-cookie.js +2 -3
- package/dist/client/consent-runtime.d.ts +6 -5
- package/dist/client/consent-runtime.js +2 -3
- package/dist/client/consent-storage.d.ts +1 -2
- package/dist/client/consent-storage.js +1 -2
- package/dist/client/consent-withdrawal.d.ts +5 -4
- package/dist/client/consent-withdrawal.js +2 -3
- package/dist/client/cookie-anonymous-id.d.ts +8 -5
- package/dist/client/cookie-anonymous-id.js +2 -3
- package/dist/client/create-client-tracker.d.ts +8 -3
- package/dist/client/create-client-tracker.js +3 -2
- package/dist/client/gpc.d.ts +1 -2
- package/dist/client/gpc.js +1 -2
- package/dist/client/initial-consent-store.d.ts +7 -6
- package/dist/client/initial-consent-store.js +2 -3
- package/dist/client/is-analytics-allowed.d.ts +5 -4
- package/dist/client/is-analytics-allowed.js +2 -3
- package/dist/client/server-persisted-anonymous-id.d.ts +5 -4
- package/dist/client/server-persisted-anonymous-id.js +2 -3
- package/dist/core/consent-config.d.ts +3 -4
- package/dist/core/consent-config.js +2 -3
- package/dist/core/consent-receipt.d.ts +7 -8
- package/dist/core/consent-receipt.js +2 -3
- package/dist/core/consent.d.ts +24 -13
- package/dist/core/consent.js +13 -10
- package/dist/core/cookie.d.ts +3 -4
- package/dist/core/cookie.js +3 -4
- package/dist/core/destination.d.ts +1 -2
- package/dist/core/destination.js +1 -2
- package/dist/core/event-catalog.d.ts +2 -3
- package/dist/core/event-catalog.js +2 -3
- package/dist/core/event-id.d.ts +1 -2
- package/dist/core/event-id.js +1 -2
- package/dist/core/tracked-event.d.ts +1 -2
- package/dist/core/tracked-event.js +1 -2
- package/dist/destinations/ad-consent.d.ts +3 -4
- package/dist/destinations/ad-consent.js +2 -3
- package/dist/destinations/google-analytics.d.ts +17 -10
- package/dist/destinations/google-analytics.js +5 -6
- package/dist/destinations/google-consent.d.ts +10 -9
- package/dist/destinations/google-consent.js +6 -7
- package/dist/destinations/meta.d.ts +8 -7
- package/dist/destinations/meta.js +3 -4
- package/dist/destinations/microsoft-uet.d.ts +8 -7
- package/dist/destinations/microsoft-uet.js +3 -4
- package/dist/destinations/shared.d.ts +8 -5
- package/dist/destinations/shared.js +4 -3
- package/dist/destinations/tiktok.d.ts +8 -7
- package/dist/destinations/tiktok.js +3 -4
- package/dist/destinations/vercel-analytics.d.ts +4 -3
- package/dist/destinations/vercel-analytics.js +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/react/consent-banner.d.ts +29 -2
- package/dist/react/consent-banner.js +12 -9
- package/dist/react/gtag-consent-bootstrap.d.ts +5 -4
- package/dist/react/gtag-consent-bootstrap.js +2 -3
- package/dist/react/use-consent.d.ts +5 -2
- package/dist/react/use-consent.js +1 -2
- package/dist/react/use-google-consent-sync.d.ts +5 -4
- package/dist/react/use-google-consent-sync.js +2 -3
- package/dist/react/use-initial-consent.d.ts +2 -3
- package/dist/react/use-initial-consent.js +2 -3
- package/dist/server/anonymous-id-cookie.d.ts +8 -7
- package/dist/server/anonymous-id-cookie.js +5 -6
- package/dist/server/consent-receipt-store.d.ts +5 -6
- package/dist/server/consent-receipt-store.js +3 -4
- package/dist/server/consent-receipt.d.ts +5 -6
- package/dist/server/consent-receipt.js +4 -5
- package/dist/server/initial-consent.d.ts +5 -4
- package/dist/server/initial-consent.js +2 -3
- package/dist/server/measurement-protocol.d.ts +10 -9
- package/dist/server/measurement-protocol.js +4 -5
- package/dist/server/region.d.ts +3 -4
- package/dist/server/region.js +3 -4
- package/dist/server/user-deletion.d.ts +10 -7
- package/dist/server/user-deletion.js +3 -4
- package/dist/tooling/import-protection.d.ts +2 -3
- package/dist/tooling/import-protection.js +2 -3
- package/package.json +11 -62
- package/dist/adapters/tanstack-start.d.ts.map +0 -1
- package/dist/adapters/tanstack-start.js.map +0 -1
- package/dist/client/ad-framework-consent.d.ts.map +0 -1
- package/dist/client/ad-framework-consent.js.map +0 -1
- package/dist/client/browser-cookie.d.ts.map +0 -1
- package/dist/client/browser-cookie.js.map +0 -1
- package/dist/client/consent-runtime.d.ts.map +0 -1
- package/dist/client/consent-runtime.js.map +0 -1
- package/dist/client/consent-storage.d.ts.map +0 -1
- package/dist/client/consent-storage.js.map +0 -1
- package/dist/client/consent-withdrawal.d.ts.map +0 -1
- package/dist/client/consent-withdrawal.js.map +0 -1
- package/dist/client/cookie-anonymous-id.d.ts.map +0 -1
- package/dist/client/cookie-anonymous-id.js.map +0 -1
- package/dist/client/create-client-tracker.d.ts.map +0 -1
- package/dist/client/create-client-tracker.js.map +0 -1
- package/dist/client/gpc.d.ts.map +0 -1
- package/dist/client/gpc.js.map +0 -1
- package/dist/client/initial-consent-store.d.ts.map +0 -1
- package/dist/client/initial-consent-store.js.map +0 -1
- package/dist/client/is-analytics-allowed.d.ts.map +0 -1
- package/dist/client/is-analytics-allowed.js.map +0 -1
- package/dist/client/server-persisted-anonymous-id.d.ts.map +0 -1
- package/dist/client/server-persisted-anonymous-id.js.map +0 -1
- package/dist/core/consent-config.d.ts.map +0 -1
- package/dist/core/consent-config.js.map +0 -1
- package/dist/core/consent-receipt.d.ts.map +0 -1
- package/dist/core/consent-receipt.js.map +0 -1
- package/dist/core/consent.d.ts.map +0 -1
- package/dist/core/consent.js.map +0 -1
- package/dist/core/cookie.d.ts.map +0 -1
- package/dist/core/cookie.js.map +0 -1
- package/dist/core/destination.d.ts.map +0 -1
- package/dist/core/destination.js.map +0 -1
- package/dist/core/event-catalog.d.ts.map +0 -1
- package/dist/core/event-catalog.js.map +0 -1
- package/dist/core/event-id.d.ts.map +0 -1
- package/dist/core/event-id.js.map +0 -1
- package/dist/core/tracked-event.d.ts.map +0 -1
- package/dist/core/tracked-event.js.map +0 -1
- package/dist/destinations/ad-consent.d.ts.map +0 -1
- package/dist/destinations/ad-consent.js.map +0 -1
- package/dist/destinations/google-analytics.d.ts.map +0 -1
- package/dist/destinations/google-analytics.js.map +0 -1
- package/dist/destinations/google-consent.d.ts.map +0 -1
- package/dist/destinations/google-consent.js.map +0 -1
- package/dist/destinations/meta.d.ts.map +0 -1
- package/dist/destinations/meta.js.map +0 -1
- package/dist/destinations/microsoft-uet.d.ts.map +0 -1
- package/dist/destinations/microsoft-uet.js.map +0 -1
- package/dist/destinations/shared.d.ts.map +0 -1
- package/dist/destinations/shared.js.map +0 -1
- package/dist/destinations/tiktok.d.ts.map +0 -1
- package/dist/destinations/tiktok.js.map +0 -1
- package/dist/destinations/vercel-analytics.d.ts.map +0 -1
- package/dist/destinations/vercel-analytics.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react/consent-banner.d.ts.map +0 -1
- package/dist/react/consent-banner.js.map +0 -1
- package/dist/react/gtag-consent-bootstrap.d.ts.map +0 -1
- package/dist/react/gtag-consent-bootstrap.js.map +0 -1
- package/dist/react/use-consent.d.ts.map +0 -1
- package/dist/react/use-consent.js.map +0 -1
- package/dist/react/use-google-consent-sync.d.ts.map +0 -1
- package/dist/react/use-google-consent-sync.js.map +0 -1
- package/dist/react/use-initial-consent.d.ts.map +0 -1
- package/dist/react/use-initial-consent.js.map +0 -1
- package/dist/server/anonymous-id-cookie.d.ts.map +0 -1
- package/dist/server/anonymous-id-cookie.js.map +0 -1
- package/dist/server/consent-receipt-store.d.ts.map +0 -1
- package/dist/server/consent-receipt-store.js.map +0 -1
- package/dist/server/consent-receipt.d.ts.map +0 -1
- package/dist/server/consent-receipt.js.map +0 -1
- package/dist/server/initial-consent.d.ts.map +0 -1
- package/dist/server/initial-consent.js.map +0 -1
- package/dist/server/measurement-protocol.d.ts.map +0 -1
- package/dist/server/measurement-protocol.js.map +0 -1
- package/dist/server/region.d.ts.map +0 -1
- package/dist/server/region.js.map +0 -1
- package/dist/server/user-deletion.d.ts.map +0 -1
- package/dist/server/user-deletion.js.map +0 -1
- package/dist/tooling/import-protection.d.ts.map +0 -1
- package/dist/tooling/import-protection.js.map +0 -1
- package/src/adapters/tanstack-start.ts +0 -135
- package/src/client/ad-framework-consent.ts +0 -86
- package/src/client/browser-cookie.ts +0 -16
- package/src/client/consent-runtime.ts +0 -80
- package/src/client/consent-storage.ts +0 -125
- package/src/client/consent-withdrawal.ts +0 -32
- package/src/client/cookie-anonymous-id.ts +0 -112
- package/src/client/create-client-tracker.ts +0 -168
- package/src/client/gpc.ts +0 -15
- package/src/client/initial-consent-store.ts +0 -218
- package/src/client/is-analytics-allowed.ts +0 -43
- package/src/client/server-persisted-anonymous-id.ts +0 -102
- package/src/core/consent-config.ts +0 -27
- package/src/core/consent-receipt.ts +0 -115
- package/src/core/consent.ts +0 -286
- package/src/core/cookie.ts +0 -29
- package/src/core/destination.ts +0 -29
- package/src/core/event-catalog.ts +0 -54
- package/src/core/event-id.ts +0 -8
- package/src/core/tracked-event.ts +0 -14
- package/src/css/consent.css +0 -119
- package/src/destinations/ad-consent.ts +0 -29
- package/src/destinations/google-analytics.ts +0 -296
- package/src/destinations/google-consent.ts +0 -164
- package/src/destinations/meta.ts +0 -96
- package/src/destinations/microsoft-uet.ts +0 -86
- package/src/destinations/shared.ts +0 -45
- package/src/destinations/tiktok.ts +0 -85
- package/src/destinations/vercel-analytics.ts +0 -39
- package/src/index.ts +0 -171
- package/src/react/consent-banner.tsx +0 -360
- package/src/react/gtag-consent-bootstrap.tsx +0 -48
- package/src/react/use-consent.ts +0 -119
- package/src/react/use-google-consent-sync.ts +0 -38
- package/src/react/use-initial-consent.ts +0 -22
- package/src/server/anonymous-id-cookie.ts +0 -103
- package/src/server/consent-receipt-store.ts +0 -79
- package/src/server/consent-receipt.ts +0 -89
- package/src/server/initial-consent.ts +0 -46
- package/src/server/measurement-protocol.ts +0 -114
- package/src/server/region.ts +0 -77
- package/src/server/user-deletion.ts +0 -93
- package/src/tooling/import-protection.ts +0 -22
package/src/server/region.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { ConsentRegion } from "#/core/consent";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* EU member states — GDPR opt-in via `resolveConsentMode("eu")`.
|
|
5
|
-
*
|
|
6
|
-
* @since 1.0.0-canary.6
|
|
7
|
-
*/
|
|
8
|
-
export const EU_COUNTRY_CODES: ReadonlySet<string> = new Set([
|
|
9
|
-
"AT",
|
|
10
|
-
"BE",
|
|
11
|
-
"BG",
|
|
12
|
-
"HR",
|
|
13
|
-
"CY",
|
|
14
|
-
"CZ",
|
|
15
|
-
"DK",
|
|
16
|
-
"EE",
|
|
17
|
-
"FI",
|
|
18
|
-
"FR",
|
|
19
|
-
"DE",
|
|
20
|
-
"GR",
|
|
21
|
-
"HU",
|
|
22
|
-
"IE",
|
|
23
|
-
"IT",
|
|
24
|
-
"LV",
|
|
25
|
-
"LT",
|
|
26
|
-
"LU",
|
|
27
|
-
"MT",
|
|
28
|
-
"NL",
|
|
29
|
-
"PL",
|
|
30
|
-
"PT",
|
|
31
|
-
"RO",
|
|
32
|
-
"SK",
|
|
33
|
-
"SI",
|
|
34
|
-
"ES",
|
|
35
|
-
"SE",
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* UK GDPR (post-Brexit) and EEA/EFTA states that apply GDPR-equivalent rules — mapped to
|
|
40
|
-
* the same `"eu"` consent region so they get opt-in, not the `"other"` opt-out default.
|
|
41
|
-
*
|
|
42
|
-
* Restricted edge runtimes that cannot import this package should duplicate these codes
|
|
43
|
-
* and keep a sync test against this export.
|
|
44
|
-
*
|
|
45
|
-
* @since 1.0.0-canary.6
|
|
46
|
-
*/
|
|
47
|
-
export const OPT_IN_EQUIVALENT_COUNTRY_CODES: ReadonlySet<string> = new Set(["GB", "IS", "LI", "NO"]);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Unrecognized codes fall back to "other", which `resolveConsentMode` treats as
|
|
51
|
-
* opt-out — safe only because opt-in regions (EU/VN plus UK/EEA/EFTA above) are matched
|
|
52
|
-
* explicitly. A *missing* code also maps to "other" here, but `resolveInitialConsent`
|
|
53
|
-
* intercepts that case first and fails closed — unknown is not known-elsewhere.
|
|
54
|
-
*
|
|
55
|
-
* @since 0.5.0-canary.4
|
|
56
|
-
*/
|
|
57
|
-
export function resolveRegionFromCountryCode(countryCode: string | undefined): ConsentRegion {
|
|
58
|
-
if (!countryCode) {
|
|
59
|
-
return "other";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const normalized = countryCode.toUpperCase();
|
|
63
|
-
|
|
64
|
-
if (EU_COUNTRY_CODES.has(normalized) || OPT_IN_EQUIVALENT_COUNTRY_CODES.has(normalized)) {
|
|
65
|
-
return "eu";
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (normalized === "VN") {
|
|
69
|
-
return "vn";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (normalized === "US") {
|
|
73
|
-
return "us";
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return "other";
|
|
77
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DSR delegation for GA4 (spec-data-subject-rights §3): the platform ships its own
|
|
3
|
-
* per-visitor deletion, so the system **delegates** rather than reimplementing a deletion
|
|
4
|
-
* store. Targets the current **Analytics Admin API** `properties.submitUserDeletion` — the
|
|
5
|
-
* legacy v3 `userDeletionRequests:upsert` was sunset with Universal Analytics, so the spec's
|
|
6
|
-
* DSR-V3 `{ id: { type: "CLIENT_ID", userId } }` shape is stale; the current request keys the
|
|
7
|
-
* subject with a flat `clientId` (a oneof with `userId`/`appInstanceId`/`userProvidedData`).
|
|
8
|
-
*
|
|
9
|
-
* @see https://developers.google.com/analytics/devguides/config/userdeletion/migration
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const ADMIN_API_ORIGIN = "https://analyticsadmin.googleapis.com";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @since 1.0.0-canary.7
|
|
16
|
-
*/
|
|
17
|
-
export interface Ga4UserDeletionRequest {
|
|
18
|
-
body: { clientId: string };
|
|
19
|
-
url: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Builds the Admin API `submitUserDeletion` request that erases one GA4 subject by
|
|
24
|
-
* `clientId` (the `_ga`-cookie id — see `extractGaClientId`). Pure and network-free so the
|
|
25
|
-
* request shape can be snapshotted/verified; pair it with {@link submitGa4UserDeletion} or
|
|
26
|
-
* any authenticated transport.
|
|
27
|
-
*
|
|
28
|
-
* @param options - `propertyId` is the numeric GA4 property (no `properties/` prefix).
|
|
29
|
-
*
|
|
30
|
-
* @since 1.0.0-canary.7
|
|
31
|
-
*/
|
|
32
|
-
export function buildGa4UserDeletionRequest(options: { clientId: string; propertyId: string }): Ga4UserDeletionRequest {
|
|
33
|
-
return {
|
|
34
|
-
body: { clientId: options.clientId },
|
|
35
|
-
url: `${ADMIN_API_ORIGIN}/v1alpha/properties/${options.propertyId}:submitUserDeletion`,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The one network primitive the sender needs — injected so the package ships no HTTP client.
|
|
41
|
-
*
|
|
42
|
-
* @since 1.0.0-canary.7
|
|
43
|
-
*/
|
|
44
|
-
export type Ga4UserDeletionTransport = (request: {
|
|
45
|
-
body: string;
|
|
46
|
-
headers: Record<string, string>;
|
|
47
|
-
url: string;
|
|
48
|
-
}) => Promise<void>;
|
|
49
|
-
|
|
50
|
-
async function defaultTransport(request: {
|
|
51
|
-
body: string;
|
|
52
|
-
headers: Record<string, string>;
|
|
53
|
-
url: string;
|
|
54
|
-
}): Promise<void> {
|
|
55
|
-
const response = await fetch(request.url, { body: request.body, headers: request.headers, method: "POST" });
|
|
56
|
-
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
throw new Error(`GA4 user deletion responded ${String(response.status)}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @since 1.0.0-canary.7
|
|
64
|
-
*/
|
|
65
|
-
export interface SubmitGa4UserDeletionOptions {
|
|
66
|
-
/** A bearer token for the `https://www.googleapis.com/auth/analytics.edit` scope — the caller owns OAuth. */
|
|
67
|
-
accessToken: string;
|
|
68
|
-
clientId: string;
|
|
69
|
-
propertyId: string;
|
|
70
|
-
transport?: Ga4UserDeletionTransport | undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Submits a GA4 user-deletion request for one `clientId`. Authorization is the caller's:
|
|
75
|
-
* pass a bearer token minted from a service account (never baked into the package). The
|
|
76
|
-
* deletion removes the subject from the Individual User report within ~72h and purges at the
|
|
77
|
-
* next run; it does **not** reach previously-aggregated reports or BigQuery exports
|
|
78
|
-
* (spec-data-subject-rights §3).
|
|
79
|
-
*
|
|
80
|
-
* @since 1.0.0-canary.7
|
|
81
|
-
*/
|
|
82
|
-
export async function submitGa4UserDeletion(options: SubmitGa4UserDeletionOptions): Promise<void> {
|
|
83
|
-
const request = buildGa4UserDeletionRequest({ clientId: options.clientId, propertyId: options.propertyId });
|
|
84
|
-
|
|
85
|
-
await (options.transport ?? defaultTransport)({
|
|
86
|
-
body: JSON.stringify(request.body),
|
|
87
|
-
headers: {
|
|
88
|
-
authorization: `Bearer ${options.accessToken}`,
|
|
89
|
-
"content-type": "application/json",
|
|
90
|
-
},
|
|
91
|
-
url: request.url,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `@codefast/tracking` subpaths every client bundle must deny (picomatch patterns) —
|
|
3
|
-
* framework-neutral data each build tool maps to its own guard: TanStack Start's
|
|
4
|
-
* `importProtection.client.specifiers`, Next's `server-only`, Remix's `.server` convention.
|
|
5
|
-
* Ships and versions with the package instead of going stale in each consumer's config.
|
|
6
|
-
* Nothing in this package imports it — its consumers are app build configs (see apps/ui
|
|
7
|
-
* vite.config.ts).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* tanstackStart({
|
|
12
|
-
* importProtection: { client: { specifiers: [...SERVER_ONLY_SUBPATHS] } },
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @since 1.0.0-canary.6
|
|
17
|
-
*/
|
|
18
|
-
export const SERVER_ONLY_SUBPATHS: ReadonlyArray<string> = [
|
|
19
|
-
"@codefast/tracking/server",
|
|
20
|
-
"@codefast/tracking/server/**",
|
|
21
|
-
"@codefast/tracking/adapters/**",
|
|
22
|
-
];
|