@baukit/analytics-posthog-web 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Koss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # `@baukit/analytics-posthog-web`
2
+
3
+ PostHog browser transport for `@baukit/analytics-core`. It translates only envelopes that have
4
+ already passed the core's consent gate, event allowlist, and scrubber.
5
+
6
+ ## Self-hosted setup
7
+
8
+ Install the core and browser SDK alongside the adapter:
9
+
10
+ ```sh
11
+ pnpm add @baukit/analytics-core @baukit/analytics-posthog-web posthog-js
12
+ ```
13
+
14
+ Use the configured factory with an explicit self-hosted URL. There is deliberately no PostHog
15
+ Cloud default:
16
+
17
+ ```ts
18
+ import { AnalyticsClient } from '@baukit/analytics-core';
19
+ import { createPostHogWebTransport } from '@baukit/analytics-posthog-web';
20
+
21
+ const transport = createPostHogWebTransport({
22
+ apiKey: 'phc_project_key',
23
+ apiHost: 'https://posthog.analytics.example.com',
24
+ });
25
+
26
+ const analytics = new AnalyticsClient({
27
+ context,
28
+ allowlist,
29
+ transport,
30
+ });
31
+ ```
32
+
33
+ SDK initialization is lazy: the configured PostHog instance is created only when the core sends
34
+ its first consent-approved batch. Its initial distinct ID is bootstrapped from the core envelope.
35
+ Autocapture, pageview/pageleave capture, exception capture, session recording, surveys, and the
36
+ initial feature-flag request are disabled. Person profiles are limited to identified users.
37
+ Automatic campaign and referrer person properties are also disabled.
38
+
39
+ An application that already owns a configured `posthog-js` instance can wrap it instead:
40
+
41
+ ```ts
42
+ import posthog from 'posthog-js';
43
+ import { PostHogWebTransport } from '@baukit/analytics-posthog-web';
44
+
45
+ const transport = new PostHogWebTransport(posthog);
46
+ ```
47
+
48
+ When wrapping an instance, the application remains responsible for initializing it only after
49
+ consent and applying equivalent privacy settings.
50
+
51
+ ## Mapping
52
+
53
+ - `capture` flattens the core-stamped context and already-scrubbed event properties, preserving the
54
+ core capture time as the PostHog timestamp.
55
+ - `identify` passes the internal user UUID and the core's already-scrubbed traits. Those traits are
56
+ the only values used for PostHog person-property `$set` behavior.
57
+ - `alias` passes the known user UUID as the alias and the core anonymous UUID as the original ID.
58
+ - `reset` resets the PostHog identity after the core has rotated its own anonymous UUID.
59
+
60
+ ## Deliberate omissions
61
+
62
+ This package does not decide consent, generate or validate product identity, define events,
63
+ allowlist properties, scrub PII, buffer commands, enable automatic capture, record sessions, or add
64
+ provider-specific event properties. Those policy decisions stay in `@baukit/analytics-core` (or,
65
+ for provider project retention and deletion, in operations).
@@ -0,0 +1,39 @@
1
+ import { type PostHogConfig } from 'posthog-js';
2
+ import type { AnalyticsEnvelope, AnalyticsEvent, Transport } from '@baukit/analytics-core';
3
+ export interface PostHogWebClient {
4
+ capture(event: string, properties?: Readonly<Record<string, unknown>>, options?: {
5
+ readonly timestamp?: Date;
6
+ }): unknown;
7
+ identify(distinctId: string, traits?: Readonly<Record<string, unknown>>): unknown;
8
+ alias(alias: string, original?: string): unknown;
9
+ reset(): unknown;
10
+ opt_in_capturing(options?: {
11
+ readonly captureEventName?: string | null | false;
12
+ }): unknown;
13
+ opt_out_capturing(): unknown;
14
+ }
15
+ type GuardedPostHogWebOption = 'advanced_disable_feature_flags_on_first_load' | 'api_host' | 'autocapture' | 'bootstrap' | 'capture_exceptions' | 'capture_pageleave' | 'capture_pageview' | 'disable_session_recording' | 'disable_surveys' | 'opt_out_capturing_by_default' | 'opt_out_persistence_by_default' | 'person_profiles' | 'save_campaign_params' | 'save_referrer';
16
+ export type PostHogWebInitOptions = Omit<Partial<PostHogConfig>, GuardedPostHogWebOption>;
17
+ export type PostHogWebInitializer = (apiKey: string, options: Partial<PostHogConfig>) => PostHogWebClient | Promise<PostHogWebClient>;
18
+ export interface PostHogWebTransportConfig {
19
+ readonly apiKey: string;
20
+ /** Absolute URL of the product's self-hosted PostHog instance. */
21
+ readonly apiHost: string;
22
+ readonly options?: PostHogWebInitOptions;
23
+ readonly initializer?: PostHogWebInitializer;
24
+ readonly onError?: (error: unknown) => void;
25
+ }
26
+ type ClientFactory = (firstEnvelope: AnalyticsEnvelope) => PostHogWebClient | Promise<PostHogWebClient>;
27
+ /** Translates privacy-checked core envelopes to a PostHog browser client. */
28
+ export declare class PostHogWebTransport<E extends AnalyticsEvent = AnalyticsEvent> implements Transport<E> {
29
+ #private;
30
+ constructor(client: PostHogWebClient | ClientFactory, onError?: (error: unknown) => void);
31
+ /** Provider failures are contained and never reject into application code. */
32
+ send(envelopes: readonly AnalyticsEnvelope<E>[]): Promise<void>;
33
+ /** Opts PostHog out and purges its in-memory batch and retry queues. */
34
+ clearPending(): Promise<void>;
35
+ }
36
+ /** Creates a lazy, safely configured PostHog browser transport. */
37
+ export declare function createPostHogWebTransport<E extends AnalyticsEvent = AnalyticsEvent>(config: PostHogWebTransportConfig): PostHogWebTransport<E>;
38
+ export {};
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAEzD,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EAEd,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CACL,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC9C,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAA;KAAE,GACtC,OAAO,CAAC;IACX,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC;IAClF,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACjD,KAAK,IAAI,OAAO,CAAC;IACjB,gBAAgB,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC;IAC3F,iBAAiB,IAAI,OAAO,CAAC;CAC9B;AAED,KAAK,uBAAuB,GACxB,8CAA8C,GAC9C,UAAU,GACV,aAAa,GACb,WAAW,GACX,oBAAoB,GACpB,mBAAmB,GACnB,kBAAkB,GAClB,2BAA2B,GAC3B,iBAAiB,GACjB,8BAA8B,GAC9B,gCAAgC,GAChC,iBAAiB,GACjB,sBAAsB,GACtB,eAAe,CAAC;AAEpB,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,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4
+ value.length = 0;
5
+ }
6
+ }
7
+ function requireNonEmpty(name, value) {
8
+ const normalized = value.trim();
9
+ if (normalized.length === 0) {
10
+ throw new TypeError(`${name} must not be empty`);
11
+ }
12
+ return normalized;
13
+ }
14
+ function requireApiHost(value) {
15
+ const apiHost = requireNonEmpty('apiHost', value).replace(/\/+$/, '');
16
+ if (!/^https?:\/\/[^\s/]+(?:\/.*)?$/u.test(apiHost)) {
17
+ throw new TypeError('apiHost must be an absolute http(s) URL');
18
+ }
19
+ return apiHost;
20
+ }
21
+ function initialIdentity(envelope) {
22
+ if (envelope.type === 'capture') {
23
+ return envelope.user_id === undefined
24
+ ? { distinctID: envelope.anonymous_id, isIdentifiedID: false }
25
+ : { distinctID: envelope.user_id, isIdentifiedID: true };
26
+ }
27
+ if (envelope.type === 'reset') {
28
+ return envelope.previous_user_id === undefined
29
+ ? { distinctID: envelope.previous_anonymous_id, isIdentifiedID: false }
30
+ : { distinctID: envelope.previous_user_id, isIdentifiedID: true };
31
+ }
32
+ return { distinctID: envelope.anonymous_id, isIdentifiedID: false };
33
+ }
34
+ function captureProperties(envelope) {
35
+ return {
36
+ ...envelope.event.properties,
37
+ schema_version: envelope.event.schema_version,
38
+ app: envelope.event.app,
39
+ app_version: envelope.event.app_version,
40
+ platform: envelope.event.platform,
41
+ environment: envelope.event.environment,
42
+ locale: envelope.event.locale,
43
+ };
44
+ }
45
+ /** Translates privacy-checked core envelopes to a PostHog browser client. */
46
+ export class PostHogWebTransport {
47
+ #clientFactory;
48
+ #onError;
49
+ #client;
50
+ #clearGeneration = 0;
51
+ #clearRequired = false;
52
+ #clearOperation;
53
+ #providerOptedOut = true;
54
+ constructor(client, onError) {
55
+ this.#clientFactory = typeof client === 'function' ? client : () => client;
56
+ this.#onError = onError;
57
+ }
58
+ /** Provider failures are contained and never reject into application code. */
59
+ async send(envelopes) {
60
+ if (envelopes.length === 0) {
61
+ return;
62
+ }
63
+ const generation = this.#clearGeneration;
64
+ let client;
65
+ try {
66
+ client = await this.#getClient(envelopes[0]);
67
+ }
68
+ catch (error) {
69
+ this.#reportError(error);
70
+ return;
71
+ }
72
+ await this.#clearOperation;
73
+ if (generation !== this.#clearGeneration) {
74
+ return;
75
+ }
76
+ if (this.#clearRequired) {
77
+ this.#purgeClient(client);
78
+ if (generation !== this.#clearGeneration) {
79
+ return;
80
+ }
81
+ this.#clearRequired = false;
82
+ }
83
+ if (!this.#optIn(client)) {
84
+ return;
85
+ }
86
+ for (const envelope of envelopes) {
87
+ if (generation !== this.#clearGeneration) {
88
+ return;
89
+ }
90
+ try {
91
+ await this.#dispatch(client, envelope);
92
+ }
93
+ catch (error) {
94
+ this.#reportError(error);
95
+ }
96
+ }
97
+ }
98
+ /** Opts PostHog out and purges its in-memory batch and retry queues. */
99
+ clearPending() {
100
+ this.#clearGeneration += 1;
101
+ this.#clearRequired = true;
102
+ this.#providerOptedOut = true;
103
+ const client = this.#client;
104
+ if (client === undefined) {
105
+ return Promise.resolve();
106
+ }
107
+ const generation = this.#clearGeneration;
108
+ const operation = client
109
+ .then((resolvedClient) => {
110
+ this.#purgeClient(resolvedClient);
111
+ if (generation === this.#clearGeneration) {
112
+ this.#clearRequired = false;
113
+ }
114
+ })
115
+ .catch((error) => {
116
+ this.#reportError(error);
117
+ })
118
+ .finally(() => {
119
+ if (this.#clearOperation === operation) {
120
+ this.#clearOperation = undefined;
121
+ }
122
+ });
123
+ this.#clearOperation = operation;
124
+ return operation;
125
+ }
126
+ #getClient(firstEnvelope) {
127
+ this.#client ??= Promise.resolve(this.#clientFactory(firstEnvelope));
128
+ return this.#client;
129
+ }
130
+ async #dispatch(client, envelope) {
131
+ switch (envelope.type) {
132
+ case 'capture':
133
+ await Promise.resolve(client.capture(envelope.event.name, captureProperties(envelope), {
134
+ timestamp: new Date(envelope.captured_at),
135
+ }));
136
+ break;
137
+ case 'identify':
138
+ await Promise.resolve(client.identify(envelope.user_id, envelope.traits));
139
+ break;
140
+ case 'alias':
141
+ await Promise.resolve(client.alias(envelope.user_id, envelope.anonymous_id));
142
+ break;
143
+ case 'reset':
144
+ await Promise.resolve(client.reset());
145
+ break;
146
+ }
147
+ }
148
+ #optIn(client) {
149
+ if (!this.#providerOptedOut) {
150
+ return true;
151
+ }
152
+ try {
153
+ client.opt_in_capturing({ captureEventName: false });
154
+ this.#providerOptedOut = false;
155
+ return true;
156
+ }
157
+ catch (error) {
158
+ this.#reportError(error);
159
+ return false;
160
+ }
161
+ }
162
+ #purgeClient(client) {
163
+ try {
164
+ client.opt_out_capturing();
165
+ }
166
+ catch (error) {
167
+ this.#reportError(error);
168
+ }
169
+ const internals = client;
170
+ clearArray(internals.__request_queue);
171
+ clearArray(internals._requestQueue?._queue);
172
+ clearArray(internals._retryQueue?._queue);
173
+ }
174
+ #reportError(error) {
175
+ try {
176
+ this.#onError?.(error);
177
+ }
178
+ catch {
179
+ // Provider diagnostics must not affect the application journey.
180
+ }
181
+ }
182
+ }
183
+ /** Creates a lazy, safely configured PostHog browser transport. */
184
+ export function createPostHogWebTransport(config) {
185
+ const apiKey = requireNonEmpty('apiKey', config.apiKey);
186
+ const apiHost = requireApiHost(config.apiHost);
187
+ const initializer = config.initializer ?? ((key, options) => posthog.init(key, options));
188
+ return new PostHogWebTransport((firstEnvelope) => {
189
+ const options = {
190
+ ...config.options,
191
+ api_host: apiHost,
192
+ autocapture: false,
193
+ capture_pageview: false,
194
+ capture_pageleave: false,
195
+ capture_exceptions: false,
196
+ disable_session_recording: true,
197
+ disable_surveys: true,
198
+ advanced_disable_feature_flags_on_first_load: true,
199
+ opt_out_capturing_by_default: true,
200
+ opt_out_persistence_by_default: true,
201
+ person_profiles: 'identified_only',
202
+ save_campaign_params: false,
203
+ save_referrer: false,
204
+ bootstrap: initialIdentity(firstEnvelope),
205
+ };
206
+ return initializer(apiKey, options);
207
+ }, config.onError);
208
+ }
209
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names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DED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@baukit/analytics-posthog-web",
3
+ "version": "0.1.0",
4
+ "description": "PostHog browser transport for @baukit/analytics-core.",
5
+ "license": "MIT",
6
+ "author": "Patrick Koss",
7
+ "homepage": "https://github.com/PatrickKoss/baukit#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/PatrickKoss/baukit.git",
11
+ "directory": "typescript/packages/analytics-posthog-web"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/PatrickKoss/baukit/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "type": "module",
20
+ "engines": {
21
+ "node": ">=24.0.0"
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "devDependencies": {
36
+ "@baukit/analytics-core": "file:../analytics-core",
37
+ "posthog-js": "1.414.0",
38
+ "typescript": "6.0.3"
39
+ },
40
+ "peerDependencies": {
41
+ "@baukit/analytics-core": "^0.1.0",
42
+ "posthog-js": ">=1.43.1 <2"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.json",
46
+ "test": "vitest run --config ../../vitest.config.ts",
47
+ "lint": "eslint src --max-warnings=0",
48
+ "format:check": "prettier --check src package.json tsconfig.json"
49
+ }
50
+ }