posthog-node 2.5.2 → 2.5.3

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.
@@ -62,7 +62,7 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
62
62
  groupProperties?: Record<string, Record<string, string>>;
63
63
  onlyEvaluateLocally?: boolean;
64
64
  }): Promise<PosthogFlagsAndPayloadsResponse>;
65
- groupIdentify({ groupType, groupKey, properties }: GroupIdentifyMessage): void;
65
+ groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void;
66
66
  reloadFeatureFlags(): Promise<void>;
67
67
  shutdown(): void;
68
68
  shutdownAsync(): Promise<void>;
@@ -13,6 +13,7 @@ export interface GroupIdentifyMessage {
13
13
  groupType: string;
14
14
  groupKey: string;
15
15
  properties?: Record<string | number, any>;
16
+ distinctId?: string;
16
17
  }
17
18
  export declare type FeatureFlagCondition = {
18
19
  properties: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-node",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "description": "PostHog Node.js integration",
5
5
  "repository": "PostHog/posthog-node",
6
6
  "scripts": {
@@ -102,11 +102,14 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
102
102
  const featureVariantProperties: Record<string, string | boolean> = {}
103
103
  if (flags) {
104
104
  for (const [feature, variant] of Object.entries(flags)) {
105
- featureVariantProperties[`$feature/${feature}`] = variant
105
+ if (variant !== false) {
106
+ featureVariantProperties[`$feature/${feature}`] = variant
107
+ }
106
108
  }
107
109
  }
110
+ const activeFlags = Object.keys(flags || {}).filter((flag) => flags?.[flag] !== false)
108
111
  const flagProperties = {
109
- $active_feature_flags: flags ? Object.keys(flags) : undefined,
112
+ $active_feature_flags: activeFlags || undefined,
110
113
  ...featureVariantProperties,
111
114
  }
112
115
  _capture({ ...properties, $groups: groups, ...flagProperties })
@@ -332,8 +335,8 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
332
335
  return { featureFlags, featureFlagPayloads }
333
336
  }
334
337
 
335
- groupIdentify({ groupType, groupKey, properties }: GroupIdentifyMessage): void {
336
- super.groupIdentifyStateless(groupType, groupKey, properties)
338
+ groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void {
339
+ super.groupIdentifyStateless(groupType, groupKey, properties, undefined, distinctId)
337
340
  }
338
341
 
339
342
  async reloadFeatureFlags(): Promise<void> {
package/src/types.ts CHANGED
@@ -16,6 +16,7 @@ export interface GroupIdentifyMessage {
16
16
  groupType: string
17
17
  groupKey: string // Unique identifier for the group
18
18
  properties?: Record<string | number, any>
19
+ distinctId?: string // optional distinctId to associate message with a person
19
20
  }
20
21
 
21
22
  export type FeatureFlagCondition = {
@@ -234,7 +234,6 @@ describe('PostHog Node.js', () => {
234
234
  posthog.groupIdentify({ groupType: 'posthog', groupKey: 'team-1', properties: { analytics: true } })
235
235
  jest.runOnlyPendingTimers()
236
236
  const batchEvents = getLastBatchEvents()
237
- console.log(batchEvents)
238
237
  expect(batchEvents).toMatchObject([
239
238
  {
240
239
  distinct_id: '$posthog_team-1',
@@ -248,6 +247,29 @@ describe('PostHog Node.js', () => {
248
247
  },
249
248
  ])
250
249
  })
250
+
251
+ it('should allow passing optional distinctID to identify group', () => {
252
+ posthog.groupIdentify({
253
+ groupType: 'posthog',
254
+ groupKey: 'team-1',
255
+ properties: { analytics: true },
256
+ distinctId: '123',
257
+ })
258
+ jest.runOnlyPendingTimers()
259
+ const batchEvents = getLastBatchEvents()
260
+ expect(batchEvents).toMatchObject([
261
+ {
262
+ distinct_id: '123',
263
+ event: '$groupidentify',
264
+ properties: {
265
+ $group_type: 'posthog',
266
+ $group_key: 'team-1',
267
+ $group_set: { analytics: true },
268
+ $lib: 'posthog-node',
269
+ },
270
+ },
271
+ ])
272
+ })
251
273
  })
252
274
 
253
275
  describe('feature flags', () => {
@@ -256,6 +278,7 @@ describe('PostHog Node.js', () => {
256
278
  'feature-1': true,
257
279
  'feature-2': true,
258
280
  'feature-variant': 'variant',
281
+ 'disabled-flag': false,
259
282
  }
260
283
 
261
284
  const mockFeatureFlagPayloads = {