Skip to content

Commit fe0bb1b

Browse files
mpclaude
andcommitted
feat: Add GoatCounter analytics and GitHub traffic persistence
- GoatCounter tracking in public/index.html - Daily GitHub Actions workflow to persist repo traffic data Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0465789 commit fe0bb1b

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/traffic.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Persist GitHub Traffic Data
2+
3+
on:
4+
schedule:
5+
- cron: '0 1 * * *' # Täglich um 01:00 UTC
6+
workflow_dispatch: # Manuell auslösbar
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
traffic:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Fetch and persist traffic data
18+
env:
19+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
run: |
21+
DATE=$(date -u +%Y-%m-%d)
22+
REPO="${{ github.repository }}"
23+
24+
mkdir -p .github/traffic
25+
26+
# Traffic-Daten abrufen
27+
VIEWS=$(gh api "repos/$REPO/traffic/views" 2>/dev/null || echo '{"count":0,"uniques":0,"views":[]}')
28+
CLONES=$(gh api "repos/$REPO/traffic/clones" 2>/dev/null || echo '{"count":0,"uniques":0,"clones":[]}')
29+
REFERRERS=$(gh api "repos/$REPO/traffic/popular/referrers" 2>/dev/null || echo '[]')
30+
PATHS=$(gh api "repos/$REPO/traffic/popular/paths" 2>/dev/null || echo '[]')
31+
32+
# Tages-Snapshot als JSONL (eine Zeile pro Tag, einfach appendbar)
33+
SNAPSHOT=$(jq -n \
34+
--arg date "$DATE" \
35+
--argjson views "$VIEWS" \
36+
--argjson clones "$CLONES" \
37+
--argjson referrers "$REFERRERS" \
38+
--argjson paths "$PATHS" \
39+
'{date: $date, views: $views, clones: $clones, referrers: $referrers, paths: $paths}')
40+
41+
# Duplikat-Check (nicht doppelt speichern wenn am selben Tag nochmal läuft)
42+
if grep -q "\"date\":\"$DATE\"" .github/traffic/traffic.jsonl 2>/dev/null; then
43+
echo "Data for $DATE already exists, skipping."
44+
else
45+
echo "$SNAPSHOT" >> .github/traffic/traffic.jsonl
46+
echo "Added traffic data for $DATE"
47+
fi
48+
49+
- name: Commit if changed
50+
run: |
51+
git config user.name "github-actions[bot]"
52+
git config user.email "github-actions[bot]@users.noreply.github.com"
53+
git add .github/traffic/
54+
git diff --cached --quiet || git commit -m "chore: update traffic data ($(date -u +%Y-%m-%d))"
55+
git push

public/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,7 @@
8181
</noscript>
8282
<div id="app"></div>
8383
<!-- built files will be auto injected -->
84+
<script data-goatcounter="https://peuqui.goatcounter.com/count"
85+
async src="//gc.zgo.at/count.js"></script>
8486
</body>
8587
</html>

0 commit comments

Comments
 (0)