@hogsend/plugin-posthog 0.22.0 → 0.23.1

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/provider.ts +18 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hogsend/plugin-posthog",
3
- "version": "0.22.0",
3
+ "version": "0.23.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "posthog-node": "^5.35.1",
26
- "@hogsend/core": "^0.22.0"
26
+ "@hogsend/core": "^0.23.1"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "ioredis": ">=5.0.0"
package/src/provider.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { type AnalyticsProvider, defineAnalyticsProvider } from "@hogsend/core";
1
+ import {
2
+ type AnalyticsProvider,
3
+ defineAnalyticsProvider,
4
+ type IdentityMergeOptions,
5
+ } from "@hogsend/core";
2
6
  import { captureEvent } from "./capture.js";
3
7
  import { createPostHogClient, DEFAULT_HOST } from "./client.js";
4
8
  import { getPersonProperties } from "./properties.js";
@@ -61,6 +65,8 @@ export function createPostHogProvider(
61
65
  },
62
66
  personWrites: true,
63
67
  oauth: true,
68
+ // posthog-node exposes a native `alias` wire (anon-absorb merge).
69
+ identityMerge: true,
64
70
  },
65
71
 
66
72
  async getPersonProperties(distinctId: string) {
@@ -84,6 +90,17 @@ export function createPostHogProvider(
84
90
  });
85
91
  },
86
92
 
93
+ mergeIdentities({ distinctId, alias }: IdentityMergeOptions) {
94
+ // Direction is load-bearing (MF-1): `distinctId` is the SURVIVING /
95
+ // canonical (identified) id, `alias` the ABSORBED (anonymous) one — per
96
+ // the PostHog DOCS, NOT the posthog-node `.d.ts` example, which shows it
97
+ // backwards. The guard makes the Part-1 self-alias free and skips empties.
98
+ if (!distinctId || !alias || distinctId === alias) return;
99
+ // Fire-and-forget: rides the same async posthog-node queue as `capture`
100
+ // (we deliberately do NOT await `aliasImmediate` on any hot path).
101
+ client.alias({ distinctId, alias });
102
+ },
103
+
87
104
  capture(opts) {
88
105
  captureEvent({ client, ...opts });
89
106
  },