Skip to content

Commit 0f17ddb

Browse files
authored
fix: debounce analytics search tracking to capture final query (#132)
Signed-off-by: Mohammod Al Amin Ashik <maa.ashik00@gmail.com>
1 parent f645d36 commit 0f17ddb

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Download Stats to PostHog
2+
3+
on:
4+
schedule:
5+
# Run daily at 06:00 UTC
6+
- cron: '0 6 * * *'
7+
workflow_dispatch: # Allow manual trigger
8+
9+
jobs:
10+
report-downloads:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Send download counts to PostHog
14+
env:
15+
POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }}
16+
POSTHOG_HOST: ${{ secrets.VITE_POSTHOG_HOST }}
17+
GH_TOKEN: ${{ github.token }}
18+
run: |
19+
POSTHOG_HOST="${POSTHOG_HOST:-https://us.i.posthog.com}"
20+
21+
# Fetch all releases
22+
releases=$(gh api repos/${{ github.repository }}/releases --paginate)
23+
24+
# Parse and send per-release download counts
25+
echo "$releases" | jq -c '.[]' | while read -r release; do
26+
tag=$(echo "$release" | jq -r '.tag_name')
27+
published=$(echo "$release" | jq -r '.published_at')
28+
29+
# Count real downloads (exclude .sig files and latest.json)
30+
downloads=$(echo "$release" | jq '[.assets[] | select(.name | (endswith(".sig") or . == "latest.json") | not) | .download_count] | add // 0')
31+
32+
# Per-platform counts
33+
windows=$(echo "$release" | jq '[.assets[] | select(.name | test("\\.(msi|exe)$")) | select(.name | endswith(".sig") | not) | .download_count] | add // 0')
34+
macos=$(echo "$release" | jq '[.assets[] | select(.name | endswith(".dmg")) | .download_count] | add // 0')
35+
linux=$(echo "$release" | jq '[.assets[] | select(.name | test("\\.(deb|rpm|AppImage)$")) | .download_count] | add // 0')
36+
37+
# latest.json hits (proxy for active installs checking for updates)
38+
updater_checks=$(echo "$release" | jq '[.assets[] | select(.name == "latest.json") | .download_count] | add // 0')
39+
40+
echo " $tag: $downloads downloads (win=$windows, mac=$macos, linux=$linux, updater=$updater_checks)"
41+
42+
# Send to PostHog
43+
curl -s -o /dev/null "${POSTHOG_HOST}/capture/" \
44+
-H 'Content-Type: application/json' \
45+
-d "{
46+
\"api_key\": \"${POSTHOG_KEY}\",
47+
\"event\": \"release_downloads\",
48+
\"distinct_id\": \"github-release-stats\",
49+
\"properties\": {
50+
\"version\": \"${tag}\",
51+
\"published_at\": \"${published}\",
52+
\"total_downloads\": ${downloads},
53+
\"windows_downloads\": ${windows},
54+
\"macos_downloads\": ${macos},
55+
\"linux_downloads\": ${linux},
56+
\"updater_checks\": ${updater_checks}
57+
}
58+
}"
59+
done
60+
61+
echo "Done reporting download stats to PostHog"

apps/desktop/src/features/registry/RegistryPage.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,20 @@ export function RegistryPage() {
8686
const timer = setTimeout(() => {
8787
if (localSearch !== searchQuery) {
8888
search(localSearch);
89-
if (localSearch.trim()) {
90-
capture('registry_search', { query: localSearch.trim() });
91-
}
9289
}
9390
}, 300);
9491
return () => clearTimeout(timer);
9592
}, [localSearch, searchQuery, search]);
9693

94+
// Track search analytics with longer debounce to capture final query only
95+
useEffect(() => {
96+
if (!localSearch.trim()) return;
97+
const timer = setTimeout(() => {
98+
capture('registry_search', { query: localSearch.trim() });
99+
}, 1500);
100+
return () => clearTimeout(timer);
101+
}, [localSearch]);
102+
97103
const handleInstall = async (id: string) => {
98104
const server = servers.find(s => s.id === id);
99105
const serverName = server?.name || 'Server';

0 commit comments

Comments
 (0)