10

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?

Kevin Bedell
  • 13,254
  • 10
  • 78
  • 114
user1021085
  • 729
  • 3
  • 10
  • 28
  • 3
    I think you could easily setup a Google Analytics on a Github Page http://stackoverflow.com/questions/17207458/how-to-add-google-analytics-tracking-id-to-github-pages – Yoann May 09 '17 at 22:08
  • @YoannM I am trying to follow this guide https://github.com/rainlab/googleanalytics-plugin but it's telling me to "In a new tab, navigate to the main Google Analytics site and select the property you want to track.", when I click the link for Google Analytics the page is just grey/blank. So I don't know how to proceed.. – user1021085 May 09 '17 at 22:32
  • Actually, I changed authuser=0 to =1 and can register an account now. – user1021085 May 09 '17 at 22:34
  • 1
    Does this answer your question? [Finding the number of views of a website hosted on GitHub Pages](https://stackoverflow.com/questions/50773333/finding-the-number-of-views-of-a-website-hosted-on-github-pages) – Franck Dernoncourt Aug 18 '22 at 20:16

1 Answers1

1

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));
}