pages/_includes/pageviews/goatcounter.html
Florian Weber 79e87b8af2
Some checks failed
Deploy Jekyll site to Pages / build (push) Failing after 7m43s
trying chirpy theme
2024-11-14 14:44:22 +01:00

20 lines
577 B
HTML

<!-- Display GoatCounter pageviews -->
<script>
let pv = document.getElementById('pageviews');
if (pv !== null) {
const uri = location.pathname.replace(/\/$/, '');
const url = `https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/${encodeURIComponent(uri)}.json`;
fetch(url)
.then((response) => response.json())
.then((data) => {
const count = data.count.replace(/\s/g, '');
pv.innerText = new Intl.NumberFormat().format(count);
})
.catch((error) => {
pv.innerText = '1';
});
}
</script>