Skip to content

feat(analytics): multi-provider (Firebase+Matomo), queueing with persistence, standardized events#2932

Merged
CharlVS merged 42 commits intodevfrom
add/enhanced-analytics-v2
Oct 2, 2025
Merged

feat(analytics): multi-provider (Firebase+Matomo), queueing with persistence, standardized events#2932
CharlVS merged 42 commits intodevfrom
add/enhanced-analytics-v2

Conversation

@CharlVS
Copy link
Copy Markdown
Collaborator

@CharlVS CharlVS commented Jul 15, 2025

feat(analytics): multi-provider (Firebase+Matomo), queueing with persistence, standardized events

@KomodoPlatform/qa Jump to the bottom of this message for testing info; but I still suggest reading below for additional context.

Overview

  • Introduces Analytics v2 with a unified repository that can fan out events to multiple providers in parallel.
  • Adds optional Matomo provider alongside Firebase, gated by runtime flags and disabled automatically when config is absent or analytics are disabled (CI/privacy).
  • Implements robust queueing and persistence to prevent event loss across restarts and during provider initialization/disable periods.
  • Standardizes event names and parameters; extends coverage in DEX, Bridge, Wallet Withdraw, Market Maker Bot, NFTs, Settings, and UI telemetry.

Key changes

  • Multiple providers behind a single interface
    • New interface lib/bloc/analytics/analytics_api.dart.
    • Providers: FirebaseAnalyticsApi and MatomoAnalyticsApi.
    • Orchestration and fan-out: lib/bloc/analytics/analytics_repo.dart registers Firebase always; registers Matomo only when both MATOMO_URL and MATOMO_SITE_ID are provided; enforces ANALYTICS_DISABLED and CI gating via lib/shared/constants.dart.
  • Provider initialization, activation, and retries
    • Each provider handles initialize/activate/deactivate/retry with up to 3 retries and debug logging. Firebase skips unsupported platforms (Linux).
  • Queueing and persistence
    • Providers maintain their own queues; repository delegates queueing.
    • Firebase: periodic persistence to SharedPreferences and restore on startup; flush on activation.
    • Matomo: uses matomo_tracker persistent dispatch; queues in-memory when disabled and flushes on activation. Optional visit-scoped custom dimension for platform.
  • Matomo provider (optional)
    • Config via --dart-define and lib/shared/constants.dart: MATOMO_URL, MATOMO_SITE_ID, optional MATOMO_PLATFORM_DIMENSION_ID.
    • Initialization enforces trailing slash; disables self when config missing; respects ANALYTICS_DISABLED and CI. Adds optional X-KW-KEY header from FEEDBACK_API_KEY if present.
    • Sends events using EventInfo with category derived from event name; numeric value inferred from common keys.
  • Event schema and coverage
    • Standardized snake_case event names and parameters across categories.
    • Extended events and wiring: DEX maker/taker confirmation, Bridge confirmation, Wallet Withdraw, NFTs (gallery/transfer), Market Maker Bot (setup/trade/error), Settings theme selection, searchbar input, and UI telemetry.
    • See lib/analytics/analytics_factory.dart, lib/analytics/events/*, and updates in lib/views/* such as:
      • lib/views/dex/simple/confirm/maker_order_confirmation.dart
      • lib/views/dex/simple/confirm/taker_order_confirmation.dart
      • lib/views/bridge/bridge_confirmation.dart
      • lib/views/wallet/coin_details/withdraw_form/withdraw_form.dart
  • Flags, gating, and docs
    • Runtime defines in lib/shared/constants.dart: ANALYTICS_DISABLED, CI, MATOMO_URL, MATOMO_SITE_ID, MATOMO_PLATFORM_DIMENSION_ID.
    • Docs updated: docs/ANALYTICS.md, new docs/MATOMO_SETUP.md, docs/FIREBASE_SETUP.md.
  • CI and platform
    • macOS plugin registrant updated; pubspec.yaml adds matomo_tracker.
    • Minor workflow/action adjustments.

Developer notes (build flags)

  • Disable analytics entirely (applies to all providers):
--dart-define=ANALYTICS_DISABLED=true
  • CI environment (implicitly disables analytics in code):
--dart-define=CI=true
  • Enable Matomo (requires both):
--dart-define=MATOMO_URL=https://your-matomo.example.com/
--dart-define=MATOMO_SITE_ID=1
  • Optional: set a Matomo visit-scoped platform dimension:
--dart-define=MATOMO_PLATFORM_DIMENSION_ID=12

Notes:

  • Matomo remains disabled when MATOMO_URL or MATOMO_SITE_ID is missing. Ensure MATOMO_URL ends with a trailing slash (as required by matomo_tracker).
  • Firebase Analytics is not initialized on Linux.

Scope

  • 40 files changed, 2196 insertions, 1277 deletions.
  • Major areas: lib/bloc/analytics/*, lib/analytics/analytics_factory.dart, lib/analytics/events/*, lib/shared/constants.dart, DEX/Bridge/Withdraw/NFT/MMB views, docs, workflows, and macOS registrant.

No breaking changes

  • Default behavior unchanged without Matomo flags; Firebase continues to work as before.
  • Analytics can be disabled via settings and runtime flags; no PII added; event updates are additive.

Testing (QA)

  1. Basic app-wide smoke testing to confirm the event hooks haven't broken the actual events.
  2. Ensure that the events are being logged for Google Analytics and Matomo either by viewing the console requests (filter kwa.komodoplatform.com for Matomo, not sure about URL for Google Analytics), or (preferably) viewing the events in Matomo and Firebase. @gcharang, please set up @smk762 with access to Matomo.

It's not realistic to test all 45 analytics events (file), but it may be sufficient to monitor the logged events post-release. When we have time, we can do a thorough scrub of all analytics to ensure they are always firing when they should, exactly once - no more and no less.


Note

Introduce unified analytics with Firebase+Matomo, robust queueing/persistence, runtime/CI gating, and standardized event instrumentation across DEX, Bridge, Wallet, NFTs, MMB, Settings, and UI.

  • Analytics:
    • Architecture: Add AnalyticsApi interface and unified AnalyticsRepository to fan out events to multiple providers.
    • Providers: Implement FirebaseAnalyticsApi and optional MatomoAnalyticsApi (registered via flags); both support activate/deactivate/retry.
    • Queueing/Persistence: Provider-level queues; Firebase persists via SharedPreferences; Matomo uses persistent dispatch; flush on activation.
    • Runtime Gating: Add ANALYTICS_DISABLED and CI flags; optional MATOMO_URL, MATOMO_SITE_ID (and platform dimension) in shared/constants.dart.
  • Event Schema & Coverage:
    • Standardize event names/params (snake_case; asset/network/hd_type/failure_reason, etc.).
    • Wire events in DEX (maker/taker), Bridge, Withdraw, NFTs (gallery/transfer), Market Maker Bot (setup/trade/error), Settings theme, searchbar, HD address, data sync, performance.
  • Docs:
    • Update docs/ANALYTICS.md, docs/FIREBASE_SETUP.md; add docs/MATOMO_SETUP.md with flags and setup guidance.
  • Build/CI:
    • Add Matomo inputs and analytics-disable behavior to build/action workflow; integration runner passes CI flags to disable analytics in tests.
  • Deps/Platform:
    • Add matomo_tracker (and related plugin registrations); minor macOS registrant/project updates.
  • Misc:
    • Add unit test scaffold for AnalyticsRepository.

Written by Cursor Bugbot for commit c3551a3. This will update automatically on new commits. Configure here.

CharlVS added 4 commits June 5, 2025 19:38
- Resolved conflicts in analytics_repo.dart by keeping the new provider-based architecture while maintaining compatibility
- Updated dependency resolved-refs to latest from dev branch
- Unified HTTP dependency version to match dev branch
- Updated win32 dependency version from dev branch
@CharlVS CharlVS self-assigned this Jul 15, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 15, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add/enhanced-analytics-v2

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.

@CharlVS CharlVS changed the base branch from main to dev July 15, 2025 16:36
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 15, 2025

Visit the preview URL for this PR (updated for commit c3551a3):

https://walletrc--pull-2932-merge-7y966wuu.web.app

(expires Wed, 08 Oct 2025 15:43:18 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f66a4ff03faa546f12f0ae5a841bd9eff2714dcc

cursor[bot]

This comment was marked as outdated.

CharlVS and others added 13 commits August 12, 2025 20:11
* Refactor analytics events with wallet type and add logging for various flows

Co-authored-by: charl <charl@vanstaden.info>

* Remove analytics logging from NFT withdraw footer

Co-authored-by: charl <charl@vanstaden.info>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
…into add/enhanced-analytics-v2

# Conflicts:
#	ios/Podfile.lock
#	macos/Podfile.lock
#	pubspec.lock
- ci(generate-assets,firebase-hosting): update action and PR workflow

- feat(analytics): Matomo API and analytics repo updates

- chore(shared): update constants

- test(integration): update integration test runner

- style: apply dart format across repo
… flags

Add MATOMO_SETUP.md; expand FIREBASE_SETUP.md; update ANALYTICS.md with runtime flags and queue persistence.
…into add/enhanced-analytics-v2

# Conflicts:
#	lib/services/initializer/app_bootstrapper.dart
#	lib/services/logger/universal_logger.dart
#	lib/shared/widgets/coin_type_tag.dart
#	lib/views/fiat/fiat_select_button.dart
#	lib/views/market_maker_bot/coin_selection_and_amount_input.dart
#	lib/views/wallet/wallet_page/common/expandable_coin_list_item.dart
- Standardized analytics events to use walletType instead of hdType
- Updated bridge events to use new BridgeSucceededEventData and BridgeFailedEventData classes
- Added analytics logging for marketbot setup started events
- Merged both walletType and durationMs parameters in bridge events
…ading details\n\n- Add optional duration_ms to bridge_success and bridge_failure payloads\n- Forward durationMs through AnalyticsBridgeSucceeded/FailedEvent wrappers\n- Pass computed durationMs when logging bridge events from trading_details.dart\n- Update required_analytics_events.csv to document duration_ms for bridge events
No functional changes in this commit. This just stages prior local modifications to ensure a clean working tree.
@CharlVS CharlVS marked this pull request as ready for review September 11, 2025 14:56
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Co-authored-by: charl <charl@vanstaden.info>
@CharlVS CharlVS changed the title feat: analytics v2 feat(analytics): Analytics v2 (Firebase+Matomo), queueing, event schema updates Sep 15, 2025
@CharlVS CharlVS force-pushed the add/enhanced-analytics-v2 branch from c73ae06 to 51f31cc Compare September 16, 2025 16:14
@CharlVS CharlVS requested a review from smk762 September 23, 2025 21:00
Copy link
Copy Markdown
Collaborator

@smk762 smk762 left a comment

Choose a reason for hiding this comment

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

Confirmed dashboard detects app, though upon browsing I noticed a few instances of Oops… there was a problem during the request. and very little else - most pages showed "no data" - though there was some. Perhaps it just needs to be populated more?

image image image image

Approving as there is enough data to confirm the linkage, and general smoke test of standard wallet/dex ops function as expected.

If further confirmation testing is required regarding the "no data", please let me know.

@gcharang
Copy link
Copy Markdown
Contributor

gcharang commented Sep 25, 2025

@smk762 there was a permissions issue and I fixed it. please check again, the data should populate

@gcharang
Copy link
Copy Markdown
Contributor

screenshot-analytics

the view_asset, swap_initiated, asset_enabled, swap_success events should mention the actual names of the assets @CharlVS

@CharlVS
Copy link
Copy Markdown
Collaborator Author

CharlVS commented Sep 25, 2025

Thanks, @gcharang I'll have a look. It should be receiving exactly the same data as the other provider.

@CharlVS
Copy link
Copy Markdown
Collaborator Author

CharlVS commented Sep 25, 2025

@cursoragent, check for issues where event parameters are not being included in the events logged by Matomo.

@cursor
Copy link
Copy Markdown

cursor bot commented Sep 25, 2025

I've enhanced the Matomo analytics tracking by modifying how events are labeled, ensuring that event parameters are now captured and displayed as the event's name (label) in Matomo. This provides more detailed and contextual information directly within the analytics interface.

  • I modified the trackEvent method in lib/bloc/analytics/matomo_analytics_api.dart to set the EventInfo.name property using a newly formatted label derived from event parameters, rather than just the event's action.
  • I implemented a new private helper method, _formatEventLabel, within lib/bloc/analytics/matomo_analytics_api.dart. This method takes a map of event parameters and converts them into a sorted, semicolon-separated string (e.g., key1=value1; key2=value2) for use as the event label.

Open in Cursor Open in Web

Learn more about Cursor Agents

@smk762
Copy link
Copy Markdown
Collaborator

smk762 commented Sep 26, 2025

@smk762 there was a permissions issue and I fixed it. please check again, the data should populate

Thanks - confirmed I dont see the error boxes any more. There's still a few places with "no data", but I can see new things too like the events table. Just took a little VPN tour around a few countries, which soon after were visible on the map.

My prior approval remains in effect, otherwise let me know if anything else specific to look for.

…ytics_events.csv

Add explicit event->category map; expand numeric keys; add sync note; prefer metadata source over hardcoding.
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

…ered

- Remove premature swap_success event from maker order confirmation
  - Maker orders only place orders on orderbook; swap happens when matched
  - Actual success/failure logged in trading_details when swap completes

- Remove incorrect swap_failure event from maker order submission errors
  - Order creation failures are not swap failures (swap never started)

- Add swap_failure tracking to taker flow for immediate RPC errors
  - Logs analytics when sell RPC fails before swap UUID is returned

- Add AnalyticsBloc and KomodoDefiSdk dependencies to TakerBloc
  - Required for logging failure events with correct wallet type

All swap analytics events (swap_initiated, swap_success, swap_failure) now:
- Trigger at correct lifecycle stages
- Are idempotent (no duplicates via state flags)
- Capture all success and failure scenarios
- Follow CSV specification requirements
- Add and update analytics events across multiple categories (cross-chain, market bot, NFT, portfolio, rewards, security, transactions, user acquisition)

- Integrate analytics tracking in blocs (bridge, coin addresses, coins manager, custom token import, market maker bot, NFT withdraw, taker)

- Integrate analytics tracking in views (bridge, DEX, settings, wallet)

- Update Matomo analytics API implementation

- Update required analytics events tracking CSV
cursor[bot]

This comment was marked as outdated.

# Conflicts:
#	AGENTS.md
#	lib/views/dex/simple/confirm/maker_order_confirmation.dart
#	lib/views/dex/simple/confirm/taker_order_confirmation.dart
#	lib/views/market_maker_bot/market_maker_bot_confirmation_form.dart
#	lib/views/settings/widgets/security_settings/private_key_settings/private_key_show.dart
@CharlVS CharlVS merged commit 0d03442 into dev Oct 2, 2025
9 of 16 checks passed
@CharlVS CharlVS deleted the add/enhanced-analytics-v2 branch October 2, 2025 11:30
@CharlVS CharlVS mentioned this pull request Oct 5, 2025
@smk762 smk762 mentioned this pull request Nov 23, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA Ready for QA Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants