Skip to content

Commit 7d2012a

Browse files
phernandezclaude
andcommitted
fix(cli): fix Umami analytics event delivery
Three issues prevented CLI analytics from reaching the Umami dashboard: 1. Wrong API endpoint — cloud.umami.is rejects /api/send, the JS tracker uses api-gateway.umami.dev 2. Missing "type": "event" top-level field required by Umami v2 API 3. Non-browser User-Agent ("basic-memory-cli/...") triggers Umami's bot detection, which silently drops events with {"beep":"boop"} 🤖 4. Daemon thread was killed before HTTP request completed on fast commands Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 7f2d4d2 commit 7d2012a

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/basic_memory/cli/analytics.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Configuration — defaults baked in, overridable via environment
2626
# ---------------------------------------------------------------------------
2727

28-
_DEFAULT_UMAMI_HOST = "https://cloud.umami.is"
28+
_DEFAULT_UMAMI_HOST = "https://api-gateway.umami.dev"
2929
_DEFAULT_UMAMI_SITE_ID = "f6479898-ebaf-4e60-bce2-6dc60a3f6c5c"
3030

3131

@@ -76,7 +76,9 @@ def track(event_name: str, data: Optional[dict] = None) -> None:
7676
host = _umami_host()
7777
site_id = _umami_site_id()
7878

79+
# Umami v2 /api/send requires "type" at top level alongside "payload"
7980
payload = {
81+
"type": "event",
8082
"payload": {
8183
"hostname": "cli.basicmemory.com",
8284
"language": "en",
@@ -87,7 +89,7 @@ def track(event_name: str, data: Optional[dict] = None) -> None:
8789
"version": basic_memory.__version__,
8890
**(data or {}),
8991
},
90-
}
92+
},
9193
}
9294

9395
def _send():
@@ -97,11 +99,16 @@ def _send():
9799
data=json.dumps(payload).encode("utf-8"),
98100
headers={
99101
"Content-Type": "application/json",
100-
"User-Agent": f"basic-memory-cli/{basic_memory.__version__}",
102+
# Umami's bot detection rejects non-browser User-Agents
103+
"User-Agent": "Mozilla/5.0 (compatible; BasicMemoryCLI/"
104+
f"{basic_memory.__version__})",
101105
},
102106
)
103107
urllib.request.urlopen(req, timeout=3)
104108
except Exception:
105109
pass # Never break the CLI for analytics
106110

107-
threading.Thread(target=_send, daemon=True).start()
111+
# Non-daemon so the process waits for the request to complete.
112+
# The 3s urllib timeout caps the worst-case exit delay.
113+
t = threading.Thread(target=_send)
114+
t.start()

0 commit comments

Comments
 (0)