@walkeros/web-destination-posthog 3.3.0-next-1776098542393

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.
@@ -0,0 +1,206 @@
1
+ import { Mapping, Flow } from '@walkeros/core';
2
+ import { DestinationWeb } from '@walkeros/web-core';
3
+ import { PostHogConfig, Properties } from 'posthog-js';
4
+
5
+ /**
6
+ * Destination-level settings.
7
+ *
8
+ * PostHog's `PostHogConfig` interface has ~80 fields — extending the SDK type
9
+ * directly keeps IntelliSense complete and prevents drift. The destination adds:
10
+ * - `apiKey` (required) — first arg to `posthog.init(...)`, NOT an init option
11
+ * - `identify` — destination-level identity mapping
12
+ * - `include` — event sections flattened into `capture()` properties
13
+ * - `group` — destination-level group association
14
+ * - `_state` — runtime state (not user-facing, mutated by init/push)
15
+ *
16
+ * All other walkerOS-specific mapping features live under mapping.settings
17
+ * (see Mapping interface below). Built-in PostHog features (session_recording,
18
+ * advanced_disable_flags, disable_surveys, capture_heatmaps, capture_exceptions,
19
+ * bootstrap, cookieless_mode, ...) are passthrough via PostHogConfig.
20
+ */
21
+ interface Settings extends Partial<PostHogConfig> {
22
+ /** PostHog project API key (e.g. "phc_XXX"). First arg to posthog.init(). */
23
+ apiKey: string;
24
+ /** Destination-level identity mapping, resolved on first push. */
25
+ identify?: Mapping.Value;
26
+ /** Destination-level group association, resolved on first push. */
27
+ group?: Mapping.Value;
28
+ /** Runtime state — populated by init() and mutated by push(). Not user-facing. */
29
+ _state?: RuntimeState;
30
+ }
31
+ interface RuntimeState {
32
+ /** Last-resolved identity values, used to skip redundant identify/group calls. */
33
+ lastIdentity?: {
34
+ distinctId?: string;
35
+ };
36
+ lastGroup?: {
37
+ type?: string;
38
+ key?: string;
39
+ };
40
+ }
41
+ /**
42
+ * PostHog SDK surface — the subset of `posthog-js` the destination actually
43
+ * uses. Mirrors the real module's default singleton export shape. Tests mock
44
+ * via env.posthog to intercept every call.
45
+ */
46
+ interface PostHogSDK {
47
+ init: (token: string, config?: Partial<PostHogConfig> & {
48
+ loaded?: (posthog: PostHogSDK) => void;
49
+ }, name?: string) => PostHogSDK;
50
+ capture: (eventName: string, properties?: Properties) => void;
51
+ identify: (distinctId?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties) => void;
52
+ setPersonProperties: (userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties) => void;
53
+ group: (groupType: string, groupKey: string, groupPropertiesToSet?: Properties) => void;
54
+ reset: (resetDeviceId?: boolean) => void;
55
+ opt_in_capturing: (options?: {
56
+ captureEventName?: string | null | false;
57
+ captureProperties?: Properties;
58
+ }) => void;
59
+ opt_out_capturing: () => void;
60
+ }
61
+ /**
62
+ * Env — optional SDK override. Production leaves this undefined and the
63
+ * destination falls back to the real `posthog-js` default export. Tests
64
+ * provide a mock via env.posthog = { ... }.
65
+ */
66
+ interface Env extends DestinationWeb.Env {
67
+ posthog?: PostHogSDK;
68
+ }
69
+
70
+ /**
71
+ * Pre-init env — all methods are no-ops until the test runner wires spies.
72
+ */
73
+ declare const init: Env | undefined;
74
+ /**
75
+ * Post-init env — same shape. The test runner clones this and replaces
76
+ * individual methods with jest.fn() so it can assert on calls.
77
+ */
78
+ declare const push: Env;
79
+ /** Simulation tracking paths for CLI --simulate. */
80
+ declare const simulation: string[];
81
+
82
+ declare const env_init: typeof init;
83
+ declare const env_push: typeof push;
84
+ declare const env_simulation: typeof simulation;
85
+ declare namespace env {
86
+ export { env_init as init, env_push as push, env_simulation as simulation };
87
+ }
88
+
89
+ /**
90
+ * Examples may optionally carry destination-level settings.
91
+ * The test runner reads `settings` from the example and merges them
92
+ * into the base destination settings on top of the fixed apiKey.
93
+ */
94
+ type PostHogStepExample = Flow.StepExample & {
95
+ settings?: Partial<Settings>;
96
+ configInclude?: string[];
97
+ };
98
+ /**
99
+ * Default event forwarding — every walkerOS event becomes
100
+ * posthog.capture(event.name, properties). With no mapping and no
101
+ * destination-level include, properties is `{}`.
102
+ */
103
+ declare const defaultEventForwarding: PostHogStepExample;
104
+ /**
105
+ * Wildcard ignore — walkerOS's standard way to drop events. The rule
106
+ * matches but does nothing. The destination fires zero SDK calls.
107
+ */
108
+ declare const wildcardIgnored: PostHogStepExample;
109
+ /**
110
+ * Destination-level settings.include flattens the walkerOS `data` section
111
+ * into prefixed capture() properties on every push.
112
+ */
113
+ declare const destinationLevelInclude: PostHogStepExample;
114
+ /**
115
+ * Per-rule settings.include REPLACES destination-level include for the
116
+ * matched rule. Here destination-level sends `data`, but the rule
117
+ * overrides it with `globals` only.
118
+ */
119
+ declare const ruleIncludeReplaces: PostHogStepExample;
120
+ /**
121
+ * Destination-level settings.identify fires on the first push (once the
122
+ * state cache is empty). The destination calls posthog.identify() and
123
+ * tracks the resolved distinctId in runtime state; subsequent pushes
124
+ * with unchanged values do NOT re-fire identify().
125
+ *
126
+ * With NO $set/$set_once keys in the resolved object, posthog.identify
127
+ * is called with just the distinctId.
128
+ */
129
+ declare const destinationLevelIdentify: PostHogStepExample;
130
+ /**
131
+ * Per-event identify with the full PostHog identity vocabulary.
132
+ * This is the "user login" pattern: set a new distinctId and enrich
133
+ * person properties. `skip: true` suppresses the default posthog.capture()
134
+ * call because we're running identity side effects only.
135
+ *
136
+ * PostHog identify signature:
137
+ * posthog.identify(distinctId, $set, $set_once)
138
+ */
139
+ declare const userLoginIdentify: PostHogStepExample;
140
+ /**
141
+ * Person-properties-only update — when the resolved identify object has
142
+ * NO `distinctId` key, the destination calls setPersonProperties($set, $set_once)
143
+ * instead of identify(). This is the "profile update" pattern: enrich
144
+ * user properties without changing identity.
145
+ *
146
+ * `skip` defaults to false here — we intentionally ALSO capture a
147
+ * "profile update" event so it shows up in PostHog's event stream.
148
+ */
149
+ declare const profileUpdateSetPersonProperties: PostHogStepExample;
150
+ /**
151
+ * User logout — reset: true fires posthog.reset(), which clears the
152
+ * distinct ID and generates a new anonymous one. `skip: true` because
153
+ * we're only running the reset side effect, no default capture().
154
+ */
155
+ declare const userLogoutReset: PostHogStepExample;
156
+ /**
157
+ * Group assignment + group properties. PostHog's group analytics (paid)
158
+ * aggregates events by company / team / project. The destination resolves
159
+ * `settings.group` to { type, key, properties? } and calls
160
+ * posthog.group(type, key, properties). `skip: true` keeps this a
161
+ * pure side-effect rule — no "company update" capture().
162
+ */
163
+ declare const groupAssignmentWithProperties: PostHogStepExample;
164
+ /**
165
+ * Order complete — PostHog has no dedicated revenue API. Revenue tracking
166
+ * is just a capture() call with the revenue properties in data. This
167
+ * example pairs `include: ["data", "globals"]` with a destination-level
168
+ * capture. The order total, shipping, currency, etc. all become
169
+ * data_* properties on the PostHog event.
170
+ */
171
+ declare const orderCompleteWithInclude: PostHogStepExample;
172
+ /**
173
+ * Consent revoked → posthog.opt_out_capturing(). The destination checks
174
+ * the consent key declared in config.consent (here "analytics") and
175
+ * toggles accordingly. opt_out_capturing() stops capture, session
176
+ * replay, AND survey rendering.
177
+ *
178
+ * Uses the canonical StepExample.command='consent' pattern: the test
179
+ * runner dispatches via elb('walker consent', in) instead of pushing
180
+ * an event.
181
+ */
182
+ declare const consentRevokeOptOut: PostHogStepExample;
183
+ /**
184
+ * Consent granted → posthog.opt_in_capturing(). Called without arguments
185
+ * by default (the SDK fires its own $opt_in event).
186
+ */
187
+ declare const consentGrantOptIn: PostHogStepExample;
188
+
189
+ type step_PostHogStepExample = PostHogStepExample;
190
+ declare const step_consentGrantOptIn: typeof consentGrantOptIn;
191
+ declare const step_consentRevokeOptOut: typeof consentRevokeOptOut;
192
+ declare const step_defaultEventForwarding: typeof defaultEventForwarding;
193
+ declare const step_destinationLevelIdentify: typeof destinationLevelIdentify;
194
+ declare const step_destinationLevelInclude: typeof destinationLevelInclude;
195
+ declare const step_groupAssignmentWithProperties: typeof groupAssignmentWithProperties;
196
+ declare const step_orderCompleteWithInclude: typeof orderCompleteWithInclude;
197
+ declare const step_profileUpdateSetPersonProperties: typeof profileUpdateSetPersonProperties;
198
+ declare const step_ruleIncludeReplaces: typeof ruleIncludeReplaces;
199
+ declare const step_userLoginIdentify: typeof userLoginIdentify;
200
+ declare const step_userLogoutReset: typeof userLogoutReset;
201
+ declare const step_wildcardIgnored: typeof wildcardIgnored;
202
+ declare namespace step {
203
+ export { type step_PostHogStepExample as PostHogStepExample, step_consentGrantOptIn as consentGrantOptIn, step_consentRevokeOptOut as consentRevokeOptOut, step_defaultEventForwarding as defaultEventForwarding, step_destinationLevelIdentify as destinationLevelIdentify, step_destinationLevelInclude as destinationLevelInclude, step_groupAssignmentWithProperties as groupAssignmentWithProperties, step_orderCompleteWithInclude as orderCompleteWithInclude, step_profileUpdateSetPersonProperties as profileUpdateSetPersonProperties, step_ruleIncludeReplaces as ruleIncludeReplaces, step_userLoginIdentify as userLoginIdentify, step_userLogoutReset as userLogoutReset, step_wildcardIgnored as wildcardIgnored };
204
+ }
205
+
206
+ export { env, step };
@@ -0,0 +1,206 @@
1
+ import { Mapping, Flow } from '@walkeros/core';
2
+ import { DestinationWeb } from '@walkeros/web-core';
3
+ import { PostHogConfig, Properties } from 'posthog-js';
4
+
5
+ /**
6
+ * Destination-level settings.
7
+ *
8
+ * PostHog's `PostHogConfig` interface has ~80 fields — extending the SDK type
9
+ * directly keeps IntelliSense complete and prevents drift. The destination adds:
10
+ * - `apiKey` (required) — first arg to `posthog.init(...)`, NOT an init option
11
+ * - `identify` — destination-level identity mapping
12
+ * - `include` — event sections flattened into `capture()` properties
13
+ * - `group` — destination-level group association
14
+ * - `_state` — runtime state (not user-facing, mutated by init/push)
15
+ *
16
+ * All other walkerOS-specific mapping features live under mapping.settings
17
+ * (see Mapping interface below). Built-in PostHog features (session_recording,
18
+ * advanced_disable_flags, disable_surveys, capture_heatmaps, capture_exceptions,
19
+ * bootstrap, cookieless_mode, ...) are passthrough via PostHogConfig.
20
+ */
21
+ interface Settings extends Partial<PostHogConfig> {
22
+ /** PostHog project API key (e.g. "phc_XXX"). First arg to posthog.init(). */
23
+ apiKey: string;
24
+ /** Destination-level identity mapping, resolved on first push. */
25
+ identify?: Mapping.Value;
26
+ /** Destination-level group association, resolved on first push. */
27
+ group?: Mapping.Value;
28
+ /** Runtime state — populated by init() and mutated by push(). Not user-facing. */
29
+ _state?: RuntimeState;
30
+ }
31
+ interface RuntimeState {
32
+ /** Last-resolved identity values, used to skip redundant identify/group calls. */
33
+ lastIdentity?: {
34
+ distinctId?: string;
35
+ };
36
+ lastGroup?: {
37
+ type?: string;
38
+ key?: string;
39
+ };
40
+ }
41
+ /**
42
+ * PostHog SDK surface — the subset of `posthog-js` the destination actually
43
+ * uses. Mirrors the real module's default singleton export shape. Tests mock
44
+ * via env.posthog to intercept every call.
45
+ */
46
+ interface PostHogSDK {
47
+ init: (token: string, config?: Partial<PostHogConfig> & {
48
+ loaded?: (posthog: PostHogSDK) => void;
49
+ }, name?: string) => PostHogSDK;
50
+ capture: (eventName: string, properties?: Properties) => void;
51
+ identify: (distinctId?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties) => void;
52
+ setPersonProperties: (userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties) => void;
53
+ group: (groupType: string, groupKey: string, groupPropertiesToSet?: Properties) => void;
54
+ reset: (resetDeviceId?: boolean) => void;
55
+ opt_in_capturing: (options?: {
56
+ captureEventName?: string | null | false;
57
+ captureProperties?: Properties;
58
+ }) => void;
59
+ opt_out_capturing: () => void;
60
+ }
61
+ /**
62
+ * Env — optional SDK override. Production leaves this undefined and the
63
+ * destination falls back to the real `posthog-js` default export. Tests
64
+ * provide a mock via env.posthog = { ... }.
65
+ */
66
+ interface Env extends DestinationWeb.Env {
67
+ posthog?: PostHogSDK;
68
+ }
69
+
70
+ /**
71
+ * Pre-init env — all methods are no-ops until the test runner wires spies.
72
+ */
73
+ declare const init: Env | undefined;
74
+ /**
75
+ * Post-init env — same shape. The test runner clones this and replaces
76
+ * individual methods with jest.fn() so it can assert on calls.
77
+ */
78
+ declare const push: Env;
79
+ /** Simulation tracking paths for CLI --simulate. */
80
+ declare const simulation: string[];
81
+
82
+ declare const env_init: typeof init;
83
+ declare const env_push: typeof push;
84
+ declare const env_simulation: typeof simulation;
85
+ declare namespace env {
86
+ export { env_init as init, env_push as push, env_simulation as simulation };
87
+ }
88
+
89
+ /**
90
+ * Examples may optionally carry destination-level settings.
91
+ * The test runner reads `settings` from the example and merges them
92
+ * into the base destination settings on top of the fixed apiKey.
93
+ */
94
+ type PostHogStepExample = Flow.StepExample & {
95
+ settings?: Partial<Settings>;
96
+ configInclude?: string[];
97
+ };
98
+ /**
99
+ * Default event forwarding — every walkerOS event becomes
100
+ * posthog.capture(event.name, properties). With no mapping and no
101
+ * destination-level include, properties is `{}`.
102
+ */
103
+ declare const defaultEventForwarding: PostHogStepExample;
104
+ /**
105
+ * Wildcard ignore — walkerOS's standard way to drop events. The rule
106
+ * matches but does nothing. The destination fires zero SDK calls.
107
+ */
108
+ declare const wildcardIgnored: PostHogStepExample;
109
+ /**
110
+ * Destination-level settings.include flattens the walkerOS `data` section
111
+ * into prefixed capture() properties on every push.
112
+ */
113
+ declare const destinationLevelInclude: PostHogStepExample;
114
+ /**
115
+ * Per-rule settings.include REPLACES destination-level include for the
116
+ * matched rule. Here destination-level sends `data`, but the rule
117
+ * overrides it with `globals` only.
118
+ */
119
+ declare const ruleIncludeReplaces: PostHogStepExample;
120
+ /**
121
+ * Destination-level settings.identify fires on the first push (once the
122
+ * state cache is empty). The destination calls posthog.identify() and
123
+ * tracks the resolved distinctId in runtime state; subsequent pushes
124
+ * with unchanged values do NOT re-fire identify().
125
+ *
126
+ * With NO $set/$set_once keys in the resolved object, posthog.identify
127
+ * is called with just the distinctId.
128
+ */
129
+ declare const destinationLevelIdentify: PostHogStepExample;
130
+ /**
131
+ * Per-event identify with the full PostHog identity vocabulary.
132
+ * This is the "user login" pattern: set a new distinctId and enrich
133
+ * person properties. `skip: true` suppresses the default posthog.capture()
134
+ * call because we're running identity side effects only.
135
+ *
136
+ * PostHog identify signature:
137
+ * posthog.identify(distinctId, $set, $set_once)
138
+ */
139
+ declare const userLoginIdentify: PostHogStepExample;
140
+ /**
141
+ * Person-properties-only update — when the resolved identify object has
142
+ * NO `distinctId` key, the destination calls setPersonProperties($set, $set_once)
143
+ * instead of identify(). This is the "profile update" pattern: enrich
144
+ * user properties without changing identity.
145
+ *
146
+ * `skip` defaults to false here — we intentionally ALSO capture a
147
+ * "profile update" event so it shows up in PostHog's event stream.
148
+ */
149
+ declare const profileUpdateSetPersonProperties: PostHogStepExample;
150
+ /**
151
+ * User logout — reset: true fires posthog.reset(), which clears the
152
+ * distinct ID and generates a new anonymous one. `skip: true` because
153
+ * we're only running the reset side effect, no default capture().
154
+ */
155
+ declare const userLogoutReset: PostHogStepExample;
156
+ /**
157
+ * Group assignment + group properties. PostHog's group analytics (paid)
158
+ * aggregates events by company / team / project. The destination resolves
159
+ * `settings.group` to { type, key, properties? } and calls
160
+ * posthog.group(type, key, properties). `skip: true` keeps this a
161
+ * pure side-effect rule — no "company update" capture().
162
+ */
163
+ declare const groupAssignmentWithProperties: PostHogStepExample;
164
+ /**
165
+ * Order complete — PostHog has no dedicated revenue API. Revenue tracking
166
+ * is just a capture() call with the revenue properties in data. This
167
+ * example pairs `include: ["data", "globals"]` with a destination-level
168
+ * capture. The order total, shipping, currency, etc. all become
169
+ * data_* properties on the PostHog event.
170
+ */
171
+ declare const orderCompleteWithInclude: PostHogStepExample;
172
+ /**
173
+ * Consent revoked → posthog.opt_out_capturing(). The destination checks
174
+ * the consent key declared in config.consent (here "analytics") and
175
+ * toggles accordingly. opt_out_capturing() stops capture, session
176
+ * replay, AND survey rendering.
177
+ *
178
+ * Uses the canonical StepExample.command='consent' pattern: the test
179
+ * runner dispatches via elb('walker consent', in) instead of pushing
180
+ * an event.
181
+ */
182
+ declare const consentRevokeOptOut: PostHogStepExample;
183
+ /**
184
+ * Consent granted → posthog.opt_in_capturing(). Called without arguments
185
+ * by default (the SDK fires its own $opt_in event).
186
+ */
187
+ declare const consentGrantOptIn: PostHogStepExample;
188
+
189
+ type step_PostHogStepExample = PostHogStepExample;
190
+ declare const step_consentGrantOptIn: typeof consentGrantOptIn;
191
+ declare const step_consentRevokeOptOut: typeof consentRevokeOptOut;
192
+ declare const step_defaultEventForwarding: typeof defaultEventForwarding;
193
+ declare const step_destinationLevelIdentify: typeof destinationLevelIdentify;
194
+ declare const step_destinationLevelInclude: typeof destinationLevelInclude;
195
+ declare const step_groupAssignmentWithProperties: typeof groupAssignmentWithProperties;
196
+ declare const step_orderCompleteWithInclude: typeof orderCompleteWithInclude;
197
+ declare const step_profileUpdateSetPersonProperties: typeof profileUpdateSetPersonProperties;
198
+ declare const step_ruleIncludeReplaces: typeof ruleIncludeReplaces;
199
+ declare const step_userLoginIdentify: typeof userLoginIdentify;
200
+ declare const step_userLogoutReset: typeof userLogoutReset;
201
+ declare const step_wildcardIgnored: typeof wildcardIgnored;
202
+ declare namespace step {
203
+ export { type step_PostHogStepExample as PostHogStepExample, step_consentGrantOptIn as consentGrantOptIn, step_consentRevokeOptOut as consentRevokeOptOut, step_defaultEventForwarding as defaultEventForwarding, step_destinationLevelIdentify as destinationLevelIdentify, step_destinationLevelInclude as destinationLevelInclude, step_groupAssignmentWithProperties as groupAssignmentWithProperties, step_orderCompleteWithInclude as orderCompleteWithInclude, step_profileUpdateSetPersonProperties as profileUpdateSetPersonProperties, step_ruleIncludeReplaces as ruleIncludeReplaces, step_userLoginIdentify as userLoginIdentify, step_userLogoutReset as userLogoutReset, step_wildcardIgnored as wildcardIgnored };
204
+ }
205
+
206
+ export { env, step };