33a1fa7cae
The goatcounter PV report splits numbers with spaces, e.g. 1024 would be '1 024'
19 lines
577 B
HTML
19 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>
|