Log visitors on Github page?
Asked Answered
I

1

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?

Ipswich answered 9/5, 2017 at 22:5 Comment(4)
I think you could easily setup a Google Analytics on a Github Page #17207958Olmsted
@YoannM I am trying to follow this guide 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..Ipswich
Actually, I changed authuser=0 to =1 and can register an account now.Ipswich
Does this answer your question? Finding the number of views of a website hosted on GitHub PagesMerkle
H
2

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));
}
Hebdomadal answered 2/10, 2022 at 21:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.