Skip to content

"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/

Python

feat(analytics): flatten cli-install/uninstall events, add cli-launch, merge live Umami+PostHog

yuhao4a2e21e3f7bc
diff --git a/cli-hub/cli_hub/__init__.py b/cli-hub/cli_hub/__init__.py
index f9ad4ed0e..00aa4cb6a 100644
--- a/cli-hub/cli_hub/__init__.py
+++ b/cli-hub/cli_hub/__init__.py
@@ -1,3 +1,3 @@
"""cli-hub — Download, manage, and browse CLI-Anything harnesses."""
-__version__ = "0.2.2"
+__version__ = "0.2.3"
diff --git a/cli-hub/cli_hub/analytics.py b/cli-hub/cli_hub/analytics.py
index 6cd1afd33..a5632d364 100644
--- a/cli-hub/cli_hub/analytics.py
+++ b/cli-hub/cli_hub/analytics.py
@@ -282,8 +282,9 @@ def track_event(event_name, url="/cli-anything-hub", data=None):
def track_install(cli_name, version):
- """Track a CLI install event — event name includes the CLI for dashboard visibility."""
- track_event(f"cli-install:{cli_name}", url=f"/cli-anything-hub/install/{cli_name}", data={
+ """Track a CLI install event. CLI name goes in properties, not the event name,
+ so the event catalog stays flat and dashboards can break down by properties.cli."""
+ track_event("cli-install", url=f"/cli-anything-hub/install/{cli_name}", data={
"cli": cli_name,
"version": version,
"platform": platform.system().lower(),
@@ -292,8 +293,18 @@ def track_install(cli_name, version):
def track_uninstall(cli_name):
"""Track a CLI uninstall event."""
- track_event(f"cli-uninstall:{cli_name}", url=f"/cli-anything-hub/uninstall/{cli_name}", data={
+ track_event("cli-uninstall", url=f"/cli-anything-hub/uninstall/{cli_name}", data={
"cli": cli_name,
+ "platform": platform.system().lower(),
+ })
+
+
+def track_launch(cli_name):
+ """Track a CLI launch event — fires when a user runs `cli-hub launch <name>`.
+ Distinct from install: this is actual usage signal."""
+ track_event("cli-launch", url=f"/cli-anything-hub/launch/{cli_name}", data={
+ "cli": cli_name,
+ "platform": platform.system().lower(),
})
diff --git a/cli-hub/cli_hub/cli.py b/cli-hub/cli_hub/cli.py
index e97ebf13a..de922f073 100644
--- a/cli-hub/cli_hub/cli.py
+++ b/cli-hub/cli_hub/cli.py
@@ -9,7 +9,14 @@ import click
from cli_hub import __version__
from cli_hub.registry import fetch_all_clis, get_cli, search_clis, list_categories
from cli_hub.installer import install_cli, uninstall_cli, get_installed, update_cli
-from cli_hub.analytics import detect_invocation_context, track_install, track_uninstall, track_visit, track_first_run
+from cli_hub.analytics import (
+ detect_invocation_context,
+ track_first_run,
+ track_install,
+ track_launch,
+ track_uninstall,
+ track_visit,
+)
def _invocation_command(ctx, version):
@@ -239,6 +246,7 @@ def launch(name, args):
)
raise SystemExit(1)
+ track_launch(name)
os.execvp(entry, [entry] + list(args))
diff --git a/cli-hub/setup.py b/cli-hub/setup.py
index eda0b779d..af145e033 100644
--- a/cli-hub/setup.py
+++ b/cli-hub/setup.py
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup(
name="cli-anything-hub",
- version="0.2.2",
+ version="0.2.3",
description="Package manager for CLI-Anything — browse, install, and manage 40+ agent-native CLI interfaces for GUI applications",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
diff --git a/cli-hub/tests/test_cli_hub.py b/cli-hub/tests/test_cli_hub.py
index d40be2c37..22f87c1f0 100644
--- a/cli-hub/tests/test_cli_hub.py
+++ b/cli-hub/tests/test_cli_hub.py
@@ -534,32 +534,47 @@ class TestAnalytics:
assert payload["payload"]["hostname"] == "clianything.cc"
@patch("cli_hub.analytics._send_event")
- def test_track_install_event_name_includes_cli(self, mock_send):
- """cli-install event name must include CLI name for dashboard visibility."""
+ def test_track_install_event_name_is_flat(self, mock_send):
+ """cli-install event name is static; CLI name lives in properties.cli."""
with patch.dict(os.environ, {}, clear=True):
track_install("gimp", "1.0.0")
import time
time.sleep(0.2)
mock_send.assert_called_once()
payload = mock_send.call_args[0][0]
- assert payload["event"] == "cli-install:gimp"
+ assert payload["event"] == "cli-install"
assert payload["properties"]["$current_url"] == "https://clianything.cc/cli-anything-hub/install/gimp"
assert payload["properties"]["cli"] == "gimp"
assert payload["properties"]["version"] == "1.0.0"
assert "platform" in payload["properties"]
@patch("cli_hub.analytics._send_event")
- def test_track_uninstall_event_name_includes_cli(self, mock_send):
- """cli-uninstall event name must include CLI name for dashboard visibility."""
+ def test_track_uninstall_event_name_is_flat(self, mock_send):
+ """cli-uninstall event name is static; CLI name lives in properties.cli."""
with patch.dict(os.environ, {}, clear=True):
analytics_track_uninstall("blender")
import time
time.sleep(0.2)
mock_send.assert_called_once()
payload = mock_send.call_args[0][0]
- assert payload["event"] == "cli-uninstall:blender"
+ assert payload["event"] == "cli-uninstall"
assert payload["properties"]["$current_url"] == "https://clianything.cc/cli-anything-hub/uninstall/blender"
assert payload["properties"]["cli"] == "blender"
+ assert "platform" in payload["properties"]
+
+ @patch("cli_hub.analytics._send_event")
+ def test_track_launch_fires(self, mock_send):
+ """cli-launch event fires with the CLI name in properties."""
+ from cli_hub.analytics import track_launch
+ with patch.dict(os.environ, {}, clear=True):
+ track_launch("gimp")
+ import time
+ time.sleep(0.2)
+ mock_send.assert_called_once()
+ payload = mock_send.call_args[0][0]
+ assert payload["event"] == "cli-launch"
+ assert payload["properties"]["cli"] == "gimp"
+ assert payload["properties"]["$current_url"] == "https://clianything.cc/cli-anything-hub/launch/gimp"
@patch("cli_hub.analytics._send_event")
def test_track_visit_human(self, mock_send):
diff --git a/docs/hub/index-modern.html b/docs/hub/index-modern.html
index 704ff3778..408e24452 100644
--- a/docs/hub/index-modern.html
+++ b/docs/hub/index-modern.html
@@ -2909,23 +2909,34 @@
document.addEventListener(evt, onHumanInteraction, { once: false, passive: true });
});
- // ── Live analytics (PostHog HogQL via Cloudflare Worker proxy) ──
- // PostHog key lives in a Cloudflare Worker secret (repo:
- // ~/clianything-analytics-worker). The worker allow-lists this exact
- // HogQL shape and forwards to us.posthog.com.
+ // ── Live analytics via Cloudflare Worker proxy ──
+ // PostHog key and Umami key live as Worker secrets (repo:
+ // ~/clianything-analytics-worker). Both sources are queried every
+ // refresh and summed, so pre-migration Umami events and post-migration
+ // PostHog events stay counted forever.
const ANALYTICS_PROXY_URL = 'https://analytics.clianything.cc/';
- const MIGRATION_STARTED_AT = '2026-04-23T09:06:38Z';
+ const UMAMI_SITE_IDS = [
+ '07082d05-efd3-4f85-a7a1-b426b0e8bfaa', // hkuds.github.io
+ 'a076c661-bed1-405c-a522-813794e688b4', // clianything.cc
+ ];
const LIVE_STATS_REFRESH_MS = 60_000;
+ const ZERO_STATS = {
+ human: 0, agent: 0,
+ cli_hub_human: 0, cli_hub_agent: 0,
+ cli_install: 0, cli_uninstall: 0, cli_launch: 0,
+ };
- async function fetchPosthogIncrement() {
+ async function fetchPosthogTotals() {
const hogql = (
"select " +
"countIf(event = 'visit-human' and properties.source = 'web' and properties.site = 'clianything.cc') as human, " +
"countIf(event = 'visit-agent' and properties.source = 'web' and properties.site = 'clianything.cc') as agent, " +
"countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = false) as cli_hub_human, " +
- "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = true) as cli_hub_agent " +
- "from events " +
- "where timestamp >= parseDateTimeBestEffort('" + MIGRATION_STARTED_AT + "')"
+ "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = true) as cli_hub_agent, " +
+ "countIf((event = 'cli-install' or like(event, 'cli-install:%')) and properties.source = 'cli') as cli_install, " +
+ "countIf((event = 'cli-uninstall' or like(event, 'cli-uninstall:%')) and properties.source = 'cli') as cli_uninstall, " +
+ "countIf(event = 'cli-launch' and properties.source = 'cli') as cli_launch " +
+ "from events"
);
const response = await fetch(ANALYTICS_PROXY_URL, {
method: 'POST',
@@ -2934,40 +2945,66 @@
});
if (!response.ok) throw new Error('posthog query http ' + response.status);
const data = await response.json();
- const row = (data.results && data.results[0]) || [0, 0, 0, 0];
- const human = Number(row[0]) || 0;
- const agent = Number(row[1]) || 0;
- const cliHuman = Number(row[2]) || 0;
- const cliAgent = Number(row[3]) || 0;
+ const row = (data.results && data.results[0]) || [0, 0, 0, 0, 0, 0, 0];
return {
- total: human + agent,
- human,
- agent,
- cli_hub_total: cliHuman + cliAgent,
- cli_hub_human: cliHuman,
- cli_hub_agent: cliAgent,
+ human: Number(row[0]) || 0,
+ agent: Number(row[1]) || 0,
+ cli_hub_human: Number(row[2]) || 0,
+ cli_hub_agent: Number(row[3]) || 0,
+ cli_install: Number(row[4]) || 0,
+ cli_uninstall: Number(row[5]) || 0,
+ cli_launch: Number(row[6]) || 0,
};
}
- function mergeStats(baseline, increment) {
+ async function fetchUmamiTotals() {
+ const totals = { ...ZERO_STATS };
+ const responses = await Promise.all(UMAMI_SITE_IDS.map((site) =>
+ fetch(ANALYTICS_PROXY_URL + 'umami/events?site=' + encodeURIComponent(site))
+ .then((r) => r.ok ? r.json() : [])
+ .catch(() => [])
+ ));
+ for (const rows of responses) {
+ if (!Array.isArray(rows)) continue;
+ for (const row of rows) {
+ const name = row && row.x;
+ const count = Number(row && row.y) || 0;
+ if (!name || !count) continue;
+ if (name === 'visit-human') totals.human += count;
+ else if (name === 'visit-agent') totals.agent += count;
+ else if (name === 'cli-install' || (typeof name === 'string' && name.startsWith('cli-install:'))) totals.cli_install += count;
+ else if (name === 'cli-uninstall' || (typeof name === 'string' && name.startsWith('cli-uninstall:'))) totals.cli_uninstall += count;
+ }
+ }
+ return totals;
+ }
+
+ function sumStats(a, b) {
+ const out = {};
+ for (const key of Object.keys(ZERO_STATS)) out[key] = (a[key] || 0) + (b[key] || 0);
+ return out;
+ }
+
+ function withDerivedTotals(s) {
+ // cli_hub_total bundles all cli-hub-sourced events so the footer's
+ // "cli-hub" number reflects end-to-end activity, not just raw
+ // invocations. The human/agent split stays tied to cli-hub call
+ // only, because Umami install/uninstall events don't carry is_agent.
return {
- total: baseline.total + increment.total,
- human: baseline.human + increment.human,
- agent: baseline.agent + increment.agent,
- cli_hub_total: baseline.cli_hub_total + increment.cli_hub_total,
- cli_hub_human: baseline.cli_hub_human + increment.cli_hub_human,
- cli_hub_agent: baseline.cli_hub_agent + increment.cli_hub_agent,
+ ...s,
+ total: s.human + s.agent,
+ cli_hub_total: s.cli_hub_human + s.cli_hub_agent + s.cli_install + s.cli_uninstall + s.cli_launch,
};
}
async function refreshVisitorStats() {
- try {
- const increment = await fetchPosthogIncrement();
- applyVisitorStats(mergeStats(BASELINE_STATS, increment));
- return true;
- } catch (_) {
- return false;
- }
+ const [posthog, umami] = await Promise.allSettled([fetchPosthogTotals(), fetchUmamiTotals()]);
+ const ph = posthog.status === 'fulfilled' ? posthog.value : null;
+ const um = umami.status === 'fulfilled' ? umami.value : null;
+ if (!ph && !um) return false;
+ const merged = sumStats(ph || ZERO_STATS, um || ZERO_STATS);
+ applyVisitorStats(withDerivedTotals(merged));
+ return true;
}
async function loadVisitorStats() {
diff --git a/docs/hub/index.html b/docs/hub/index.html
index 9d687feea..1ec1fee1d 100644
--- a/docs/hub/index.html
+++ b/docs/hub/index.html
@@ -3123,25 +3123,35 @@
document.addEventListener(evt, onHumanInteraction, { once: false, passive: true });
});
- // ── Live analytics (PostHog HogQL via Cloudflare Worker proxy) ──
- // The PostHog personal API key lives in a Cloudflare Worker secret
- // (repo: ~/clianything-analytics-worker). The worker allow-lists this
- // exact HogQL shape and forwards to us.posthog.com. The baseline
- // BASELINE_STATS is the Umami total at migration cutover; live PostHog
- // counts since then are added on top.
+ // ── Live analytics via Cloudflare Worker proxy ──
+ // PostHog personal key and Umami API key live as Worker secrets
+ // (repo: ~/clianything-analytics-worker). Both sources are queried
+ // every refresh and summed, so pre-migration Umami events and
+ // post-migration PostHog events both stay counted forever.
+ // BASELINE_STATS is a last-resort fallback when both live fetches fail.
const ANALYTICS_PROXY_URL = 'https://analytics.clianything.cc/';
- const MIGRATION_STARTED_AT = '2026-04-23T09:06:38Z';
+ const UMAMI_SITE_IDS = [
+ '07082d05-efd3-4f85-a7a1-b426b0e8bfaa', // hkuds.github.io
+ 'a076c661-bed1-405c-a522-813794e688b4', // clianything.cc
+ ];
const LIVE_STATS_REFRESH_MS = 60_000;
+ const ZERO_STATS = {
+ human: 0, agent: 0,
+ cli_hub_human: 0, cli_hub_agent: 0,
+ cli_install: 0, cli_uninstall: 0, cli_launch: 0,
+ };
- async function fetchPosthogIncrement() {
+ async function fetchPosthogTotals() {
const hogql = (
"select " +
"countIf(event = 'visit-human' and properties.source = 'web' and properties.site = 'clianything.cc') as human, " +
"countIf(event = 'visit-agent' and properties.source = 'web' and properties.site = 'clianything.cc') as agent, " +
"countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = false) as cli_hub_human, " +
- "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = true) as cli_hub_agent " +
- "from events " +
- "where timestamp >= parseDateTimeBestEffort('" + MIGRATION_STARTED_AT + "')"
+ "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = true) as cli_hub_agent, " +
+ "countIf((event = 'cli-install' or like(event, 'cli-install:%')) and properties.source = 'cli') as cli_install, " +
+ "countIf((event = 'cli-uninstall' or like(event, 'cli-uninstall:%')) and properties.source = 'cli') as cli_uninstall, " +
+ "countIf(event = 'cli-launch' and properties.source = 'cli') as cli_launch " +
+ "from events"
);
const response = await fetch(ANALYTICS_PROXY_URL, {
method: 'POST',
@@ -3150,40 +3160,69 @@
});
if (!response.ok) throw new Error('posthog query http ' + response.status);
const data = await response.json();
- const row = (data.results && data.results[0]) || [0, 0, 0, 0];
- const human = Number(row[0]) || 0;
- const agent = Number(row[1]) || 0;
- const cliHuman = Number(row[2]) || 0;
- const cliAgent = Number(row[3]) || 0;
+ const row = (data.results && data.results[0]) || [0, 0, 0, 0, 0, 0, 0];
return {
- total: human + agent,
- human,
- agent,
- cli_hub_total: cliHuman + cliAgent,
- cli_hub_human: cliHuman,
- cli_hub_agent: cliAgent,
+ human: Number(row[0]) || 0,
+ agent: Number(row[1]) || 0,
+ cli_hub_human: Number(row[2]) || 0,
+ cli_hub_agent: Number(row[3]) || 0,
+ cli_install: Number(row[4]) || 0,
+ cli_uninstall: Number(row[5]) || 0,
+ cli_launch: Number(row[6]) || 0,
};
}
- function mergeStats(baseline, increment) {
+ async function fetchUmamiTotals() {
+ // Umami events/series returns [{x: eventName, t: timestamp, y: count}, ...].
+ // Pre-migration we only emitted visit-human, visit-agent, and
+ // cli-install:{name} / cli-uninstall:{name} — no cli-hub call, no cli-launch.
+ const totals = { ...ZERO_STATS };
+ const responses = await Promise.all(UMAMI_SITE_IDS.map((site) =>
+ fetch(ANALYTICS_PROXY_URL + 'umami/events?site=' + encodeURIComponent(site))
+ .then((r) => r.ok ? r.json() : [])
+ .catch(() => [])
+ ));
+ for (const rows of responses) {
+ if (!Array.isArray(rows)) continue;
+ for (const row of rows) {
+ const name = row && row.x;
+ const count = Number(row && row.y) || 0;
+ if (!name || !count) continue;
+ if (name === 'visit-human') totals.human += count;
+ else if (name === 'visit-agent') totals.agent += count;
+ else if (name === 'cli-install' || (typeof name === 'string' && name.startsWith('cli-install:'))) totals.cli_install += count;
+ else if (name === 'cli-uninstall' || (typeof name === 'string' && name.startsWith('cli-uninstall:'))) totals.cli_uninstall += count;
+ }
+ }
+ return totals;
+ }
+
+ function sumStats(a, b) {
+ const out = {};
+ for (const key of Object.keys(ZERO_STATS)) out[key] = (a[key] || 0) + (b[key] || 0);
+ return out;
+ }
+
+ function withDerivedTotals(s) {
+ // cli_hub_total bundles all cli-hub-sourced events so the footer's
+ // "cli-hub" number reflects end-to-end activity, not just raw
+ // invocations. The human/agent split stays tied to cli-hub call
+ // only, because Umami install/uninstall events don't carry is_agent.
return {
- total: baseline.total + increment.total,
- human: baseline.human + increment.human,
- agent: baseline.agent + increment.agent,
- cli_hub_total: baseline.cli_hub_total + increment.cli_hub_total,
- cli_hub_human: baseline.cli_hub_human + increment.cli_hub_human,
- cli_hub_agent: baseline.cli_hub_agent + increment.cli_hub_agent,
+ ...s,
+ total: s.human + s.agent,
+ cli_hub_total: s.cli_hub_human + s.cli_hub_agent + s.cli_install + s.cli_uninstall + s.cli_launch,
};
}
async function refreshVisitorStats() {
- try {
- const increment = await fetchPosthogIncrement();
- applyVisitorStats(mergeStats(BASELINE_STATS, increment));
- return true;
- } catch (_) {
- return false;
- }
+ const [posthog, umami] = await Promise.allSettled([fetchPosthogTotals(), fetchUmamiTotals()]);
+ const ph = posthog.status === 'fulfilled' ? posthog.value : null;
+ const um = umami.status === 'fulfilled' ? umami.value : null;
+ if (!ph && !um) return false;
+ const merged = sumStats(ph || ZERO_STATS, um || ZERO_STATS);
+ applyVisitorStats(withDerivedTotals(merged));
+ return true;
}
async function loadVisitorStats() {