Skip to content

feat!: run beforeSend on the native-built event on iOS, macOS and Android - #682

Merged
turnipdabeets merged 29 commits into
feat/v6-desktop-capture-v1from
feat/v6-before-send-parity
Nov 3, 2026
Merged

turnipdabeets merged 29 commits into
feat/v6-desktop-capture-v1from
feat/v6-before-send-parity

Conversation

@turnipdabeets

@turnipdabeets turnipdabeets commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

On iOS, macOS and Android, Dart beforeSend callbacks ran on the raw call input, before the native SDK added its properties. The native properties won afterwards, so a callback couldn't see or remove device, app, session or registered properties, and it had no uuid, timestamp or distinct id. Windows, Linux and the native iOS and Android SDKs already run beforeSend on the final event. This brings Flutter mobile in line with them in 6.0. Changing what the callback receives later would be a breaking change.

Calling the Dart hook from inside native beforeSend doesn't work: native hooks are synchronous and method channels are async, the same problem #255 hit. Instead, the event takes two calls: native builds the event, Dart runs the callbacks, then native sends the result.

Depends on unreleased native APIs. It needs buildEventForWrapper / sendBuiltEventForWrapper from PostHog/posthog-android#904 and PostHog/posthog-ios#991. The native ranges stay 4.0.0 ..< 5.0.0, since both APIs ship in 4.0.0. Both PRs, and the follow-up fixes from review (PostHog/posthog-ios#1010 and #1012, PostHog/posthog-android#928 and #930), are merged into feat/v4-capture-v1; 4.0.0 isn't released yet.

Changes

  • Mobile beforeSend: with callbacks set, capture, captureAi, screen and captureException call buildEvent, run the callbacks on the built event, then call sendBuiltEvent. A dropped event calls discardBuiltEvent, which only frees the plugin's copy. With no callbacks, an event still takes the single existing native call.
  • PostHogEvent: new uuid (read-only), distinctId and timestamp fields, set on iOS, macOS and Android. $set and $set_once still arrive as userProperties / userPropertiesSetOnce, as on desktop.
  • Native hooks: PosthogFlutterPlugin.addBeforeSend in Swift and Kotlin covers events the native SDK captures itself (crashes, lifecycle, $feature_flag_called, replay, identify). These hooks run after the plugin's $flutter_version hook.
  • Unchanged: identify, alias, group and setPersonProperties still don't go through the Dart hook (documented).
  • Plugin internals: the plugin holds each built event between the two calls, so native-only state on the event survives. Callbacks are synchronous, so Dart sends an event back right after they run. One that never comes back (for example after a hot restart) is dropped on the next build once it is a minute old, so it can't stay in memory. On Android, native values the channel can't carry (for example a Date registered natively) are sent to Dart as strings.
  • Cleanup: the old Dart-side hook path is removed, since it only ran with no callbacks.

💚 How did you test it?

🧪 How to test locally (for agents and reviewers)

CI's build-android and build-apple jobs can't pass until posthog-ios and posthog-android 4.0 are released, because no 4.x version resolves yet. To test now, build against the native feat/v4-capture-v1 branches. Don't commit these overrides.

Android: check out feat/v4-capture-v1 of posthog-android, then:

sed -i '' -E 's/^coreVersion=.*/coreVersion=7.99.0/; s/^androidVersion=.*/androidVersion=4.99.0/' gradle.properties
./gradlew :posthog:publishToMavenLocal :posthog-android:publishToMavenLocal -x signMavenPublication

Add mavenLocal() as the first repository in example/android/build.gradle.kts. Use a new version for each republish, because Gradle can reuse a stale one.

iOS/macOS: check out feat/v4-capture-v1 of posthog-ios and point posthog_flutter/darwin/posthog_flutter/Package.swift at it:

.package(name: "posthog-ios", path: "/absolute/path/to/posthog-ios"),

