Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log visitors on Github page?

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?

like image 734
user1021085 Avatar asked May 03 '26 23:05

user1021085


1 Answers

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));
}
like image 161
Hm Elius Hossain Himel Avatar answered May 05 '26 13:05

Hm Elius Hossain Himel