Repository navigation
docs(before-send-hook): run the hook once, on the event as sent - #151
Draft
posthog[bot] wants to merge 1 commit into
Draft
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
posthog-android ran the hook chain twice per stateful capture, and posthog-rust merged groups and trimmed minimized $feature_flag_called events after the hook. Both now match posthog-ios and posthog-python. Specify the single invocation and the event shape the hook sees. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: 4237a2aa-9610-4c4f-a024-1ae7a64b0d75
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two SDKs changed their before-send behavior this week, in the same direction, because the spec never said how many times the hook runs or which assembly steps must already be done when it does.
uuid-keyed sampling hooks kept about half their configured rate, and hook edits todistinctId,timestampanduuidwere discarded by the rebuild. The fix queues the event the single hook pass returned, and minimizes$feature_flag_calledbefore the hook, as the stateless path and posthog-ios already did.$groupsafter the hook, so a hook could not see or change them, and minimized$feature_flag_calledevents were trimmed after the hook, so properties a hook added were silently dropped. Both steps now run before the hook, matching posthog-python.What changed in the spec
before-send-hookgains one requirement: the hook chain runs exactly once per captured event; the event handed to it is the event that would be sent if the hook returned it unchanged (groups already merged, minimized flag-called events already trimmed); and the SDK enqueues what the hook returned instead of rebuilding it. The existing Flutter wrapper-layer divergence is carried over unchanged.Proposed, applied and archived on this branch under
openspec/changes/archive/2026-10-27-run-before-send-once-on-the-sent-event/, asAGENTS.mdasks.Uncertain / for review
acceptance/private/before-send-hook.featureis untouched: the harness has no steps for invocation counts, group merging, or minimal flag-called events. The four new scenarios live inspec.mdonly and have not been run against an adapter.openspec validate --specs --strictwas not run — the OpenSpec CLI is not installed in this environment.Created with PostHog Desktop
🤖 Generated with Claude Code