14
14
description : ' Custom commit message (optional)'
15
15
required : false
16
16
type : string
17
+ push : # Trigger on push to any branch
18
+ branches : ['**']
17
19
18
20
jobs :
19
21
update-badge :
@@ -33,24 +35,28 @@ jobs:
33
35
- name : Fetch Plausible Analytics Data
34
36
id : analytics
35
37
run : |
36
- # Fetch pageviews from Plausible API
38
+ # Fetch both pageviews and unique visitors from Plausible API
37
39
response=$(curl -s -X POST https://plausible.io/api/v2/query \
38
40
-H "Authorization: Bearer ${{ secrets.PLAUSIBLE_API_KEY }}" \
39
41
-H "Content-Type: application/json" \
40
42
-d '{
41
43
"site_id": "openwashdata.org",
42
- "metrics": ["pageviews"],
44
+ "metrics": ["pageviews", "visitors" ],
43
45
"date_range": "all"
44
46
}')
45
47
46
- # Extract pageview count
48
+ # Extract pageview and visitor counts
47
49
pageviews=$(echo $response | jq -r '.results[0].pageviews // 0')
50
+ visitors=$(echo $response | jq -r '.results[0].visitors // 0')
48
51
49
- # Format number with commas for readability
52
+ # Format numbers with commas for readability
50
53
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')
51
55
52
56
echo "pageviews=$pageviews" >> $GITHUB_OUTPUT
53
57
echo "formatted_pageviews=$formatted_pageviews" >> $GITHUB_OUTPUT
58
+ echo "visitors=$visitors" >> $GITHUB_OUTPUT
59
+ echo "formatted_visitors=$formatted_visitors" >> $GITHUB_OUTPUT
54
60
55
61
- name : Create Badge Data
56
62
run : |
@@ -74,13 +80,13 @@ jobs:
74
80
run : |
75
81
git config --local user.email "[email protected] "
76
82
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
78
84
79
85
# Use custom commit message if provided, otherwise use default
80
86
if [ -n "${{ github.event.inputs.custom_message }}" ]; then
81
87
commit_msg="${{ github.event.inputs.custom_message }}"
82
88
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 "
84
90
fi
85
91
86
92
# Force commit if requested, otherwise only commit if changes exist
0 commit comments