Build: from example/, with Swift Package Manager enabled (flutter config --enable-swift-package-manager), run flutter build apk --debug and flutter build ios --simulator --debug.

Local server: set config.host to http://127.0.0.1:<port>.

  • Android: add android:usesCleartextTraffic="true" to <application> and run adb reverse tcp:<port> tcp:<port>.
  • iOS: set NSAppTransportSecurity > NSAllowsArbitraryLoads in Runner/Info.plist.
  • Server: use HTTP/1.1, and return {"hasFeatureFlags": true} from /array/<token>/config. Otherwise Android skips /flags and reports empty flags.

Run tests on a device with flutter test integration_test/<file>.dart -d <device>.

What to check on this PR: the native dependencies (posthog-android#904, posthog-ios#991) are already in feat/v4-capture-v1. A Dart beforeSend should see the native-added properties, its edits and drops should win, and events the native SDK captures itself should also go through it.

Merge notes

#686 and #688 are merged in (Nov 3):

Still conflicts with:

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Written with Claude Code. The approach (native build → Dart hook → native send, plus a native-side hook) was picked over three alternatives: calling Dart from native beforeSend (ruled out because native hooks are synchronous), having Dart rebuild the properties (they'd drift from native state), and documenting the gap. Ran an automated code review before pushing; fixes from it are in this commit (no-throw handling of unreadable built events, blank distinctId ignored, codec-safe Android values, dead code removed).

@turnipdabeets turnipdabeets self-assigned this Oct 29, 2026
@turnipdabeets
turnipdabeets requested a review from a team as a code owner October 29, 2026 00:00

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 893daf8: 2 Must fix, 2 Should fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

posthog-flutter Compliance Report

Date: 2026-11-03T23:41:15.169959+00:00
Duration: 370116ms

✅ All Tests Passed!

232/232 tests passed


Capture_V1 Tests

✅ 105/105 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 255ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 130ms
Required Headers.Has Authorization Bearer Header ✅ 126ms
Required Headers.Has Content Type Json ✅ 128ms
Required Headers.Has Posthog Sdk Info Format ✅ 122ms
Required Headers.Has Posthog Attempt Header ✅ 123ms
Required Headers.Has Posthog Request Id ✅ 124ms
Required Headers.Has Posthog Request Timestamp ✅ 123ms
Required Headers.Has User Agent ✅ 124ms
Body Format.Body Has Created At And Batch ✅ 121ms
Body Format.No Api Key In Body ✅ 120ms
Body Format.No Sent At In Body ✅ 121ms
Event Format.Event Has Required Root Fields ✅ 120ms
Event Format.Event Uuid Is Valid ✅ 121ms
Event Format.Event Timestamp Is Rfc3339 ✅ 122ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 121ms
Event Format.Distinct Id Is String ✅ 123ms
Event Format.Distinct Id At Root Not Properties ✅ 120ms
Event Format.Custom Properties Preserved ✅ 122ms
Event Format.Set Properties Preserved ✅ 121ms
Event Format.Set Once Properties Preserved ✅ 121ms
Event Format.Groups Properties Preserved ✅ 120ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 121ms
Event Format.Event Has Required Root Fields Batch ✅ 127ms
Event Format.Event Uuid Is Valid Batch ✅ 127ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 125ms
Event Format.Distinct Id Is String Batch ✅ 127ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 126ms
Event Format.Custom Properties Preserved Batch ✅ 128ms
Event Format.Set Properties Preserved Batch ✅ 125ms
Event Format.Set Once Properties Preserved Batch ✅ 126ms
Event Format.Groups Properties Preserved Batch ✅ 126ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 125ms
Batch Behavior.Multiple Events In Single Batch ✅ 133ms
Batch Behavior.Batch Envelope Smoke ✅ 128ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 109ms
Batch Behavior.Flush At Triggers Batch ✅ 1017ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 121ms
Deduplication.Generates Unique Uuids ✅ 133ms
Deduplication.Different Events Same Content Different Uuids ✅ 123ms
Deduplication.Preserves Uuid On Retry ✅ 5129ms
Deduplication.Preserves Timestamp On Retry ✅ 5126ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5132ms
Deduplication.No Duplicate Events In Batch ✅ 132ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 118ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 10130ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 5124ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2235ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 5127ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 120ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 124ms
Response Format Validation.Success No Retry After When All Ok ✅ 121ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 122ms
Response Format Validation.Success No Retry After When Drop Only ✅ 123ms
Response Format Validation.Response Echoes Request Id ✅ 117ms
Retry Behavior.Retries On 408 ✅ 5125ms
Retry Behavior.Retries On 500 ✅ 5125ms
Retry Behavior.Retries On 503 ✅ 5124ms
Retry Behavior.Retries On 504 ✅ 5126ms
Retry Behavior.Retries On 404 ✅ 5127ms
Retry Behavior.Retries On 429 ✅ 5125ms
Retry Behavior.Retries On 502 ✅ 5125ms
Retry Behavior.Retryable Errors Have Retry After ✅ 2124ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 8128ms
Retry Behavior.Does Not Retry On 400 ✅ 2120ms
Retry Behavior.Does Not Retry On 401 ✅ 2122ms
Retry Behavior.Does Not Retry On 402 ✅ 2121ms
Retry Behavior.Does Not Retry On 413 ✅ 2122ms
Retry Behavior.Does Not Retry On 415 ✅ 2123ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2121ms
Retry Behavior.Implements Backoff ✅ 12133ms
Partial Batch Handling.Handles 200 Full Success ✅ 2123ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3127ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3126ms
Partial Batch Handling.Does Not Retry Warning Events ✅ 3126ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 5127ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 5128ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 5130ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 5128ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 5127ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 5130ms
Partial Batch Handling.Respects Retry After On Partial ✅ 5125ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3125ms
Partial Batch Handling.Mixed Ok Drop Warning No Retry ✅ 3130ms
Compression.Sends Gzip Content Encoding ✅ 122ms
Compression.No Content Encoding When Disabled ✅ 117ms
Compression.Compressed Body Is Decompressible ✅ 117ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2120ms
Event Options.Cookieless Mode Override ✅ 120ms
Event Options.Disable Skew Correction Override ✅ 118ms
Event Options.Process Person Profile Override ✅ 119ms
Event Options.Product Tour Id Override ✅ 117ms
Event Options.Unset Options Omitted ✅ 116ms
Event Options.Options Override In Batch ✅ 123ms
Event Options.Unknown Option Passes Through ✅ 119ms
Event Options.Option Value Is Not Converted ✅ 118ms
Event Options.Lenient Bool Option Values Are Not Converted ✅ 117ms
Event Options.Option Wins Over Legacy Property ✅ 118ms
Event Options.Legacy Property Fills Unset Option ✅ 117ms
Event Options.Null Option Falls Back To Legacy Property ✅ 118ms
Property Layers.Caller Property Beats Registered Property ✅ 118ms
Property Layers.Before Send Runs Last ✅ 118ms
Fail Open.Empty Api Key Sends Nothing ✅ 1113ms
Fail Open.Personal Api Key Sends Nothing ✅ 1111ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 119ms

Capture_Ai_V1 Tests

✅ 110/110 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 121ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 119ms
Endpoint And Method.Capture Does Not Reroute Ai Named Events ✅ 119ms
Endpoint And Method.Capture Ai Does Not Reroute Non Ai Events ✅ 117ms
Lane Isolation.Failing Ai Lane Does Not Delay Analytics ✅ 5134ms
Required Headers.Has Authorization Bearer Header ✅ 119ms
Required Headers.Has Content Type Json ✅ 118ms
Required Headers.Has Posthog Sdk Info Format ✅ 118ms
Required Headers.Has Posthog Attempt Header ✅ 117ms
Required Headers.Has Posthog Request Id ✅ 117ms
Required Headers.Has Posthog Request Timestamp ✅ 118ms
Required Headers.Has User Agent ✅ 118ms
Body Format.Body Has Created At And Batch ✅ 118ms
Body Format.No Api Key In Body ✅ 118ms
Body Format.No Sent At In Body ✅ 117ms
Event Format.Event Has Required Root Fields ✅ 117ms
Event Format.Event Uuid Is Valid ✅ 117ms
Event Format.Event Timestamp Is Rfc3339 ✅ 116ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 118ms
Event Format.Distinct Id Is String ✅ 118ms
Event Format.Distinct Id At Root Not Properties ✅ 118ms
Event Format.Custom Properties Preserved ✅ 117ms
Event Format.Set Properties Preserved ✅ 117ms
Event Format.Set Once Properties Preserved ✅ 117ms
Event Format.Groups Properties Preserved ✅ 117ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 117ms
Event Format.Event Has Required Root Fields Batch ✅ 123ms
Event Format.Event Uuid Is Valid Batch ✅ 124ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 122ms
Event Format.Distinct Id Is String Batch ✅ 123ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 122ms
Event Format.Custom Properties Preserved Batch ✅ 123ms
Event Format.Set Properties Preserved Batch ✅ 123ms
Event Format.Set Once Properties Preserved Batch ✅ 122ms
Event Format.Groups Properties Preserved Batch ✅ 122ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 124ms
Batch Behavior.Multiple Events In Single Batch ✅ 128ms
Batch Behavior.Batch Envelope Smoke ✅ 125ms
Batch Behavior.Flush At Triggers Batch ✅ 1015ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 119ms
Deduplication.Generates Unique Uuids ✅ 129ms
Deduplication.Different Events Same Content Different Uuids ✅ 121ms
Deduplication.Preserves Uuid On Retry ✅ 5123ms
Deduplication.Preserves Timestamp On Retry ✅ 5125ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5129ms
Deduplication.No Duplicate Events In Batch ✅ 129ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 118ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 10128ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 5124ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2232ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 5125ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 118ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 124ms
Response Format Validation.Success No Retry After When All Ok ✅ 121ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 120ms
Response Format Validation.Success No Retry After When Drop Only ✅ 121ms
Response Format Validation.Response Echoes Request Id ✅ 118ms
Retry Behavior.Retries On 408 ✅ 5124ms
Retry Behavior.Retries On 500 ✅ 5123ms
Retry Behavior.Retries On 503 ✅ 5124ms
Retry Behavior.Retries On 504 ✅ 5124ms
Retry Behavior.Retries On 404 ✅ 5124ms
Retry Behavior.Retries On 429 ✅ 5124ms
Retry Behavior.Retries On 502 ✅ 5125ms
Retry Behavior.Retryable Errors Have Retry After ✅ 2120ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 8127ms
Retry Behavior.Does Not Retry On 400 ✅ 2123ms
Retry Behavior.Does Not Retry On 401 ✅ 2121ms
Retry Behavior.Does Not Retry On 402 ✅ 2121ms
Retry Behavior.Does Not Retry On 413 ✅ 2121ms
Retry Behavior.Does Not Retry On 415 ✅ 2123ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2122ms
Retry Behavior.Implements Backoff ✅ 12130ms
Partial Batch Handling.Handles 200 Full Success ✅ 2121ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3127ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3123ms
Partial Batch Handling.Does Not Retry Warning Events ✅ 3124ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 5126ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 5127ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 5130ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 5125ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 5126ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 5125ms
Partial Batch Handling.Respects Retry After On Partial ✅ 5126ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3125ms
Partial Batch Handling.Mixed Ok Drop Warning No Retry ✅ 3129ms
Compression.Sends Gzip Content Encoding ✅ 117ms
Compression.No Content Encoding When Disabled ✅ 117ms
Compression.Compressed Body Is Decompressible ✅ 117ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2120ms
Event Options.Cookieless Mode Override ✅ 117ms
Event Options.Disable Skew Correction Override ✅ 117ms
Event Options.Process Person Profile Override ✅ 116ms
Event Options.Product Tour Id Override ✅ 118ms
Event Options.Unset Options Omitted ✅ 116ms
Event Options.Options Override In Batch ✅ 122ms
Event Options.Unknown Option Passes Through ✅ 116ms
Event Options.Option Value Is Not Converted ✅ 116ms
Event Options.Lenient Bool Option Values Are Not Converted ✅ 117ms
Event Options.Option Wins Over Legacy Property ✅ 118ms
Event Options.Legacy Property Fills Unset Option ✅ 116ms
Event Options.Null Option Falls Back To Legacy Property ✅ 118ms
Event Size.Event Over Ceiling Is Not Sent ✅ 3553ms
Event Size.Over Ceiling Drop Is Reported Or Logged Without Content ✅ 2192ms
Event Size.Batches Close Before Byte Target ✅ 5543ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 120ms
Property Layers.Caller Property Beats Registered Property ✅ 117ms
Property Layers.Before Send Runs Last ✅ 116ms
Fail Open.Empty Api Key Sends Nothing ✅ 1112ms
Fail Open.Personal Api Key Sends Nothing ✅ 1113ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 24ms
Request Payload.Flags Request Uses V2 Query Param ✅ 17ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 14ms
Request Payload.Flags Request Omits Authorization Header ✅ 13ms
Request Payload.Token In Flags Body Matches Init ✅ 13ms
Request Payload.Groups Round Trip ✅ 14ms
Request Payload.Groups Default To Empty Object ✅ 13ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 13ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 13ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 14ms
Request Lifecycle.No Flags Request On Init Alone ✅ 5ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 116ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 22ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 15ms
Retry Behavior.Retries Flags On 502 ✅ 322ms
Retry Behavior.Retries Flags On 504 ✅ 322ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 124ms

@veria-ai

veria-ai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 749478a: 1 Must fix.

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 980eee4: 1 Should fix.

This is review round 3 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.

Base automatically changed from feat/v6-desktop-capture-ai to feat/v6-desktop-capture-v1 October 29, 2026 21:05
turnipdabeets and others added 8 commits October 30, 2026 11:11
…roid

Dart beforeSend callbacks now get the event the native SDK built, with
its system and registered properties, uuid, distinct id and timestamp,
and the native SDK sends what they return without adding properties.
Without callbacks, events still take one native call.

Also adds PosthogFlutterPlugin.addBeforeSend in Swift and Kotlin for
events the native SDK captures itself.
- On Windows and Linux, `PostHogEvent` now carries the event's uuid,
  distinct ID and timestamp, as on iOS, macOS and Android. A callback can
  change the distinct ID (a blank one keeps the current) and the
  timestamp; the event keeps its uuid.
- `$exception_steps` are attached as the event is built, before the
  callbacks, as posthog-ios and posthog-android do, so a callback sees
  and can remove them. Steps recorded while a callback runs, or an event
  renamed to `$exception`, no longer get them.
- The prepared core event carries its uuid and distinct ID, which the
  queue keeps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… current user's flag cache

When a beforeSend callback sends the event for another distinct id, its
$set and $set_once no longer update the current user's flag person
properties or person-properties hash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 1e3bc43: 1 Must fix, 1 Should fix.

This is review round 4 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.

Native refuses sendBuiltEvent once one of them has reached it, so the event
would be lost if they could run between buildEvent and sendBuiltEvent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
turnipdabeets added a commit that referenced this pull request Oct 30, 2026
With #682 and beforeSend set, an event takes two native calls. Without the
queue, an optOut(), close() or setup() made right after capture() reaches
native between them and the event is lost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
turnipdabeets and others added 4 commits October 30, 2026 13:07
setup() replaces the callbacks synchronously, so an event still waiting on
its native build ran the next setup's chain, or none, and skipped its filter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With callbacks set, capture('$screen') reached the native builders' screen()
path, which drops an event without a $screen_name and, on iOS, ignores person
properties. Build it under another name and restore the name in Dart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	posthog_flutter/lib/src/posthog_flutter_desktop.dart

@eli-r-ph eli-r-ph left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CI never compiles or tests the new Kotlin and Swift code, because the build jobs fail at dependency download. Please build and test locally against the native 4.x branches before merging.

Comment thread posthog_flutter/MIGRATION.md Resolved
turnipdabeets and others added 4 commits November 2, 2026 18:39
…p captured

Matches iOS and Android. A callback that adds $set to an anonymous event no
longer turns person processing on for later events, and one that strips $set
no longer leaves it off after a person-processed event.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Android

Nested values from the method channel are untyped, so a callback casting
$exception_list to List<Map<String, dynamic>> threw and the event was dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A wall clock jump during a beforeSend callback could evict and lose the
event. Android already uses a monotonic clock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
turnipdabeets added a commit that referenced this pull request Nov 3, 2026
* feat!: make beforeSend callbacks synchronous

Event and log beforeSend callbacks no longer return FutureOr, matching the
native SDKs and the before-send-hook spec. The event is handed to the SDK in
the same call, so calls made right after an un-awaited capture can no longer
reach the SDK first, on every platform including Windows and Linux.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: keep the call queue on iOS, macOS and Android

With #682 and beforeSend set, an event takes two native calls. Without the
queue, an optOut(), close() or setup() made right after capture() reaches
native between them and the event is lost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(android): restore the screenshot scale expectation lost in the main merge

* fix(web): hand feature events to posthog-js before yielding

Without CallOrder the await on the flag lookup let a reset() made right after
an un-awaited captureFeatureView or captureFeatureInteraction overtake it, so
the event went out as the new anonymous user with the previous user's flag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: fold #686 release notes into the 6.0 docs

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Brings in synchronous beforeSend (#686) and the desktop queue worker (#688).

- IO keeps the native build/send path; applyBeforeSend is no longer awaited.
- Desktop: the prepared event's uuid and distinctId reach both
  capturePrepared and the new async captureAiPrepared, and person
  processing still follows what the app captured. An event sent for
  another distinct id leaves the current user's person state alone on
  both lanes.
- Tests with async hooks are dropped, as #686 did; the "calls made right
  after an event" test expects buildEvent/sendBuiltEvent with a hook.
turnipdabeets added a commit that referenced this pull request Nov 3, 2026
…eset

Folds in the MIGRATION.md and changeset text of #682, #698, #703, #670,
#695 and #699 so landing this PR last is "take this side".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
turnipdabeets added a commit that referenced this pull request Nov 3, 2026
Takes #682's built-event path in posthog_core.dart, posthog_flutter_io.dart
and posthog_flutter_desktop.dart. #682's prepared event carries the
distinct id, uuid and person processing, so this branch's distinctId
parameters, hadPersonProcessing and its own $exception_steps move are
dropped. Keeps this branch's desktop continuation check (project and
consent only, so an event a callback's reset() or identify() outlives is
sent as its user) and the screen session guard.

The IO hook tests now expect buildEvent and sendBuiltEvent instead of
capture. The weaker duplicate $exception_steps desktop test is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
turnipdabeets and others added 2 commits November 3, 2026 15:50
* feat!: make beforeSend callbacks synchronous

Event and log beforeSend callbacks no longer return FutureOr, matching the
native SDKs and the before-send-hook spec. The event is handed to the SDK in
the same call, so calls made right after an un-awaited capture can no longer
reach the SDK first, on every platform including Windows and Linux.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: keep the call queue on iOS, macOS and Android

With #682 and beforeSend set, an event takes two native calls. Without the
queue, an optOut(), close() or setup() made right after capture() reaches
native between them and the event is lost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(android): restore the screenshot scale expectation lost in the main merge

* fix(web): hand feature events to posthog-js before yielding

Without CallOrder the await on the flag lookup let a reset() made right after
an un-awaited captureFeatureView or captureFeatureInteraction overtake it, so
the event went out as the new anonymous user with the previous user's flag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: fold #686 release notes into the 6.0 docs

* fix: run a renaming beforeSend once and keep its user properties

A hook that renamed a screen or exception ran again through capture() and lost
its userProperties on web, iOS, Android and macOS. Also covers calls made from
inside a hook and bursts of events, and documents that a hook blocks the UI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: keep events when beforeSend resets on desktop or sets user properties on web

On Windows and Linux, a callback calling reset() or identify() dropped the
event. It now goes out as the user it was prepared for, as on iOS, Android and
macOS. On web, userProperties set on a screen or exception that kept its name
were lost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(web): keep an event on its user when beforeSend changes the user

posthog-js builds the event after the callbacks, so one calling reset() or
identify() moved the event to the new user. It now stays on the earlier user,
as on the other platforms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(desktop): keep the prepared user's person and session state when beforeSend changes the user

A hook calling reset() or identify() left the event on its original user,
but person processing was recomputed from the replacement's state, and a
$screen hook calling reset() put the old screen in the new session.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(web): don't restore the distinct id across a beforeSend consent change

Under cookieless_mode on_reject, restoring the id reattached the opted-out
user to a cookieless event, or sent the shared cookieless id after opting in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(web): drop user properties when beforeSend resets the user

posthog-js stores an event's $set as the current user's person properties
for flags, so after a reset() in the callback they reached the next user.
identify() of an anonymous user links the two, so they stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: note what a web beforeSend calling reset() keeps

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: add exception steps before beforeSend on Windows and Linux

beforeSend can now read, change or remove $exception_steps, as on iOS and Android.

Claude-Session: https://claude.ai/code/session_019xLynws83apuXa9LfRy9Aq

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
turnipdabeets and others added 2 commits November 3, 2026 18:32
…apter

The adapter's captureStateless/captureAiStateless overrides now forward
the uuid parameter, and its prepareEvent override copies uuid, distinctId
and requestsPersonProcessing, so it compiles against #690's base.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@turnipdabeets
turnipdabeets merged commit 0d9204f into feat/v6-desktop-capture-v1 Nov 3, 2026
20 of 23 checks passed
@turnipdabeets
turnipdabeets deleted the feat/v6-before-send-parity branch November 3, 2026 23:35
turnipdabeets added a commit that referenced this pull request Nov 3, 2026
… platform (#701)

* docs: link the capture v1 SDK upgrade guide

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: cover capture v1 on Windows and Linux and align the 6.0 guide with the backend SDK guides

Claude-Session: https://claude.ai/code/session_019xLynws83apuXa9LfRy9Aq

* docs: lone surrogates on Windows and Linux (#703)

Claude-Session: https://claude.ai/code/session_019xLynws83apuXa9LfRy9Aq

* docs: identify ignores a distinct ID with a lone surrogate (#703)

Claude-Session: https://claude.ai/code/session_019xLynws83apuXa9LfRy9Aq

* docs: complete the platform interface changes and the upgrade checklist

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: document the final 6.0 state in the guide and one grouped changeset

Folds in the MIGRATION.md and changeset text of #682, #698, #703, #670,
#695 and #699 so landing this PR last is "take this side".

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: describe lone surrogates as repaired on Windows and Linux

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: cover the /flags request in the lone surrogate changeset entry

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: note the /flags request in the lone surrogate guide line

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: say the SDK keeps lone-surrogate ids as passed and repairs what it sends

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: drop the confirmed capture v1 default TODOs from the guide

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: say $locale follows a per-app language picked in macOS Settings too

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants