feat: CLI analytics via Umami event collector#572
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7c6d31b29
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| def _analytics_disabled() -> bool: | ||
| """True when analytics should not fire.""" | ||
| value = os.getenv("BASIC_MEMORY_NO_PROMOS", "").strip().lower() | ||
| return value in {"1", "true", "yes"} |
There was a problem hiding this comment.
Honor CLI promo opt-out before sending analytics
track() only checks _analytics_disabled() (the BASIC_MEMORY_NO_PROMOS env var), so it ignores the persisted opt-out set by bm cloud promo --off (cloud_promo_opt_out in core_commands.promo). In that state, later commands (for example bm cloud login) still emit analytics events, which contradicts the module’s stated “same opt-out mechanisms as promo messaging” behavior and leaks telemetry after an explicit opt-out. Add a config-based opt-out check (or reuse promo gating logic) before dispatching events.
Useful? React with 👍 / 👎.
Add lightweight, non-blocking analytics to track the CLI-to-cloud conversion funnel: - cli-promo-shown: promo panel displayed (first run or version bump) - cli-promo-opted-out: user ran `bm cloud promo --off` - cli-cloud-login-started: user initiated `bm cloud login` - cli-cloud-login-success: login + subscription verified - cli-cloud-login-sub-required: login hit subscription wall Implementation: - New analytics.py module using stdlib only (urllib + threading) - Fire-and-forget daemon threads, 3s timeout, silent on failure - Respects BASIC_MEMORY_NO_PROMOS env var (same opt-out as promos) - Configured via BASIC_MEMORY_UMAMI_HOST and BASIC_MEMORY_UMAMI_SITE_ID - No-op when env vars are unset (zero impact on existing installs) - UTM-tagged learn-more URL for web attribution No new dependencies. Analytics never blocks or breaks the CLI. Signed-off-by: phernandez <paul@basicmachines.co>
193b4cb to
da560cf
Compare
What
Lightweight, non-blocking analytics for the CLI-to-cloud conversion funnel. Tracks promo impressions, opt-outs, and cloud login attempts/successes via Umami's event collector API.
Events Tracked
cli-promo-showncli-promo-opted-outbm cloud promo --offcli-cloud-login-startedbm cloud logincli-cloud-login-successcli-cloud-login-sub-requiredAlso
utm_source=bm-cli&utm_medium=promo&utm_campaign=cloud-upsell) for web attribution in UmamiDesign
urllib.request+threading)BASIC_MEMORY_NO_PROMOSenv varBASIC_MEMORY_UMAMI_HOSTandBASIC_MEMORY_UMAMI_SITE_IDenv vars to activate. Existing installs see zero change.Umami Setup Instructions
After merging, you need to configure Umami to receive these events:
1. Get your Umami website ID
2. Set environment variables
Wherever the
bmCLI runs (or in your deployment/build config):For testing locally: set these in your shell before running
bm statusetc.For production/distribution: these would go in the release build config or be baked into a future config file. Users without these vars set get zero analytics (the module is a complete no-op).
3. Create custom events dashboard in Umami
cli-promo-shown(top of funnel)cli-cloud-login-started(intent)cli-cloud-login-success(conversion)cli-promo-showncli-cloud-login-startedcli-cloud-login-success4. UTM attribution
The learn-more URL now points to:
Check Insights → UTM in Umami to see CLI-sourced web traffic.
5. Verify it works
Tests
32 tests pass including new analytics tests covering: