-
Notifications
You must be signed in to change notification settings - Fork 201
fix: apply before_send to identify and groupIdentify events #2550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: apply before_send to identify and groupIdentify events #2550
Conversation
|
@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( |
There was a problem hiding this comment.
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
There was a problem hiding this 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
packages/node/src/client.ts
Outdated
| 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) | ||
| } | ||
| }) |
There was a problem hiding this comment.
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.
packages/node/src/client.ts
Outdated
| groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void { | ||
| super.groupIdentifyStateless(groupType, groupKey, properties, { disableGeoip }, distinctId) | ||
| this.prepareEventMessage({ | ||
| distinctId: distinctId || `$${groupType}_${groupKey}`, |
There was a problem hiding this comment.
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
Problem
An issue was raised where the
before_sendcallback was only invoked forcaptureevents, but not foridentifyorgroupIdentifyevents. This meant that users were unable to modify these event types viabefore_send.Changes
identify()andidentifyImmediate()methods to useprepareEventMessage()groupIdentify()to useprepareEventMessage()before_sendfunctionality for the updated methodsRelease info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file