@codefast/tracking 1.0.0-canary.6 → 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 +55 -0
- package/README.md +72 -17
- 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.mts → browser-cookie.d.ts} +2 -4
- 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} +3 -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.mts → gpc.d.ts} +2 -4
- 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.mts → consent.d.ts} +49 -51
- 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.mts → cookie.d.ts} +3 -5
- 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.mts → event-id.d.ts} +2 -4
- 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.mts → use-initial-consent.d.ts} +3 -6
- 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.mts → region.d.ts} +5 -15
- 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 +238 -59
- package/src/adapters/tanstack-start.ts +135 -0
- package/src/client/ad-framework-consent.ts +86 -0
- package/src/client/cookie-anonymous-id.ts +19 -0
- package/src/client/create-client-tracker.ts +81 -10
- package/src/client/server-persisted-anonymous-id.ts +4 -1
- package/src/core/consent-receipt.ts +115 -0
- package/src/core/consent.ts +2 -2
- package/src/core/destination.ts +7 -0
- package/src/core/event-catalog.ts +5 -4
- package/src/core/tracked-event.ts +5 -20
- package/src/destinations/ad-consent.ts +29 -0
- package/src/destinations/meta.ts +96 -0
- package/src/destinations/microsoft-uet.ts +86 -0
- package/src/destinations/tiktok.ts +85 -0
- package/src/index.ts +138 -19
- package/src/server/anonymous-id-cookie.ts +49 -22
- package/src/server/consent-receipt-store.ts +79 -0
- package/src/server/consent-receipt.ts +89 -0
- package/src/server/initial-consent.ts +0 -2
- package/src/server/measurement-protocol.ts +114 -0
- package/src/server/region.ts +0 -10
- package/src/server/user-deletion.ts +93 -0
- package/src/tooling/import-protection.ts +22 -0
- package/dist/client/browser-cookie.mjs +0 -15
- package/dist/client/consent-runtime.d.mts +0 -56
- package/dist/client/consent-runtime.mjs +0 -35
- package/dist/client/consent-storage.mjs +0 -82
- package/dist/client/consent-withdrawal.d.mts +0 -21
- package/dist/client/consent-withdrawal.mjs +0 -17
- package/dist/client/cookie-anonymous-id.d.mts +0 -37
- package/dist/client/cookie-anonymous-id.mjs +0 -46
- package/dist/client/create-client-tracker.d.mts +0 -32
- package/dist/client/create-client-tracker.mjs +0 -40
- package/dist/client/gpc.mjs +0 -14
- package/dist/client/index.d.mts +0 -10
- package/dist/client/index.mjs +0 -10
- package/dist/client/initial-consent-store.d.mts +0 -66
- package/dist/client/initial-consent-store.mjs +0 -119
- package/dist/client/is-analytics-allowed.d.mts +0 -29
- package/dist/client/is-analytics-allowed.mjs +0 -23
- package/dist/client/server-persisted-anonymous-id.d.mts +0 -33
- package/dist/client/server-persisted-anonymous-id.mjs +0 -50
- package/dist/core/consent-config.d.mts +0 -27
- package/dist/core/consent-config.mjs +0 -11
- package/dist/core/consent.mjs +0 -152
- package/dist/core/cookie.mjs +0 -23
- package/dist/core/destination.d.mts +0 -25
- package/dist/core/destination.mjs +0 -1
- package/dist/core/event-catalog.d.mts +0 -39
- package/dist/core/event-catalog.mjs +0 -30
- package/dist/core/event-id.mjs +0 -11
- package/dist/core/index.d.mts +0 -8
- package/dist/core/index.mjs +0 -6
- package/dist/core/tracked-event.d.mts +0 -30
- package/dist/core/tracked-event.mjs +0 -1
- package/dist/destinations/google-analytics.d.mts +0 -150
- package/dist/destinations/google-analytics.mjs +0 -130
- package/dist/destinations/google-consent.d.mts +0 -64
- package/dist/destinations/google-consent.mjs +0 -102
- package/dist/destinations/index.d.mts +0 -2
- package/dist/destinations/index.mjs +0 -2
- package/dist/destinations/shared.d.mts +0 -20
- package/dist/destinations/shared.mjs +0 -13
- package/dist/destinations/vercel-analytics.d.mts +0 -28
- package/dist/destinations/vercel-analytics.mjs +0 -23
- package/dist/import-protection.d.mts +0 -19
- package/dist/import-protection.mjs +0 -23
- package/dist/index.d.mts +0 -8
- package/dist/index.mjs +0 -6
- package/dist/react/consent-banner.d.mts +0 -180
- package/dist/react/consent-banner.mjs +0 -214
- package/dist/react/gtag-consent-bootstrap.d.mts +0 -27
- package/dist/react/gtag-consent-bootstrap.mjs +0 -29
- package/dist/react/index.d.mts +0 -6
- package/dist/react/index.mjs +0 -6
- package/dist/react/use-consent.d.mts +0 -45
- package/dist/react/use-consent.mjs +0 -71
- package/dist/react/use-google-consent-sync.d.mts +0 -23
- package/dist/react/use-google-consent-sync.mjs +0 -24
- package/dist/react/use-initial-consent.mjs +0 -19
- package/dist/server/anonymous-id-cookie.d.mts +0 -46
- package/dist/server/anonymous-id-cookie.mjs +0 -51
- package/dist/server/index.d.mts +0 -5
- package/dist/server/index.mjs +0 -4
- package/dist/server/initial-consent.d.mts +0 -29
- package/dist/server/initial-consent.mjs +0 -31
- package/dist/server/region.mjs +0 -77
- package/dist/tanstack-start/index.d.mts +0 -58
- package/dist/tanstack-start/index.mjs +0 -45
- package/src/client/index.ts +0 -28
- package/src/core/index.ts +0 -40
- package/src/destinations/index.ts +0 -19
- package/src/import-protection.ts +0 -20
- package/src/react/index.ts +0 -37
- package/src/server/index.ts +0 -16
- package/src/tanstack-start/index.ts +0 -83
package/dist/core/index.d.mts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CONSENT_CATEGORIES, CONSENT_REGIONS, ConsentCategory, ConsentDecision, ConsentMode, ConsentRecord, ConsentRegion, ConsentStorage, InitialConsent, ResolveDefaultConsentOptions, ResolveEffectiveConsentOptions, STRICTEST_INITIAL_CONSENT, createConsentDecision, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent } from "./consent.mjs";
|
|
2
|
-
import { ConsentConfig, defineConsentConfig } from "./consent-config.mjs";
|
|
3
|
-
import { TrackEvent, TrackedEvent, TrackedEventBase } from "./tracked-event.mjs";
|
|
4
|
-
import { Destination } from "./destination.mjs";
|
|
5
|
-
import { EventCatalog, EventDefinition, assertValidEventProperties, defineEventCatalog } from "./event-catalog.mjs";
|
|
6
|
-
import { readCookieValue } from "./cookie.mjs";
|
|
7
|
-
import { generateEventId } from "./event-id.mjs";
|
|
8
|
-
export { CONSENT_CATEGORIES, CONSENT_REGIONS, type ConsentCategory, type ConsentConfig, type ConsentDecision, type ConsentMode, type ConsentRecord, type ConsentRegion, type ConsentStorage, type Destination, type EventCatalog, type EventDefinition, type InitialConsent, type ResolveDefaultConsentOptions, type ResolveEffectiveConsentOptions, STRICTEST_INITIAL_CONSENT, type TrackEvent, type TrackedEvent, type TrackedEventBase, assertValidEventProperties, createConsentDecision, defineConsentConfig, defineEventCatalog, generateEventId, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readCookieValue, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent };
|
package/dist/core/index.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { CONSENT_CATEGORIES, CONSENT_REGIONS, STRICTEST_INITIAL_CONSENT, createConsentDecision, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent } from "./consent.mjs";
|
|
2
|
-
import { defineConsentConfig } from "./consent-config.mjs";
|
|
3
|
-
import { readCookieValue } from "./cookie.mjs";
|
|
4
|
-
import { assertValidEventProperties, defineEventCatalog } from "./event-catalog.mjs";
|
|
5
|
-
import { generateEventId } from "./event-id.mjs";
|
|
6
|
-
export { CONSENT_CATEGORIES, CONSENT_REGIONS, STRICTEST_INITIAL_CONSENT, assertValidEventProperties, createConsentDecision, defineConsentConfig, defineEventCatalog, generateEventId, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readCookieValue, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
//#region src/core/tracked-event.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Fields shared by every envelope the tracker builds.
|
|
4
|
-
*
|
|
5
|
-
* @since 1.0.0-canary.6
|
|
6
|
-
*/
|
|
7
|
-
interface TrackedEventBase {
|
|
8
|
-
anonymousId: string;
|
|
9
|
-
eventId: string;
|
|
10
|
-
timestamp: number;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A catalog-defined event envelope, as handed to destinations.
|
|
14
|
-
*
|
|
15
|
-
* @since 1.0.0-canary.6
|
|
16
|
-
*/
|
|
17
|
-
interface TrackEvent extends TrackedEventBase {
|
|
18
|
-
name: string;
|
|
19
|
-
properties: Record<string, unknown>;
|
|
20
|
-
type: "track";
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The envelope destinations receive. `type` stays a discriminant so a future kind is an
|
|
24
|
-
* additive union member, not a wire-format break.
|
|
25
|
-
*
|
|
26
|
-
* @since 0.5.0-canary.4
|
|
27
|
-
*/
|
|
28
|
-
type TrackedEvent = TrackEvent;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { TrackEvent, TrackedEvent, TrackedEventBase };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { ConsentDecision } from "../core/consent.mjs";
|
|
2
|
-
import { ConsentConfig } from "../core/consent-config.mjs";
|
|
3
|
-
import { Destination } from "../core/destination.mjs";
|
|
4
|
-
import { GoogleConsentParams } from "./google-consent.mjs";
|
|
5
|
-
import { FlatPropertyValue } from "./shared.mjs";
|
|
6
|
-
|
|
7
|
-
//#region src/destinations/google-analytics.d.ts
|
|
8
|
-
type GtagPropertyValue = FlatPropertyValue;
|
|
9
|
-
/**
|
|
10
|
-
* All signatures share one `gtag` global, so they must live in a single overloaded type —
|
|
11
|
-
* two separate `declare global` augmentations with different signatures for the same
|
|
12
|
-
* property is a TS error, not a merge.
|
|
13
|
-
*
|
|
14
|
-
* @since 1.0.0-canary.6
|
|
15
|
-
*/
|
|
16
|
-
type GtagFunction = {
|
|
17
|
-
(command: "config", targetId: string, params?: Record<string, GtagPropertyValue>): void;
|
|
18
|
-
(command: "consent", action: "default" | "update", params: GoogleConsentParams): void;
|
|
19
|
-
(command: "event", eventName: string, params?: Record<string, GtagPropertyValue>): void;
|
|
20
|
-
(command: "js", startDate: Date): void;
|
|
21
|
-
(command: "set", params: Record<string, GtagPropertyValue>): void;
|
|
22
|
-
(command: "set", key: string, value: boolean): void;
|
|
23
|
-
};
|
|
24
|
-
declare global {
|
|
25
|
-
interface Window {
|
|
26
|
-
dataLayer?: Array<unknown>;
|
|
27
|
-
gtag?: GtagFunction;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @since 1.0.0-canary.6
|
|
32
|
-
*/
|
|
33
|
-
interface EnsureGtagOptions {
|
|
34
|
-
/**
|
|
35
|
-
* Name of the queue array on `window`. Defaults to `"dataLayer"`. Must match across
|
|
36
|
-
* `ensureGtag` / `loadGtagScript` / `buildGtagConsentBootstrapScript` for one page.
|
|
37
|
-
*/
|
|
38
|
-
dataLayerName?: string | undefined;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Ensures the standard gtag.js queueing stub exists so consent commands can be issued
|
|
42
|
-
* before the tag itself loads — gtag.js replays the queue in order once it boots.
|
|
43
|
-
*
|
|
44
|
-
* @since 1.0.0-canary.6
|
|
45
|
-
*/
|
|
46
|
-
declare function ensureGtag(options?: EnsureGtagOptions): GtagFunction | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* @since 1.0.0-canary.6
|
|
49
|
-
*/
|
|
50
|
-
interface LoadGtagScriptOptions {
|
|
51
|
-
/**
|
|
52
|
-
* Name of the queue array on `window`. Defaults to `"dataLayer"` — must match the
|
|
53
|
-
* bootstrap / `ensureGtag` call that already applied Consent Mode.
|
|
54
|
-
*/
|
|
55
|
-
dataLayerName?: string | undefined;
|
|
56
|
-
/** Forwarded as `gtag('config', id, { debug_mode: true })` for GA4 DebugView. */
|
|
57
|
-
debugMode?: boolean | undefined;
|
|
58
|
-
/** Google Analytics 4 Measurement ID (e.g. `"G-XXXXXXX"`). */
|
|
59
|
-
gaMeasurementId: string;
|
|
60
|
-
/**
|
|
61
|
-
* CSP nonce applied to the injected gtag.js `<script>` element. The app must also put
|
|
62
|
-
* the same nonce on any inline bootstrap `<script>` that runs `buildGtagConsentBootstrapScript`.
|
|
63
|
-
*/
|
|
64
|
-
nonce?: string | undefined;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Loads gtag.js on demand — idempotent (a second call is a no-op) and reuses any
|
|
68
|
-
* existing `dataLayer`/`gtag` stub instead of clobbering it. Queues `js`/`config` before
|
|
69
|
-
* appending the script tag, so gtag.js replays them under the caller's already-applied
|
|
70
|
-
* consent state once it boots. Prefer `buildGtagConsentBootstrapScript` for page load
|
|
71
|
-
* (advanced Consent Mode always injects the tag after the default); use this when the
|
|
72
|
-
* bootstrap did not run, or as an idempotent safety net after a runtime grant.
|
|
73
|
-
*
|
|
74
|
-
* @since 1.0.0-canary.6
|
|
75
|
-
*/
|
|
76
|
-
declare function loadGtagScript(options: LoadGtagScriptOptions): void;
|
|
77
|
-
/**
|
|
78
|
-
* Expires Google's `_ga` / `_ga_*` cookies on `path=/` and the current host's parent
|
|
79
|
-
* domain. Consent Mode stops using them once denied but never removes them — call from
|
|
80
|
-
* a consent-withdrawal handler so a revoke does not leave identifier cookies behind.
|
|
81
|
-
*
|
|
82
|
-
* @since 1.0.0-canary.6
|
|
83
|
-
*/
|
|
84
|
-
declare function clearGoogleAnalyticsCookies(): void;
|
|
85
|
-
/**
|
|
86
|
-
* Google Consent Mode v2's "update" signal — call whenever the visitor's effective
|
|
87
|
-
* consent changes (a banner decision, or one synced from another tab), so already-loaded
|
|
88
|
-
* GA4/Ads tags pick up the change without a page reload.
|
|
89
|
-
*
|
|
90
|
-
* @since 0.5.0-canary.4
|
|
91
|
-
*/
|
|
92
|
-
declare function updateGoogleConsent(decision: ConsentDecision, options?: EnsureGtagOptions): void;
|
|
93
|
-
/**
|
|
94
|
-
* @since 1.0.0-canary.6
|
|
95
|
-
*/
|
|
96
|
-
interface GtagConsentBootstrapOptions {
|
|
97
|
-
/** The same object `useConsent` receives — the bootstrap reads its `storageKey` and `policyVersion`. */
|
|
98
|
-
config: ConsentConfig;
|
|
99
|
-
/**
|
|
100
|
-
* Name of the queue array on `window`. Defaults to `"dataLayer"`. Must match
|
|
101
|
-
* `loadGtagScript` / `ensureGtag` if those run later on the same page.
|
|
102
|
-
*/
|
|
103
|
-
dataLayerName?: string | undefined;
|
|
104
|
-
/**
|
|
105
|
-
* Consent to apply when nothing valid is stored yet. Embedded as a literal — bake the
|
|
106
|
-
* strictest default on cached/shared HTML; upgrade after hydration via the private
|
|
107
|
-
* server-fn lane + `updateGoogleConsent`.
|
|
108
|
-
*/
|
|
109
|
-
defaultConsent: ConsentDecision;
|
|
110
|
-
/** Forwarded as `gtag('config', id, { debug_mode: true })` after the consent default. */
|
|
111
|
-
debugMode?: boolean | undefined;
|
|
112
|
-
/** Google Analytics 4 Measurement ID (e.g. `"G-XXXXXXX"`). */
|
|
113
|
-
gaMeasurementId: string;
|
|
114
|
-
/**
|
|
115
|
-
* CSP nonce written onto the *injected* gtag.js `<script>` element inside the generated
|
|
116
|
-
* source. The host `<script dangerouslySetInnerHTML={…}>` that embeds this string must
|
|
117
|
-
* receive the same nonce from the app (this helper only returns JS text, not a React node).
|
|
118
|
-
*/
|
|
119
|
-
nonce?: string | undefined;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Builds the literal JS source for a `<script dangerouslySetInnerHTML>` mounted in
|
|
123
|
-
* `<head>`, before hydration: applies Consent Mode v2's default signal from the visitor's
|
|
124
|
-
* stored decision (falling back to literal `defaultConsent` when none is stored yet),
|
|
125
|
-
* then always loads gtag.js (advanced Consent Mode) so cookieless pings / modeling can
|
|
126
|
-
* run even when storage is denied. A runtime decision change needs `updateGoogleConsent`
|
|
127
|
-
* so the already-loaded tag picks up the grant/deny — this only covers the page-load
|
|
128
|
-
* default + script injection.
|
|
129
|
-
*
|
|
130
|
-
* @since 1.0.0-canary.6
|
|
131
|
-
*/
|
|
132
|
-
declare function buildGtagConsentBootstrapScript(options: GtagConsentBootstrapOptions): string;
|
|
133
|
-
/**
|
|
134
|
-
* @since 0.5.0-canary.4
|
|
135
|
-
*/
|
|
136
|
-
interface GoogleAnalyticsDestinationOptions {
|
|
137
|
-
name?: string | undefined;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Forwards catalog events to `window.gtag` as GA4 custom events. Page views are not this
|
|
141
|
-
* destination's job: `gtag('config', ...)` sends the initial page_view and GA4's Enhanced
|
|
142
|
-
* Measurement tracks SPA history changes. Requires the gtag.js snippet plus
|
|
143
|
-
* `gtag('config', measurementId)` mounted once by the app (see the consent bootstrap) —
|
|
144
|
-
* gtag.js owns its own batching and unload delivery.
|
|
145
|
-
*
|
|
146
|
-
* @since 0.5.0-canary.4
|
|
147
|
-
*/
|
|
148
|
-
declare function createGoogleAnalyticsDestination(options?: GoogleAnalyticsDestinationOptions): Destination;
|
|
149
|
-
//#endregion
|
|
150
|
-
export { EnsureGtagOptions, GoogleAnalyticsDestinationOptions, GtagConsentBootstrapOptions, GtagFunction, LoadGtagScriptOptions, buildGtagConsentBootstrapScript, clearGoogleAnalyticsCookies, createGoogleAnalyticsDestination, ensureGtag, loadGtagScript, updateGoogleConsent };
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_DATA_LAYER_NAME, buildGoogleConsentBootstrapPreamble, ensureDataLayer, toGoogleConsentParams, warnUnlessGa4EventName } from "./google-consent.mjs";
|
|
2
|
-
import { flattenEventProps } from "./shared.mjs";
|
|
3
|
-
//#region src/destinations/google-analytics.ts
|
|
4
|
-
const GTAG_SCRIPT_BASE_URL = "https://www.googletagmanager.com/gtag/js";
|
|
5
|
-
function gtagScriptSrc(gaMeasurementId, dataLayerName) {
|
|
6
|
-
const url = new URL(GTAG_SCRIPT_BASE_URL);
|
|
7
|
-
url.searchParams.set("id", gaMeasurementId);
|
|
8
|
-
if (dataLayerName !== "dataLayer") url.searchParams.set("l", dataLayerName);
|
|
9
|
-
return url.toString();
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Ensures the standard gtag.js queueing stub exists so consent commands can be issued
|
|
13
|
-
* before the tag itself loads — gtag.js replays the queue in order once it boots.
|
|
14
|
-
*
|
|
15
|
-
* @since 1.0.0-canary.6
|
|
16
|
-
*/
|
|
17
|
-
function ensureGtag(options = {}) {
|
|
18
|
-
if (typeof window === "undefined") return;
|
|
19
|
-
const dataLayerName = options.dataLayerName ?? "dataLayer";
|
|
20
|
-
ensureDataLayer(dataLayerName);
|
|
21
|
-
window.gtag ??= function gtag() {
|
|
22
|
-
ensureDataLayer(dataLayerName)?.push(arguments);
|
|
23
|
-
};
|
|
24
|
-
return window.gtag;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Loads gtag.js on demand — idempotent (a second call is a no-op) and reuses any
|
|
28
|
-
* existing `dataLayer`/`gtag` stub instead of clobbering it. Queues `js`/`config` before
|
|
29
|
-
* appending the script tag, so gtag.js replays them under the caller's already-applied
|
|
30
|
-
* consent state once it boots. Prefer `buildGtagConsentBootstrapScript` for page load
|
|
31
|
-
* (advanced Consent Mode always injects the tag after the default); use this when the
|
|
32
|
-
* bootstrap did not run, or as an idempotent safety net after a runtime grant.
|
|
33
|
-
*
|
|
34
|
-
* @since 1.0.0-canary.6
|
|
35
|
-
*/
|
|
36
|
-
function loadGtagScript(options) {
|
|
37
|
-
if (typeof document === "undefined" || document.querySelector(`script[src^="${GTAG_SCRIPT_BASE_URL}"]`) !== null) return;
|
|
38
|
-
const dataLayerName = options.dataLayerName ?? "dataLayer";
|
|
39
|
-
const gtag = ensureGtag({ dataLayerName });
|
|
40
|
-
if (!gtag) return;
|
|
41
|
-
gtag("js", /* @__PURE__ */ new Date());
|
|
42
|
-
if (options.debugMode === true) gtag("config", options.gaMeasurementId, { debug_mode: true });
|
|
43
|
-
else gtag("config", options.gaMeasurementId);
|
|
44
|
-
const script = document.createElement("script");
|
|
45
|
-
script.async = true;
|
|
46
|
-
script.src = gtagScriptSrc(options.gaMeasurementId, dataLayerName);
|
|
47
|
-
if (options.nonce !== void 0) script.nonce = options.nonce;
|
|
48
|
-
document.head.append(script);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Expires Google's `_ga` / `_ga_*` cookies on `path=/` and the current host's parent
|
|
52
|
-
* domain. Consent Mode stops using them once denied but never removes them — call from
|
|
53
|
-
* a consent-withdrawal handler so a revoke does not leave identifier cookies behind.
|
|
54
|
-
*
|
|
55
|
-
* @since 1.0.0-canary.6
|
|
56
|
-
*/
|
|
57
|
-
function clearGoogleAnalyticsCookies() {
|
|
58
|
-
if (typeof document === "undefined") return;
|
|
59
|
-
const { hostname } = globalThis.location;
|
|
60
|
-
for (const cookie of document.cookie.split("; ")) {
|
|
61
|
-
const name = cookie.split("=")[0];
|
|
62
|
-
if (name !== void 0 && (name === "_ga" || name.startsWith("_ga_"))) {
|
|
63
|
-
document.cookie = `${name}=; path=/; max-age=0`;
|
|
64
|
-
document.cookie = `${name}=; path=/; max-age=0; domain=.${hostname}`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Google Consent Mode v2's "update" signal — call whenever the visitor's effective
|
|
70
|
-
* consent changes (a banner decision, or one synced from another tab), so already-loaded
|
|
71
|
-
* GA4/Ads tags pick up the change without a page reload.
|
|
72
|
-
*
|
|
73
|
-
* @since 0.5.0-canary.4
|
|
74
|
-
*/
|
|
75
|
-
function updateGoogleConsent(decision, options = {}) {
|
|
76
|
-
ensureGtag(options)?.("consent", "update", toGoogleConsentParams(decision));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Builds the literal JS source for a `<script dangerouslySetInnerHTML>` mounted in
|
|
80
|
-
* `<head>`, before hydration: applies Consent Mode v2's default signal from the visitor's
|
|
81
|
-
* stored decision (falling back to literal `defaultConsent` when none is stored yet),
|
|
82
|
-
* then always loads gtag.js (advanced Consent Mode) so cookieless pings / modeling can
|
|
83
|
-
* run even when storage is denied. A runtime decision change needs `updateGoogleConsent`
|
|
84
|
-
* so the already-loaded tag picks up the grant/deny — this only covers the page-load
|
|
85
|
-
* default + script injection.
|
|
86
|
-
*
|
|
87
|
-
* @since 1.0.0-canary.6
|
|
88
|
-
*/
|
|
89
|
-
function buildGtagConsentBootstrapScript(options) {
|
|
90
|
-
const { config, dataLayerName = DEFAULT_DATA_LAYER_NAME, defaultConsent, debugMode, gaMeasurementId, nonce } = options;
|
|
91
|
-
const gtagScriptUrl = gtagScriptSrc(gaMeasurementId, dataLayerName);
|
|
92
|
-
const configArgs = debugMode === true ? `${JSON.stringify(gaMeasurementId)}, { debug_mode: true }` : JSON.stringify(gaMeasurementId);
|
|
93
|
-
const nonceAssignment = nonce === void 0 ? "" : `gtagScript.nonce = ${JSON.stringify(nonce)};`;
|
|
94
|
-
return `${buildGoogleConsentBootstrapPreamble({
|
|
95
|
-
consentStorageKey: config.storageKey,
|
|
96
|
-
dataLayerName,
|
|
97
|
-
defaultConsent,
|
|
98
|
-
policyVersion: config.policyVersion
|
|
99
|
-
})}
|
|
100
|
-
gtag("js", new Date());
|
|
101
|
-
gtag("config", ${configArgs});
|
|
102
|
-
var gtagScript = document.createElement("script");
|
|
103
|
-
gtagScript.async = true;
|
|
104
|
-
gtagScript.src = ${JSON.stringify(gtagScriptUrl)};
|
|
105
|
-
${nonceAssignment}
|
|
106
|
-
document.head.appendChild(gtagScript);
|
|
107
|
-
`;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Forwards catalog events to `window.gtag` as GA4 custom events. Page views are not this
|
|
111
|
-
* destination's job: `gtag('config', ...)` sends the initial page_view and GA4's Enhanced
|
|
112
|
-
* Measurement tracks SPA history changes. Requires the gtag.js snippet plus
|
|
113
|
-
* `gtag('config', measurementId)` mounted once by the app (see the consent bootstrap) —
|
|
114
|
-
* gtag.js owns its own batching and unload delivery.
|
|
115
|
-
*
|
|
116
|
-
* @since 0.5.0-canary.4
|
|
117
|
-
*/
|
|
118
|
-
function createGoogleAnalyticsDestination(options = {}) {
|
|
119
|
-
const name = options.name ?? "google-analytics";
|
|
120
|
-
return {
|
|
121
|
-
name,
|
|
122
|
-
async send(event) {
|
|
123
|
-
if (typeof window === "undefined" || typeof window.gtag !== "function") return;
|
|
124
|
-
if (!warnUnlessGa4EventName(name, event.name)) return;
|
|
125
|
-
window.gtag("event", event.name, flattenEventProps(event.properties));
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
export { buildGtagConsentBootstrapScript, clearGoogleAnalyticsCookies, createGoogleAnalyticsDestination, ensureGtag, loadGtagScript, updateGoogleConsent };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ConsentDecision } from "../core/consent.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/destinations/google-consent.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* gtag.js/gtm.js's default queue-array name — shared so the gtag and GTM helpers cannot disagree.
|
|
6
|
-
*
|
|
7
|
-
* @since 1.0.0-canary.6
|
|
8
|
-
*/
|
|
9
|
-
declare const DEFAULT_DATA_LAYER_NAME = "dataLayer";
|
|
10
|
-
type GoogleConsentState = "denied" | "granted";
|
|
11
|
-
/**
|
|
12
|
-
* Consent Mode v2 params issued via `gtag('consent', …)` — shared by the gtag and GTM
|
|
13
|
-
* bootstraps so signal mapping cannot drift between them.
|
|
14
|
-
*
|
|
15
|
-
* @since 1.0.0-canary.6
|
|
16
|
-
*/
|
|
17
|
-
interface GoogleConsentParams {
|
|
18
|
-
ad_personalization: GoogleConsentState;
|
|
19
|
-
ad_storage: GoogleConsentState;
|
|
20
|
-
ad_user_data: GoogleConsentState;
|
|
21
|
-
analytics_storage: GoogleConsentState;
|
|
22
|
-
region?: ReadonlyArray<string> | undefined;
|
|
23
|
-
wait_for_update?: number | undefined;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Maps a package `ConsentDecision` onto Consent Mode v2's four storage signals.
|
|
27
|
-
*
|
|
28
|
-
* @since 1.0.0-canary.6
|
|
29
|
-
*/
|
|
30
|
-
declare function toGoogleConsentParams(decision: ConsentDecision): GoogleConsentParams;
|
|
31
|
-
/**
|
|
32
|
-
* @since 1.0.0-canary.6
|
|
33
|
-
*/
|
|
34
|
-
interface GoogleConsentBootstrapPreambleOptions {
|
|
35
|
-
/** localStorage key holding the package's `ConsentRecord`. */
|
|
36
|
-
consentStorageKey: string;
|
|
37
|
-
dataLayerName: string;
|
|
38
|
-
/** Literal fallback when nothing valid is stored — baked into the script as JSON. */
|
|
39
|
-
defaultConsent: ConsentDecision;
|
|
40
|
-
policyVersion: string;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Shared head of the gtag and GTM consent bootstraps: dataLayer init, `gtag()` stub,
|
|
44
|
-
* stored-decision read (policy-version + shape checked), and the Consent Mode v2
|
|
45
|
-
* "default" signal. The builders append only their tag-specific tail, so the consent
|
|
46
|
-
* logic cannot drift between them.
|
|
47
|
-
*
|
|
48
|
-
* @since 1.0.0-canary.6
|
|
49
|
-
*/
|
|
50
|
-
declare function buildGoogleConsentBootstrapPreamble(options: GoogleConsentBootstrapPreambleOptions): string;
|
|
51
|
-
/**
|
|
52
|
-
* Reads or creates a named `window[dataLayerName]` queue array.
|
|
53
|
-
*
|
|
54
|
-
* @since 1.0.0-canary.6
|
|
55
|
-
*/
|
|
56
|
-
declare function ensureDataLayer(dataLayerName: string): Array<unknown> | undefined;
|
|
57
|
-
/**
|
|
58
|
-
* Warns and returns `false` when `eventName` would be rejected by GA4.
|
|
59
|
-
*
|
|
60
|
-
* @since 1.0.0-canary.6
|
|
61
|
-
*/
|
|
62
|
-
declare function warnUnlessGa4EventName(destinationName: string, eventName: string): boolean;
|
|
63
|
-
//#endregion
|
|
64
|
-
export { DEFAULT_DATA_LAYER_NAME, GoogleConsentBootstrapPreambleOptions, GoogleConsentParams, buildGoogleConsentBootstrapPreamble, ensureDataLayer, toGoogleConsentParams, warnUnlessGa4EventName };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { CONSENT_CATEGORIES } from "../core/consent.mjs";
|
|
2
|
-
//#region src/destinations/google-consent.ts
|
|
3
|
-
/**
|
|
4
|
-
* gtag.js/gtm.js's default queue-array name — shared so the gtag and GTM helpers cannot disagree.
|
|
5
|
-
*
|
|
6
|
-
* @since 1.0.0-canary.6
|
|
7
|
-
*/
|
|
8
|
-
const DEFAULT_DATA_LAYER_NAME = "dataLayer";
|
|
9
|
-
/**
|
|
10
|
-
* Which per-category decision each Consent Mode v2 signal follows: `analytics` drives
|
|
11
|
-
* `analytics_storage`; `ads` drives all three ads signals together.
|
|
12
|
-
*/
|
|
13
|
-
const GOOGLE_CONSENT_SIGNAL_CATEGORIES = {
|
|
14
|
-
ad_personalization: "ads",
|
|
15
|
-
ad_storage: "ads",
|
|
16
|
-
ad_user_data: "ads",
|
|
17
|
-
analytics_storage: "analytics"
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Maps a package `ConsentDecision` onto Consent Mode v2's four storage signals.
|
|
21
|
-
*
|
|
22
|
-
* @since 1.0.0-canary.6
|
|
23
|
-
*/
|
|
24
|
-
function toGoogleConsentParams(decision) {
|
|
25
|
-
return {
|
|
26
|
-
ad_personalization: decision[GOOGLE_CONSENT_SIGNAL_CATEGORIES.ad_personalization] ? "granted" : "denied",
|
|
27
|
-
ad_storage: decision[GOOGLE_CONSENT_SIGNAL_CATEGORIES.ad_storage] ? "granted" : "denied",
|
|
28
|
-
ad_user_data: decision[GOOGLE_CONSENT_SIGNAL_CATEGORIES.ad_user_data] ? "granted" : "denied",
|
|
29
|
-
analytics_storage: decision[GOOGLE_CONSENT_SIGNAL_CATEGORIES.analytics_storage] ? "granted" : "denied"
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/** JS fragment that validates a stored `ConsentRecord.decision` shape inside a bootstrap. */
|
|
33
|
-
function consentDecisionShapeCheckExpression() {
|
|
34
|
-
return CONSENT_CATEGORIES.map((category) => `typeof record.decision[${JSON.stringify(category)}] === "boolean"`).join(" && ");
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* JS object-literal fragment for `gtag("consent", "default", { … })` — generated from
|
|
38
|
-
* {@link GOOGLE_CONSENT_SIGNAL_CATEGORIES} so runtime and bootstrap stay aligned.
|
|
39
|
-
*/
|
|
40
|
-
function consentSignalAssignmentsExpression() {
|
|
41
|
-
return Object.keys(GOOGLE_CONSENT_SIGNAL_CATEGORIES).map((signal) => {
|
|
42
|
-
return `${signal}: consent.${GOOGLE_CONSENT_SIGNAL_CATEGORIES[signal]} ? "granted" : "denied"`;
|
|
43
|
-
}).join(",\n ");
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Shared head of the gtag and GTM consent bootstraps: dataLayer init, `gtag()` stub,
|
|
47
|
-
* stored-decision read (policy-version + shape checked), and the Consent Mode v2
|
|
48
|
-
* "default" signal. The builders append only their tag-specific tail, so the consent
|
|
49
|
-
* logic cannot drift between them.
|
|
50
|
-
*
|
|
51
|
-
* @since 1.0.0-canary.6
|
|
52
|
-
*/
|
|
53
|
-
function buildGoogleConsentBootstrapPreamble(options) {
|
|
54
|
-
const dataLayerAccess = `window[${JSON.stringify(options.dataLayerName)}]`;
|
|
55
|
-
return `
|
|
56
|
-
${dataLayerAccess} = ${dataLayerAccess} || [];
|
|
57
|
-
function gtag(){${dataLayerAccess}.push(arguments);}
|
|
58
|
-
var storedConsent = null;
|
|
59
|
-
try {
|
|
60
|
-
var record = JSON.parse(window.localStorage.getItem(${JSON.stringify(options.consentStorageKey)}));
|
|
61
|
-
if (record && record.policyVersion === ${JSON.stringify(options.policyVersion)} && record.decision && ${consentDecisionShapeCheckExpression()}) {
|
|
62
|
-
storedConsent = record.decision;
|
|
63
|
-
}
|
|
64
|
-
} catch (e) {}
|
|
65
|
-
var consent = storedConsent || (${JSON.stringify(options.defaultConsent)});
|
|
66
|
-
gtag("consent", "default", {
|
|
67
|
-
${consentSignalAssignmentsExpression()}
|
|
68
|
-
});`;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Reads or creates a named `window[dataLayerName]` queue array.
|
|
72
|
-
*
|
|
73
|
-
* @since 1.0.0-canary.6
|
|
74
|
-
*/
|
|
75
|
-
function ensureDataLayer(dataLayerName) {
|
|
76
|
-
if (typeof window === "undefined") return;
|
|
77
|
-
const existing = Reflect.get(window, dataLayerName);
|
|
78
|
-
const layer = Array.isArray(existing) ? existing : [];
|
|
79
|
-
Reflect.set(window, dataLayerName, layer);
|
|
80
|
-
return layer;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* GA4's event-name rules (letter start, letters/digits/underscores only, ≤40 chars).
|
|
84
|
-
* Catalog `track` names that fail this are accepted by gtag/MP HTTP but dropped at GA4
|
|
85
|
-
* processing with no client error — destinations warn and skip instead of sending nowhere.
|
|
86
|
-
*/
|
|
87
|
-
const GA4_EVENT_NAME_PATTERN = /^[A-Za-z][\w]{0,39}$/;
|
|
88
|
-
function isGa4EventName(name) {
|
|
89
|
-
return GA4_EVENT_NAME_PATTERN.test(name);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Warns and returns `false` when `eventName` would be rejected by GA4.
|
|
93
|
-
*
|
|
94
|
-
* @since 1.0.0-canary.6
|
|
95
|
-
*/
|
|
96
|
-
function warnUnlessGa4EventName(destinationName, eventName) {
|
|
97
|
-
if (isGa4EventName(eventName)) return true;
|
|
98
|
-
console.warn(`[tracking] "${destinationName}" dropped event "${eventName}" — GA4 event names must start with a letter and contain only letters, digits, or underscores (max 40 chars)`);
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
|
-
export { DEFAULT_DATA_LAYER_NAME, buildGoogleConsentBootstrapPreamble, ensureDataLayer, toGoogleConsentParams, warnUnlessGa4EventName };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { EnsureGtagOptions, GoogleAnalyticsDestinationOptions, GtagConsentBootstrapOptions, GtagFunction, LoadGtagScriptOptions, buildGtagConsentBootstrapScript, clearGoogleAnalyticsCookies, createGoogleAnalyticsDestination, ensureGtag, loadGtagScript, updateGoogleConsent } from "./google-analytics.mjs";
|
|
2
|
-
export { type EnsureGtagOptions, type GoogleAnalyticsDestinationOptions, type GtagConsentBootstrapOptions, type GtagFunction, type LoadGtagScriptOptions, buildGtagConsentBootstrapScript, clearGoogleAnalyticsCookies, createGoogleAnalyticsDestination, ensureGtag, loadGtagScript, updateGoogleConsent };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { buildGtagConsentBootstrapScript, clearGoogleAnalyticsCookies, createGoogleAnalyticsDestination, ensureGtag, loadGtagScript, updateGoogleConsent } from "./google-analytics.mjs";
|
|
2
|
-
export { buildGtagConsentBootstrapScript, clearGoogleAnalyticsCookies, createGoogleAnalyticsDestination, ensureGtag, loadGtagScript, updateGoogleConsent };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/destinations/shared.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* @since 1.0.0-canary.6
|
|
4
|
-
*/
|
|
5
|
-
type FlatPropertyValue = boolean | number | string;
|
|
6
|
-
/**
|
|
7
|
-
* Event params must be flat string/number/boolean (optionally `null`) — stringify
|
|
8
|
-
* anything else instead of letting the destination silently drop it.
|
|
9
|
-
*
|
|
10
|
-
* @since 1.0.0-canary.6
|
|
11
|
-
*/
|
|
12
|
-
declare function flattenEventProps(properties: Record<string, unknown>): Record<string, FlatPropertyValue>;
|
|
13
|
-
/**
|
|
14
|
-
* @since 1.0.0-canary.6
|
|
15
|
-
*/
|
|
16
|
-
declare function flattenEventProps(properties: Record<string, unknown>, options: {
|
|
17
|
-
allowNull: true;
|
|
18
|
-
}): Record<string, FlatPropertyValue | null>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { FlatPropertyValue, flattenEventProps };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/destinations/shared.ts
|
|
2
|
-
/**
|
|
3
|
-
* @since 1.0.0-canary.6
|
|
4
|
-
*/
|
|
5
|
-
function flattenEventProps(properties, options = {}) {
|
|
6
|
-
const result = {};
|
|
7
|
-
for (const [key, value] of Object.entries(properties)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") result[key] = value;
|
|
8
|
-
else if (options.allowNull === true && value === null) result[key] = null;
|
|
9
|
-
else if (value !== void 0 && value !== null) result[key] = JSON.stringify(value);
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { flattenEventProps };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Destination } from "../core/destination.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/destinations/vercel-analytics.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* @since 1.0.0-canary.6
|
|
6
|
-
*/
|
|
7
|
-
interface VercelAnalyticsDestinationOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Vercel Analytics is cookieless and its events carry no identifier from this
|
|
10
|
-
* package, so it qualifies for `"exempt"` — it then keeps receiving events while the
|
|
11
|
-
* tracker's analytics gate is closed. Defaults to `"required"` so pre-consent delivery
|
|
12
|
-
* stays an explicit opt-in.
|
|
13
|
-
*/
|
|
14
|
-
consentRequirement?: "exempt" | "required" | undefined;
|
|
15
|
-
name?: string | undefined;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* `track()` only pushes onto Vercel's own in-page queue (`window.va`/`window.vaq`), which
|
|
19
|
-
* handles batching and unload delivery itself. Requires the Vercel Analytics script to be
|
|
20
|
-
* loaded once elsewhere in the app (`<Analytics />` from `@vercel/analytics/react`, or the
|
|
21
|
-
* framework-agnostic `inject()`) — this destination only queues events, so it imports the
|
|
22
|
-
* base `@vercel/analytics` package and has no React dependency of its own.
|
|
23
|
-
*
|
|
24
|
-
* @since 0.5.0-canary.4
|
|
25
|
-
*/
|
|
26
|
-
declare function createVercelAnalyticsDestination(options?: VercelAnalyticsDestinationOptions): Destination;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { VercelAnalyticsDestinationOptions, createVercelAnalyticsDestination };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { flattenEventProps } from "./shared.mjs";
|
|
2
|
-
import { track } from "@vercel/analytics";
|
|
3
|
-
//#region src/destinations/vercel-analytics.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. Requires the Vercel Analytics script to be
|
|
7
|
-
* loaded once elsewhere in the app (`<Analytics />` from `@vercel/analytics/react`, or the
|
|
8
|
-
* framework-agnostic `inject()`) — this destination only queues events, so it imports the
|
|
9
|
-
* base `@vercel/analytics` package and has no React dependency of its own.
|
|
10
|
-
*
|
|
11
|
-
* @since 0.5.0-canary.4
|
|
12
|
-
*/
|
|
13
|
-
function createVercelAnalyticsDestination(options = {}) {
|
|
14
|
-
return {
|
|
15
|
-
consentRequirement: options.consentRequirement ?? "required",
|
|
16
|
-
name: options.name ?? "vercel-analytics",
|
|
17
|
-
async send(event) {
|
|
18
|
-
track(event.name, flattenEventProps(event.properties, { allowNull: true }));
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { createVercelAnalyticsDestination };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//#region src/import-protection.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Import specifiers (picomatch patterns) every client bundle must deny — spread into
|
|
4
|
-
* TanStack Start's `importProtection.client.specifiers` so the deny-list ships and
|
|
5
|
-
* versions with the package instead of going stale in each consumer's config. Nothing in
|
|
6
|
-
* this package imports it — its consumers are app build configs (see apps/ui vite.config.ts).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* tanstackStart({
|
|
11
|
-
* importProtection: { client: { specifiers: [...SERVER_ONLY_IMPORT_SPECIFIERS] } },
|
|
12
|
-
* });
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @since 1.0.0-canary.6
|
|
16
|
-
*/
|
|
17
|
-
declare const SERVER_ONLY_IMPORT_SPECIFIERS: ReadonlyArray<string>;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { SERVER_ONLY_IMPORT_SPECIFIERS };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//#region src/import-protection.ts
|
|
2
|
-
/**
|
|
3
|
-
* Import specifiers (picomatch patterns) every client bundle must deny — spread into
|
|
4
|
-
* TanStack Start's `importProtection.client.specifiers` so the deny-list ships and
|
|
5
|
-
* versions with the package instead of going stale in each consumer's config. Nothing in
|
|
6
|
-
* this package imports it — its consumers are app build configs (see apps/ui vite.config.ts).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* tanstackStart({
|
|
11
|
-
* importProtection: { client: { specifiers: [...SERVER_ONLY_IMPORT_SPECIFIERS] } },
|
|
12
|
-
* });
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @since 1.0.0-canary.6
|
|
16
|
-
*/
|
|
17
|
-
const SERVER_ONLY_IMPORT_SPECIFIERS = [
|
|
18
|
-
"@codefast/tracking/server",
|
|
19
|
-
"@codefast/tracking/server/**",
|
|
20
|
-
"@codefast/tracking/tanstack-start"
|
|
21
|
-
];
|
|
22
|
-
//#endregion
|
|
23
|
-
export { SERVER_ONLY_IMPORT_SPECIFIERS };
|
package/dist/index.d.mts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CONSENT_CATEGORIES, CONSENT_REGIONS, ConsentCategory, ConsentDecision, ConsentMode, ConsentRecord, ConsentRegion, ConsentStorage, InitialConsent, ResolveDefaultConsentOptions, ResolveEffectiveConsentOptions, STRICTEST_INITIAL_CONSENT, createConsentDecision, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent } from "./core/consent.mjs";
|
|
2
|
-
import { ConsentConfig, defineConsentConfig } from "./core/consent-config.mjs";
|
|
3
|
-
import { TrackEvent, TrackedEvent, TrackedEventBase } from "./core/tracked-event.mjs";
|
|
4
|
-
import { Destination } from "./core/destination.mjs";
|
|
5
|
-
import { EventCatalog, EventDefinition, assertValidEventProperties, defineEventCatalog } from "./core/event-catalog.mjs";
|
|
6
|
-
import { readCookieValue } from "./core/cookie.mjs";
|
|
7
|
-
import { generateEventId } from "./core/event-id.mjs";
|
|
8
|
-
export { CONSENT_CATEGORIES, CONSENT_REGIONS, type ConsentCategory, type ConsentConfig, type ConsentDecision, type ConsentMode, type ConsentRecord, type ConsentRegion, type ConsentStorage, type Destination, type EventCatalog, type EventDefinition, type InitialConsent, type ResolveDefaultConsentOptions, type ResolveEffectiveConsentOptions, STRICTEST_INITIAL_CONSENT, type TrackEvent, type TrackedEvent, type TrackedEventBase, assertValidEventProperties, createConsentDecision, defineConsentConfig, defineEventCatalog, generateEventId, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readCookieValue, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent };
|
package/dist/index.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { CONSENT_CATEGORIES, CONSENT_REGIONS, STRICTEST_INITIAL_CONSENT, createConsentDecision, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent } from "./core/consent.mjs";
|
|
2
|
-
import { defineConsentConfig } from "./core/consent-config.mjs";
|
|
3
|
-
import { readCookieValue } from "./core/cookie.mjs";
|
|
4
|
-
import { assertValidEventProperties, defineEventCatalog } from "./core/event-catalog.mjs";
|
|
5
|
-
import { generateEventId } from "./core/event-id.mjs";
|
|
6
|
-
export { CONSENT_CATEGORIES, CONSENT_REGIONS, STRICTEST_INITIAL_CONSENT, assertValidEventProperties, createConsentDecision, defineConsentConfig, defineEventCatalog, generateEventId, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readCookieValue, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent };
|