Skip to content

fix: gate posthog analytics events#3541

Merged
Baalmart merged 1 commit into
stagingfrom
fix/posthog-analytics-gating
May 27, 2026
Merged

fix: gate posthog analytics events#3541
Baalmart merged 1 commit into
stagingfrom
fix/posthog-analytics-gating

Conversation

@Mozart299

@Mozart299 Mozart299 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Added ability to disable analytics tracking via research mode feature flag.
    • Fixed user identity initialization order in authentication flow.
  • Refactor

    • Disabled automatic application lifecycle event capturing in analytics.
    • Reordered analytics initialization sequence during user authentication.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2e257ea7-249e-4f52-9b8b-7b7e2e63a2ff

📥 Commits

Reviewing files that changed from the base of the PR and between 750e371 and eec75d9.

📒 Files selected for processing (4)
  • src/mobile/lib/main.dart
  • src/mobile/lib/src/app/auth/bloc/auth_bloc.dart
  • src/mobile/lib/src/app/shared/services/analytics_service.dart
  • src/mobile/lib/src/app/shared/services/feature_flag_service.dart

📝 Walkthrough

Walkthrough

This PR implements a feature-flag-driven analytics control system for the mobile app. A new isAnalyticsEnabled getter gates event capture in AnalyticsService, auth flows reorder user identity setup before tracking events, and PostHog stops capturing app lifecycle events automatically.

Changes

Analytics Event Control and User Identity Tracking

Layer / File(s) Summary
Feature flag analytics control
src/mobile/lib/src/app/shared/services/feature_flag_service.dart
Added isAnalyticsEnabled getter that returns the state of AppFeatureFlag.researchMode via the existing isEnabled(...) method.
Analytics event capture guard
src/mobile/lib/src/app/shared/services/analytics_service.dart
trackEvent now checks FeatureFlagService.instance.isAnalyticsEnabled and returns early without calling Posthog().capture(...) when analytics are disabled.
Auth user identity before tracking
src/mobile/lib/src/app/auth/bloc/auth_bloc.dart
In _onLoginUser, _onRegisterUser, and _onLoginWithProvider, reordered calls so AuthHelper.getCurrentUserId(...) and AnalyticsService().setUserIdentity(...) execute before trackUserLoggedIn()/trackUserRegistered().
PostHog lifecycle event configuration
src/mobile/lib/main.dart
Changed PostHog setup to set postHogConfig.captureApplicationLifecycleEvents from true to false.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

📊 Events now check before they fly,
User known when tracked on high,
Feature flags become the gate,
App lifecycle meets its fate. 🚀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the PR: gating PostHog analytics events based on feature flags, which is reflected across all four modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/posthog-analytics-gating

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mozart299
Mozart299 requested a review from Baalmart May 27, 2026 05:52
@Baalmart
Baalmart merged commit ed03ef7 into staging May 27, 2026
18 of 20 checks passed
@Baalmart
Baalmart deleted the fix/posthog-analytics-gating branch May 27, 2026 09:35
@Baalmart Baalmart mentioned this pull request May 27, 2026
7 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jul 8, 2026
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