From 9c49bc854162e2d4a3080b3e8c8cab421f3cf0bb Mon Sep 17 00:00:00 2001 From: Ioannis J Date: Tue, 20 Jan 2026 23:18:06 +0200 Subject: [PATCH 1/3] chore(docs): add flutter beforeSend docs --- contents/docs/libraries/flutter/index.mdx | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/contents/docs/libraries/flutter/index.mdx b/contents/docs/libraries/flutter/index.mdx index 47bf4e04f89d..38f20c3679c7 100644 --- a/contents/docs/libraries/flutter/index.mdx +++ b/contents/docs/libraries/flutter/index.mdx @@ -206,6 +206,56 @@ To check if a user is opted out: await Posthog().isOptedOut(); ``` +## Amending or dropping events + +You can provide a `beforeSend` callback when initializing the SDK to amend or drop events before they are sent to PostHog. + +### Redacting information in events + +`beforeSend` gives you one place to edit or redact information before it is sent to PostHog. For example: + +```dart +final config = PostHogConfig(''); +config.host = ''; + +config.beforeSend = (event) { + // Redact email from properties + if (event.properties?['email'] != null) { + event.properties?['email'] = '***@***.***'; + } + return event; +}; + +await Posthog().setup(config); +``` + +### Dropping events + +Return `null` from the callback to drop the event: + +```dart +config.beforeSend = (event) { + // Drop events you don't want to send + if (event.event == 'ignored_event') { + return null; + } + return event; +}; +``` + +### Limitations + +The `beforeSend` callback only applies to events captured via Dart APIs: +- `Posthog().capture()` - custom events +- `Posthog().screen()` - screen events (event name is `$screen`) +- `Posthog().captureException()` - exception events (event name is `$exception`) + +It does **not** intercept native-initiated events such as: +- Session replay events (`$snapshot`) +- Application lifecycle events (`Application Opened`, etc.) + +Additionally, only user-provided properties are available in the callback. System properties (like `$device_type`, `$session_id`) are added by the native SDK at a later stage. + ## Debug mode If you're not seeing the expected events being captured, the feature flags being evaluated, or the surveys being shown, you can enable debug mode to see what's happening. From 585e62e066a2264e8e5f122d7389f92338c4d7b7 Mon Sep 17 00:00:00 2001 From: Ioannis J Date: Wed, 21 Jan 2026 00:03:20 +0200 Subject: [PATCH 2/3] fix: --- contents/docs/libraries/flutter/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/docs/libraries/flutter/index.mdx b/contents/docs/libraries/flutter/index.mdx index 38f20c3679c7..9b1d682907e4 100644 --- a/contents/docs/libraries/flutter/index.mdx +++ b/contents/docs/libraries/flutter/index.mdx @@ -208,7 +208,7 @@ await Posthog().isOptedOut(); ## Amending or dropping events -You can provide a `beforeSend` callback when initializing the SDK to amend or drop events before they are sent to PostHog. +Since version 5.12.0, you can provide a `beforeSend` callback when initializing the SDK to amend or drop events before they are sent to PostHog. ### Redacting information in events From 162ff48bc30479d56c6360609a265862f4977ec5 Mon Sep 17 00:00:00 2001 From: Ioannis J Date: Tue, 3 Feb 2026 15:30:28 +0200 Subject: [PATCH 3/3] Update contents/docs/libraries/flutter/index.mdx Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> --- contents/docs/libraries/flutter/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/docs/libraries/flutter/index.mdx b/contents/docs/libraries/flutter/index.mdx index 9b1d682907e4..875fb236932c 100644 --- a/contents/docs/libraries/flutter/index.mdx +++ b/contents/docs/libraries/flutter/index.mdx @@ -208,7 +208,7 @@ await Posthog().isOptedOut(); ## Amending or dropping events -Since version 5.12.0, you can provide a `beforeSend` callback when initializing the SDK to amend or drop events before they are sent to PostHog. +Since version 5.13.0, you can provide a `beforeSend` callback when initializing the SDK to amend or drop events before they are sent to PostHog. ### Redacting information in events