I have a lil site on github pages and I was wondering if there was a way to see when people(I think 1-3) visit the page? It's not enough for the traffic tab on github stats to show anything and since it's on github pages I can't write to file or database.
Any way at all? Use javascript to send tweets on an account made for logging visitor(s), writing to database even though people say that's a bad idea.. Just any way at all?
Maybe this would help. I use this to count visitors on my personal portfolio which is hosted on GitHub pages and it's pretty much effective.
const KEY = `YOUR_KEY`;
const NAMESPACE = "YOURDOMAIN.COM";
const COUNT_URL = `https://api.countapi.xyz`;
const counter = document.getElementById("visit-count");
const getCount = async () => {
const response = await fetch(`${COUNT_URL}/get/${NAMESPACE}/${KEY}`);
const data = await response.json();
setValue(data.value);
};
const incrementCount = async () => {
const response = await fetch(`${COUNT_URL}/hit/${NAMESPACE}/${KEY}`);
const data = await response.json();
setValue(data.value);
};
const setValue = (num) => {
counter.innerText = `Total Unique Visitor: ${num}`;
};
if (localStorage.getItem("hasVisited") == null) {
incrementCount()
.then(() => {
localStorage.setItem("hasVisited", "true");
})
.catch((err) => console.log(err));
} else {
getCount()
.catch((err) => console.log(err));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With