Skip to content

Conversation

@MohamedH1998
Copy link

@MohamedH1998 MohamedH1998 commented Nov 5, 2025

Problem

An issue was raised where the before_send callback was only invoked for capture events, but not for identify or groupIdentify events. This meant that users were unable to modify these event types via before_send.

Changes

  • Refactor identify() and identifyImmediate() methods to use prepareEventMessage()
  • Refactor groupIdentify() to use prepareEventMessage()
  • Add tests for before_send functionality for the updated methods

Release info Sub-libraries affected

Libraries affected

  • All of them
  • posthog-js (web)
  • posthog-js-lite (web lite)
  • posthog-node
  • posthog-react-native
  • @posthog/react
  • @posthog/ai
  • @posthog/nextjs-config
  • @posthog/nuxt

Checklist

  • Tests for new code
  • Accounted for the impact of any changes across different platforms
  • Accounted for backwards compatibility of any changes (no breaking changes!)
  • Took care not to unnecessarily increase the bundle size

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

@vercel
Copy link

vercel bot commented Nov 5, 2025

@MohamedH1998 is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

$set_once: userPropsOnce,
},
{ disableGeoip }
this.addPendingPromise(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is consistent w/ capture method implementation

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 1148 to 1173
this.prepareEventMessage({
distinctId: distinctId || `$${groupType}_${groupKey}`,
event: '$groupidentify',
properties: {
$group_type: groupType,
$group_key: groupKey,
$group_set: properties || {},
},
disableGeoip,
})
.then(({ distinctId, properties, options }) => {
const { $group_type, $group_key, $group_set, ...eventProperties } = properties
return super.groupIdentifyStateless(
$group_type as string,
$group_key as string | number,
$group_set as PostHogEventProperties,
options,
distinctId,
eventProperties
)
})
.catch((err) => {
if (err) {
console.error(err)
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing addPendingPromise() wrapper around promise chain

both identify() (line 437) and identifyImmediate() (line 483) wrap their promise chains with addPendingPromise(), but groupIdentify() doesn't. this means the promise won't be tracked in the promise queue, potentially causing events to be lost during flush() operations.

wrap the entire promise chain with this.addPendingPromise(...) like the other methods do.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/node/src/client.ts
Line: 1148:1173

Comment:
**logic:** missing `addPendingPromise()` wrapper around promise chain

both `identify()` (line 437) and `identifyImmediate()` (line 483) wrap their promise chains with `addPendingPromise()`, but `groupIdentify()` doesn't. this means the promise won't be tracked in the promise queue, potentially causing events to be lost during `flush()` operations.

wrap the entire promise chain with `this.addPendingPromise(...)` like the other methods do.

How can I resolve this? If you propose a fix, please make it concise.

groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void {
super.groupIdentifyStateless(groupType, groupKey, properties, { disableGeoip }, distinctId)
this.prepareEventMessage({
distinctId: distinctId || `$${groupType}_${groupKey}`,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how groupIdentifyStateless also sets distinctId when the incoming param is null

@MohamedH1998 MohamedH1998 changed the title fix: apply before_send to identify and groupIdentify ends fix: apply before_send to identify and groupIdentify events Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant