@entifix/posthog 0.1.0-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 r10c Technologies
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,16 @@
1
+ # @entifix/posthog
2
+
3
+ The PostHog adapter for the product-analytics `Tracker` port
4
+ (`@entifix/tooling/tracking`). One vendor, two SDKs, two entry points:
5
+
6
+ - **`@entifix/posthog`** — `makePostHogTracker(client)` over
7
+ `posthog-node` (backend, server-side events).
8
+ - **`@entifix/posthog/browser`** — `makeBrowserTracker(posthog)`
9
+ over `posthog-js` (browser events + sync feature-flag / A-B reads).
10
+
11
+ Both return a framework-free `Tracker`, provided per environment behind
12
+ `TrackerTag` (Effect `Context.Tag`) at a composition root — the same
13
+ adapter-per-environment shape as REST vs Mongo behind `EntityRepositoryTag`.
14
+
15
+ Unlike OpenTelemetry (which stays unwrapped), a real vendor SDK belongs behind an
16
+ adapter: swapping PostHog for another analytics backend touches only this package.
@@ -0,0 +1,2 @@
1
+ export * from './make-browser-tracker.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './make-browser-tracker.js';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/browser/index.ts"],"sourcesContent":["export * from './make-browser-tracker.js';\n"],"names":[],"mappings":"AAAA,cAAc,4BAA4B"}
@@ -0,0 +1,13 @@
1
+ import type { Tracker } from '@entifix/tooling/tracking';
2
+ import type { PostHog } from 'posthog-js';
3
+ /**
4
+ * Adapt the `posthog-js` browser client to the {@link Tracker} port. The
5
+ * browser half of the analytics adapter: provided as `TrackerTag` in a Next
6
+ * client composition root, resolved by a `useTracker()` hook (the browser runs
7
+ * Effect DI just like the backend).
8
+ *
9
+ * `flag` reads the browser's locally-cached flags synchronously — which is why
10
+ * the `Tracker.flag` contract is sync — defaulting an unknown flag to `false`.
11
+ */
12
+ export declare const makeBrowserTracker: (posthog: PostHog) => Tracker;
13
+ //# sourceMappingURL=make-browser-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-browser-tracker.d.ts","sourceRoot":"","sources":["../../src/browser/make-browser-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAK1C;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,OAAO,KAAG,OAQpD,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ const toProperties = (props)=>props === undefined ? undefined : _extends({}, props);
3
+ /**
4
+ * Adapt the `posthog-js` browser client to the {@link Tracker} port. The
5
+ * browser half of the analytics adapter: provided as `TrackerTag` in a Next
6
+ * client composition root, resolved by a `useTracker()` hook (the browser runs
7
+ * Effect DI just like the backend).
8
+ *
9
+ * `flag` reads the browser's locally-cached flags synchronously — which is why
10
+ * the `Tracker.flag` contract is sync — defaulting an unknown flag to `false`.
11
+ */ export const makeBrowserTracker = (posthog)=>({
12
+ track: (event, props)=>{
13
+ posthog.capture(event, toProperties(props));
14
+ },
15
+ identify: (id, traits)=>{
16
+ posthog.identify(id, toProperties(traits));
17
+ },
18
+ flag: (key)=>{
19
+ var _posthog_getFeatureFlag;
20
+ return (_posthog_getFeatureFlag = posthog.getFeatureFlag(key)) != null ? _posthog_getFeatureFlag : false;
21
+ }
22
+ });
23
+
24
+ //# sourceMappingURL=make-browser-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/browser/make-browser-tracker.ts"],"sourcesContent":["import type { Props, Tracker } from '@entifix/tooling/tracking';\nimport type { PostHog } from 'posthog-js';\n\nconst toProperties = (props?: Props): Record<string, unknown> | undefined =>\n props === undefined ? undefined : { ...props };\n\n/**\n * Adapt the `posthog-js` browser client to the {@link Tracker} port. The\n * browser half of the analytics adapter: provided as `TrackerTag` in a Next\n * client composition root, resolved by a `useTracker()` hook (the browser runs\n * Effect DI just like the backend).\n *\n * `flag` reads the browser's locally-cached flags synchronously — which is why\n * the `Tracker.flag` contract is sync — defaulting an unknown flag to `false`.\n */\nexport const makeBrowserTracker = (posthog: PostHog): Tracker => ({\n track: (event, props) => {\n posthog.capture(event, toProperties(props));\n },\n identify: (id, traits) => {\n posthog.identify(id, toProperties(traits));\n },\n flag: key => posthog.getFeatureFlag(key) ?? false,\n});\n"],"names":["toProperties","props","undefined","makeBrowserTracker","posthog","track","event","capture","identify","id","traits","flag","key","getFeatureFlag"],"mappings":";AAGA,MAAMA,eAAe,CAACC,QACpBA,UAAUC,YAAYA,YAAY,aAAKD;AAEzC;;;;;;;;CAQC,GACD,OAAO,MAAME,qBAAqB,CAACC,UAA+B,CAAA;QAChEC,OAAO,CAACC,OAAOL;YACbG,QAAQG,OAAO,CAACD,OAAON,aAAaC;QACtC;QACAO,UAAU,CAACC,IAAIC;YACbN,QAAQI,QAAQ,CAACC,IAAIT,aAAaU;QACpC;QACAC,MAAMC,CAAAA;gBAAOR;oBAAAA,0BAAAA,QAAQS,cAAc,CAACD,gBAAvBR,0BAA+B;;IAC9C,CAAA,EAAG"}
@@ -0,0 +1,2 @@
1
+ export * from './make-posthog-tracker.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './make-posthog-tracker.js';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './make-posthog-tracker.js';\n"],"names":[],"mappings":"AAAA,cAAc,4BAA4B"}
@@ -0,0 +1,19 @@
1
+ import type { Tracker } from '@entifix/tooling/tracking';
2
+ import type { PostHog } from 'posthog-node';
3
+ /** Options for {@link makePostHogTracker}. */
4
+ export interface PostHogTrackerOptions {
5
+ /** distinctId used when a `track` call carries none (default `'anonymous'`). */
6
+ readonly distinctId?: string;
7
+ }
8
+ /**
9
+ * Adapt the `posthog-node` client to the framework-free {@link Tracker} port.
10
+ * The server-side half of the analytics adapter: provided as `TrackerTag`
11
+ * (`@entifix/business`) at a service composition root.
12
+ *
13
+ * `flag` returns `false` here: `posthog-node` evaluates flags asynchronously, so
14
+ * the synchronous `Tracker.flag` (which fits the browser's cached, sync eval) has
15
+ * no server-side answer. Server-side experiment assignment gets a dedicated async
16
+ * path if/when experiments move off the browser.
17
+ */
18
+ export declare const makePostHogTracker: (client: PostHog, options?: PostHogTrackerOptions) => Tracker;
19
+ //# sourceMappingURL=make-posthog-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-posthog-tracker.d.ts","sourceRoot":"","sources":["../src/make-posthog-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,8CAA8C;AAC9C,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAaD;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,OAAO,EACf,UAAS,qBAA0B,KAClC,OAeF,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ const toProperties = (props)=>props === undefined ? undefined : _extends({}, props);
3
+ const resolveDistinctId = (props, fallback)=>{
4
+ const fromProps = props == null ? void 0 : props['distinctId'];
5
+ return typeof fromProps === 'string' ? fromProps : fallback;
6
+ };
7
+ /**
8
+ * Adapt the `posthog-node` client to the framework-free {@link Tracker} port.
9
+ * The server-side half of the analytics adapter: provided as `TrackerTag`
10
+ * (`@entifix/business`) at a service composition root.
11
+ *
12
+ * `flag` returns `false` here: `posthog-node` evaluates flags asynchronously, so
13
+ * the synchronous `Tracker.flag` (which fits the browser's cached, sync eval) has
14
+ * no server-side answer. Server-side experiment assignment gets a dedicated async
15
+ * path if/when experiments move off the browser.
16
+ */ export const makePostHogTracker = (client, options = {})=>{
17
+ var _options_distinctId;
18
+ const fallback = (_options_distinctId = options.distinctId) != null ? _options_distinctId : 'anonymous';
19
+ return {
20
+ track: (event, props)=>{
21
+ client.capture({
22
+ distinctId: resolveDistinctId(props, fallback),
23
+ event,
24
+ properties: toProperties(props)
25
+ });
26
+ },
27
+ identify: (id, traits)=>{
28
+ client.identify({
29
+ distinctId: id,
30
+ properties: toProperties(traits)
31
+ });
32
+ },
33
+ flag: ()=>false
34
+ };
35
+ };
36
+
37
+ //# sourceMappingURL=make-posthog-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/make-posthog-tracker.ts"],"sourcesContent":["import type { Props, Tracker } from '@entifix/tooling/tracking';\nimport type { PostHog } from 'posthog-node';\n\n/** Options for {@link makePostHogTracker}. */\nexport interface PostHogTrackerOptions {\n /** distinctId used when a `track` call carries none (default `'anonymous'`). */\n readonly distinctId?: string;\n}\n\nconst toProperties = (props?: Props): Record<string, unknown> | undefined =>\n props === undefined ? undefined : { ...props };\n\nconst resolveDistinctId = (\n props: Props | undefined,\n fallback: string,\n): string => {\n const fromProps = props?.['distinctId'];\n return typeof fromProps === 'string' ? fromProps : fallback;\n};\n\n/**\n * Adapt the `posthog-node` client to the framework-free {@link Tracker} port.\n * The server-side half of the analytics adapter: provided as `TrackerTag`\n * (`@entifix/business`) at a service composition root.\n *\n * `flag` returns `false` here: `posthog-node` evaluates flags asynchronously, so\n * the synchronous `Tracker.flag` (which fits the browser's cached, sync eval) has\n * no server-side answer. Server-side experiment assignment gets a dedicated async\n * path if/when experiments move off the browser.\n */\nexport const makePostHogTracker = (\n client: PostHog,\n options: PostHogTrackerOptions = {},\n): Tracker => {\n const fallback = options.distinctId ?? 'anonymous';\n return {\n track: (event, props) => {\n client.capture({\n distinctId: resolveDistinctId(props, fallback),\n event,\n properties: toProperties(props),\n });\n },\n identify: (id, traits) => {\n client.identify({ distinctId: id, properties: toProperties(traits) });\n },\n flag: () => false,\n };\n};\n"],"names":["toProperties","props","undefined","resolveDistinctId","fallback","fromProps","makePostHogTracker","client","options","distinctId","track","event","capture","properties","identify","id","traits","flag"],"mappings":";AASA,MAAMA,eAAe,CAACC,QACpBA,UAAUC,YAAYA,YAAY,aAAKD;AAEzC,MAAME,oBAAoB,CACxBF,OACAG;IAEA,MAAMC,YAAYJ,yBAAAA,KAAO,CAAC,aAAa;IACvC,OAAO,OAAOI,cAAc,WAAWA,YAAYD;AACrD;AAEA;;;;;;;;;CASC,GACD,OAAO,MAAME,qBAAqB,CAChCC,QACAC,UAAiC,CAAC,CAAC;QAElBA;IAAjB,MAAMJ,YAAWI,sBAAAA,QAAQC,UAAU,YAAlBD,sBAAsB;IACvC,OAAO;QACLE,OAAO,CAACC,OAAOV;YACbM,OAAOK,OAAO,CAAC;gBACbH,YAAYN,kBAAkBF,OAAOG;gBACrCO;gBACAE,YAAYb,aAAaC;YAC3B;QACF;QACAa,UAAU,CAACC,IAAIC;YACbT,OAAOO,QAAQ,CAAC;gBAAEL,YAAYM;gBAAIF,YAAYb,aAAagB;YAAQ;QACrE;QACAC,MAAM,IAAM;IACd;AACF,EAAE"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@entifix/posthog",
3
+ "version": "0.1.0-0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/r10c-technologies/entifix.git",
8
+ "directory": "packages/ts/posthog-client"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ "./package.json": "./package.json",
19
+ ".": {
20
+ "@entifix/source": "./src/index.ts",
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./browser": {
26
+ "@entifix/source": "./src/browser/index.ts",
27
+ "types": "./dist/browser/index.d.ts",
28
+ "import": "./dist/browser/index.js",
29
+ "default": "./dist/browser/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "!**/*.tsbuildinfo",
35
+ "LICENSE"
36
+ ],
37
+ "nx": {
38
+ "tags": [
39
+ "layer:entifix",
40
+ "scope:shared",
41
+ "entifix:client",
42
+ "tier:2"
43
+ ],
44
+ "sourceRoot": "packages/ts/posthog-client/src",
45
+ "targets": {
46
+ "build": {
47
+ "executor": "@nx/js:swc",
48
+ "outputs": [
49
+ "{options.outputPath}"
50
+ ],
51
+ "options": {
52
+ "outputPath": "packages/ts/posthog-client/dist",
53
+ "main": "packages/ts/posthog-client/src/index.ts",
54
+ "tsConfig": "packages/ts/posthog-client/tsconfig.lib.json",
55
+ "skipTypeCheck": true,
56
+ "stripLeadingPaths": true
57
+ }
58
+ }
59
+ }
60
+ },
61
+ "dependencies": {
62
+ "@swc/helpers": "0.5.23",
63
+ "posthog-js": "1.417.0",
64
+ "posthog-node": "5.49.0",
65
+ "@entifix/tooling": "0.1.0-0"
66
+ }
67
+ }