@d8a-tech/wt 0.1.0

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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +113 -0
  3. package/dist/browser_entry.d.ts +1 -0
  4. package/dist/cookies/consent.d.ts +4 -0
  5. package/dist/cookies/cookie_jar.d.ts +48 -0
  6. package/dist/cookies/cookie_settings.d.ts +23 -0
  7. package/dist/cookies/d8a_cookies.d.ts +71 -0
  8. package/dist/cookies/identity.d.ts +89 -0
  9. package/dist/cookies/session_manager.d.ts +36 -0
  10. package/dist/ga4/consent_wire.d.ts +38 -0
  11. package/dist/ga4/gtag_mapper.d.ts +46 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.min.mjs +3 -0
  14. package/dist/index.min.mjs.map +7 -0
  15. package/dist/install.d.ts +23 -0
  16. package/dist/runtime/anon_cid.d.ts +13 -0
  17. package/dist/runtime/browser_context.d.ts +2 -0
  18. package/dist/runtime/config_resolver.d.ts +4 -0
  19. package/dist/runtime/consent_resolver.d.ts +7 -0
  20. package/dist/runtime/consent_update_ping.d.ts +10 -0
  21. package/dist/runtime/d8a_global.d.ts +11 -0
  22. package/dist/runtime/debug_logger.d.ts +6 -0
  23. package/dist/runtime/dispatcher.d.ts +18 -0
  24. package/dist/runtime/engagement_timer.d.ts +21 -0
  25. package/dist/runtime/enhanced_measurement.d.ts +14 -0
  26. package/dist/runtime/gtag_consent_bridge.d.ts +9 -0
  27. package/dist/runtime/linker.d.ts +53 -0
  28. package/dist/runtime/param_precedence.d.ts +27 -0
  29. package/dist/runtime/queue_consumer.d.ts +12 -0
  30. package/dist/runtime/runtime_names.d.ts +12 -0
  31. package/dist/runtime/state.d.ts +2 -0
  32. package/dist/runtime/uach.d.ts +31 -0
  33. package/dist/transport/send.d.ts +20 -0
  34. package/dist/types.d.ts +144 -0
  35. package/dist/utils/endpoint.d.ts +14 -0
  36. package/dist/utils/gtag_primitives.d.ts +8 -0
  37. package/dist/utils/is_record.d.ts +1 -0
  38. package/dist/utils/window_slots.d.ts +4 -0
  39. package/dist/web-tracker.min.js +3 -0
  40. package/dist/web-tracker.min.js.map +7 -0
  41. package/dist/wt.min.js +3 -0
  42. package/dist/wt.min.js.map +7 -0
  43. package/index.d.ts +167 -0
  44. package/package.json +62 -0
