Skip to content

[leancode_analytics_posthog] Send one $screen event per navigation - #563

Open
zoskar wants to merge 2 commits into
masterfrom
fix/posthog-observer-duplicate-screen
Open

[leancode_analytics_posthog] Send one $screen event per navigation#563
zoskar wants to merge 2 commits into
masterfrom
fix/posthog-observer-duplicate-screen

Conversation

@zoskar

@zoskar zoskar commented Aug 10, 2026

Copy link
Copy Markdown

⚠️ - 🤖 AI fix for sth that came out in new project made from template

Problem

LeanAnalyticsPostHogObserver sends a $screen for the LeanAnalyticsRoute id, then calls super,
which makes PosthogObserver send a second one named after RouteSettings.name.

One navigation, two events, two naming schemes — in an auto_route app that's loginPage and
LoginRoute for the same push. Screen view counts come out doubled and split across both names.

It only surfaces when routes carry a non-empty RouteSettings.name; PosthogObserver skips the
rest, which is why the package can look fine in projects that don't name their routes.

Fix

Pass a nameExtractor that returns null, so the inherited screen view is suppressed while
PosthogObserver's own bookkeeping — survey context, route subscriptions — still runs.

Routes that don't implement LeanAnalyticsRoute stop being tracked, which is what the class already
documents.

zoskar added 2 commits August 10, 2026 13:34
The observer sent its own screen view for the `LeanAnalyticsRoute` id and
then delegated to `PosthogObserver`, which sent a second one named after
`RouteSettings.name`. Suppressing the inherited screen view with a null
`nameExtractor` keeps the superclass bookkeeping intact.
@zoskar zoskar self-assigned this Aug 10, 2026
@zoskar
zoskar requested a review from alszczep August 10, 2026 11:41
@zoskar
zoskar marked this pull request as ready for review August 10, 2026 11:44
@PiotrRogulski

Copy link
Copy Markdown
Member

@zoskar I think a more "complete" fix would be to implement support for parameters in the posthog_flutter package itself 😛 (e.g., there could be a parametersExtractor next to the exxisting nameExtractor)

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.

2 participants