Skip to content

feat: add disableGeoip config - #720

Merged
marandaneto merged 4 commits into
PostHog:mainfrom
dirgaydtm:feat/disable-geoip
Nov 14, 2026
Merged

marandaneto merged 4 commits into
PostHog:mainfrom
dirgaydtm:feat/disable-geoip

Conversation

@dirgaydtm

@dirgaydtm dirgaydtm commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Closes #424.

Apps can now opt out of server-side GeoIP enrichment, so PostHog doesn't infer the user's location from their IP address. With disableGeoIp: true, events carry $geoip_disable: true and feature flag requests send geoip_disable: true. Defaults to false.

Platform Events /flags
iOS / macOS yes, via posthog-ios disableGeoIp (available at our 3.92.3 floor) yes
Desktop (Windows, Linux) yes, in the Dart core yes
Android yes, via posthog-android disableGeoIp (minimum 3.77.0) yes
Web no, a debug warning points to posthog-js before_send no

Android forwards the option to native PostHogAndroidConfig.disableGeoIp, released in posthog-android 3.77.0. The minimum Android SDK dependency is now 3.77.0. Native handling covers analytics events and feature flag requests without a plugin beforeSend workaround.

Divergence from sdk-specs

Compared with the capture requirement "Client-level GeoIP control with per-call override":

  • The spec stamps the marker before before_send. Here it's added after the Flutter beforeSend on every platform, because native SDKs and the desktop core add SDK properties after Dart callbacks run. The disableGeoIp dartdoc notes that a callback can't see or remove it.
  • No per-call option. The spec requires it for server SDKs only.
  • Flutter web does not apply the option.

$geoip_disable stays an event property on the v6 branch (it isn't in legacyOptionProperties), so this shouldn't conflict with capture v1.

💚 How did you test it?

  • Desktop core: events get the marker when enabled and omit it by default, a marker the caller passes in survives when the option is off, and the /flags body sends geoip_disable for both values.
  • Platform channel: setup sends disableGeoIp; setup_request.json snapshot updated.
  • Android: plugin tests verify native disableGeoIp forwarding for true, false, and omitted values. The true case failed before the native forwarding change and passes afterward.
  • Original contribution: flutter test (1319 passing), ./gradlew :posthog_flutter:testDebugUnitTest, make checkFormatDart analyzeDart checkApiDart.
  • Review follow-up: all 78 Android unit tests passed on JDK 17 with posthog-android 3.77.0. All 196 tests in test/core/feature_flags_test.dart, test/core/posthog_core_test.dart, and test/posthog_flutter_io_test.dart passed. make checkFormatKotlin checkFormatDart analyzeDart checkApiDart and git diff --check passed.

The original contribution did not locally test the Swift change, native formatters, or browser tests. The review follow-up ran Kotlin and Swift formatting checks, but did not build Swift or run browser tests.

  • Casing follow-up: renamed the public Flutter field and channel key to disableGeoIp to match Android/iOS; regenerated the API snapshot. Full Flutter VM suite: 1319 passed, 1 skipped; Android: 78 passed; finite compliance adapter suite: 25 passed. Kotlin/Dart/Swift formatting, Dart analysis, and API checks passed.
  • Real Android 15 emulator against PostHog Cloud: 21/21 synthetic events persisted with unique UUIDs, independently queried through PostHog MCP. Default and explicit false cases received GeoIP enrichment; all enabled-case events, including native lifecycle and flag-call events, carried the marker and had no location. Geographic flag-targeting outcomes were not tested because no existing fixture was available; no remote resources were created.

📝 Checklist

  • All commits are signed
  • 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 (Claude Opus 5.5 High) at my direction, test-first per seam (desktop core, platform channel, Android plugin), then reviewed against CONTRIBUTING.md and the sdk-specs GeoIP requirement. The initial implementation marked Android events behind a shortcut: comment. The Pi-assisted review follow-up replaces that workaround with native disableGeoIp configuration and raises the Android minimum to 3.77.0. Web follows the existing warning pattern because the host app initializes posthog-js.

Let an app opt out of server-side GeoIP enrichment. With disableGeoip
set, events carry $geoip_disable: true and feature flag requests send
geoip_disable: true.

iOS and macOS pass it to posthog-ios disableGeoIp, and the desktop core
stamps events and the /flags body itself. posthog-android has no such
option yet (PostHog/posthog-android#562), so the plugin marks events
through a native beforeSend and flag requests still use GeoIP there.
Flutter web only warns, as for other options posthog-js owns.

Refs PostHog#424
@dirgaydtm
dirgaydtm requested a review from a team as a code owner November 12, 2026 07:28
marandaneto
marandaneto previously approved these changes Nov 12, 2026

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code looks good; no qualifying findings. Verdict: correct.

Thank you for your contribution!

@marandaneto
marandaneto requested a review from a team November 12, 2026 09:35
@marandaneto
marandaneto dismissed their stale review November 12, 2026 09:35

left a comment

@marandaneto
marandaneto enabled auto-merge (squash) November 13, 2026 13:59

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code looks good; no qualifying findings. Verdict: correct.

Thank you for your contribution!

@marandaneto
marandaneto merged commit bef8702 into PostHog:main Nov 14, 2026
29 checks passed
posthog Bot added a commit to PostHog/posthog.com that referenced this pull request Nov 14, 2026
Add a "Disable GeoIP enrichment" section to the Flutter SDK docs for the new disableGeoIp config option (PostHog/posthog-flutter#720). It tells how to set the option, what it adds to events and flag requests, the Android minimum version, and the Flutter Web alternative.

The version 5.61.0 is the next minor release from the pending changeset. The current release is 5.60.3.

Generated-By: PostHog Desktop
Task-Id: ee724bc8-7ac8-4545-952d-c3b94a44928e
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.

Support disableGeoip config

2 participants