package/index.d.ts ADDED
@@ -0,0 +1,167 @@
1
+ export type ConsentModeAction = "default" | "update";
2
+ export type ConsentStatus = "granted" | "denied";
3
+
4
+ export type ConsentState = {
5
+ ad_storage?: ConsentStatus;
6
+ analytics_storage?: ConsentStatus;
7
+ functionality_storage?: ConsentStatus;
8
+ personalization_storage?: ConsentStatus;
9
+ security_storage?: ConsentStatus;
10
+ };
11
+
12
+ export type D8aConfigParams = {
13
+ /**
14
+ * Server-side destination URL (tracker uses this as the final endpoint).
15
+ * Example (cloud): "https://global.t.d8a.tech/<property_id>/d/c"
16
+ * Example (on-prem): "https://example.org/d/c"
17
+ */
18
+ server_container_url?: string;
19
+
20
+ /**
21
+ * Optional name of the queue array on `window` used for buffering calls.
22
+ * For script-tag usage, you can also pass it via the script src `?l=<name>`.
23
+ */
24
+ data_layer_name?: string;
25
+ debug_mode?: boolean;
26
+ cookie_domain?: "auto" | "none" | string;
27
+ cookie_path?: string;
28
+ cookie_expires?: number;
29
+ cookie_flags?: string;
30
+ cookie_prefix?: string;
31
+ cookie_update?: boolean;
32
+ session_timeout_ms?: number;
33
+ /**
34
+ * Minimum engaged time (in seconds) required to flip `seg=1` (session engaged).
35
+ * Defaults to 10.
36
+ */
37
+ session_engagement_time_sec?: number;
38
+ flush_interval_ms?: number;
39
+ max_batch_size?: number;
40
+
41
+ /**
42
+ * GA4-style user id (stored in-memory by the tracker). On the wire it maps
43
+ * to the `uid` parameter.
44
+ */
45
+ user_id?: string;
46
+
47
+ // gtag-style request/page overrides
48
+ client_id?: string;
49
+ campaign_id?: string;
50
+ campaign_source?: string;
51
+ campaign_medium?: string;
52
+ campaign_name?: string;
53
+ campaign_term?: string;
54
+ campaign_content?: string;
55
+ page_location?: string;
56
+ page_title?: string;
57
+ page_referrer?: string;
58
+ content_group?: string;
59
+ language?: string;
60
+ screen_resolution?: string;
61
+ ignore_referrer?: boolean;
62
+ send_page_view?: boolean;
63
+
64
+ // Enhanced measurement
65
+ site_search_enabled?: boolean;
66
+ site_search_query_params?: string | string[];
67
+ outbound_clicks_enabled?: boolean;
68
+ outbound_exclude_domains?: string | string[];
69
+ file_downloads_enabled?: boolean;
70
+ file_download_extensions?: string | string[];
71
+ };
72
+
73
+ export type D8aSetParams = {
74
+ user_id?: string;
75
+
76
+ // same override keys as config (global defaults)
77
+ client_id?: string;
78
+ campaign_id?: string;
79
+ campaign_source?: string;
80
+ campaign_medium?: string;
81
+ campaign_name?: string;
82
+ campaign_term?: string;
83
+ campaign_content?: string;
84
+ page_location?: string;
85
+ page_title?: string;
86
+ page_referrer?: string;
87
+ content_group?: string;
88
+ language?: string;
89
+ screen_resolution?: string;
90
+ ignore_referrer?: boolean;
91
+
92
+ cookie_domain?: "auto" | "none" | string;
93
+ cookie_path?: string;
94
+ cookie_expires?: number;
95
+ cookie_flags?: string;
96
+ cookie_prefix?: string;
97
+ cookie_update?: boolean;
98
+ /**
99
+ * Global default for `session_engagement_time_sec` (see config).
100
+ */
101
+ session_engagement_time_sec?: number;
102
+
103
+ // Enhanced measurement
104
+ site_search_enabled?: boolean;
105
+ site_search_query_params?: string | string[];
106
+ outbound_clicks_enabled?: boolean;
107
+ outbound_exclude_domains?: string | string[];
108
+ file_downloads_enabled?: boolean;
109
+ file_download_extensions?: string | string[];
110
+ };
111
+
112
+ export type D8aEventParams = Record<
113
+ string,
114
+ string | number | boolean | null | undefined | string[] | Array<Record<string, unknown>>
115
+ >;
116
+
117
+ export interface D8aFn {
118
+ (...args: unknown[]): void;
119
+ js(date: Date): void;
120
+ config(propertyId: string, params?: D8aConfigParams): void;
121
+ event(eventName: string, params?: D8aEventParams): void;
122
+ set(params: D8aSetParams): void;
123
+ consent(action: ConsentModeAction, state: ConsentState): void;
124
+ }
125
+
126
+ declare global {
127
+ interface Window {
128
+ dataLayer?: unknown[];
129
+ d8a?: D8aFn;
130
+ d8aDataLayerName?: string;
131
+ d8aGlobalName?: string;
132
+ d8aGtagDataLayerName?: string;
133
+ }
134
+ }
135
+
136
+ export type InstallD8aOptions = {
137
+ windowRef?: unknown;
138
+ dataLayerName?: string;
139
+ globalName?: string;
140
+ gtagDataLayerName?: string;
141
+ };
142
+
143
+ export type QueueConsumer = {
144
+ start(): void;
145
+ stop(): void;
146
+ getState(): unknown;
147
+ setOnEvent(fn: (name: string, params: D8aEventParams) => void): void;
148
+ setOnConfig(fn: (propertyId: string, params: D8aConfigParams) => void): void;
149
+ };
150
+
151
+ export type Dispatcher = {
152
+ enqueueEvent(name: string, params?: D8aEventParams): void;
153
+ flush(opts: { useBeacon: boolean }): Promise<{ sent: number }>;
154
+ flushNow(opts?: { useBeacon?: boolean }): Promise<{ sent: number }>;
155
+ attachLifecycleFlush(): void;
156
+ };
157
+
158
+ export type InstallD8aResult = {
159
+ consumer: QueueConsumer;
160
+ dispatcher: Dispatcher;
161
+ dataLayerName: string;
162
+ globalName: string;
163
+ };
164
+
165
+ export function installD8a(opts?: InstallD8aOptions): InstallD8aResult;
166
+
167
+ export {};
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@d8a-tech/wt",
3
+ "version": "0.1.0",
4
+ "description": "The d8a web tracker provides a GA4 gtag-style API that sends GA4 gtag-compatible requests directly to a d8a collector.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.min.mjs",
8
+ "module": "./dist/index.min.mjs",
9
+ "types": "./index.d.ts",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/d8a-tech/d8a.git",
16
+ "directory": "js/web-tracker"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/d8a-tech/d8a/issues"
20
+ },
21
+ "homepage": "https://d8a.tech",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./index.d.ts",
25
+ "import": "./dist/index.min.mjs"
26
+ },
27
+ "./browser": "./dist/wt.min.js"
28
+ },
29
+ "files": [
30
+ "dist/",
31
+ "index.d.ts",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "prepack": "npm run build && npm run types",
37
+ "build": "node scripts/build.mjs",
38
+ "dev": "vite",
39
+ "test": "tsx --test test/*.test.ts",
40
+ "typecheck": "tsc -p tsconfig.build.json --noEmit && tsc -p tsconfig.test.json --noEmit",
41
+ "hash": "node scripts/hash.mjs",
42
+ "types": "tsc -p tsconfig.build.json",
43
+ "lint": "eslint .",
44
+ "lint:fix": "eslint . --fix",
45
+ "format": "prettier . --check",
46
+ "format:fix": "prettier . --write"
47
+ },
48
+ "devDependencies": {
49
+ "@eslint/js": "^9.36.0",
50
+ "@types/node": "^22.13.1",
51
+ "@typescript-eslint/eslint-plugin": "^8.30.0",
52
+ "@typescript-eslint/parser": "^8.30.0",
53
+ "esbuild": "^0.25.9",
54
+ "eslint": "^9.36.0",
55
+ "eslint-config-prettier": "^10.1.8",
56
+ "globals": "^16.4.0",
57
+ "prettier": "^3.6.2",
58
+ "tsx": "^4.19.2",
59
+ "typescript": "^5.7.3",
60
+ "vite": "^6.0.0"
61
+ }
62
+ }