VickiLanger / OpenGates

Reference checklist of things to avoid gatekeeping in posts, articles, videos, talks, presentations, podcasts, and in any other content.
https://OpenGates.dev/
MIT License
4 stars 9 forks source link

[FEATURE] Add visitor counter to footer #26

Open VickiLanger opened 2 years ago

VickiLanger commented 2 years ago

It would be cool if we had a visitor counter at the bottom. I'm imagining a '90s-esque counter

VickiLanger commented 2 years ago

We could use something like this, but isn't local storage just local to a browser? Would this count across everyone or just be a count of how many times an individual browser had visited the site?

var counterContainer = document.querySelector(".website-counter"); // get the div
var visitCount = localStorage.getItem("page_view"); // get views from localStorage

if (visitCount) { // if page_view does exist
  visitCount = Number(visitCount) + 1; 
  localStorage.setItem("page_view", visitCount); //update localStorage
} else {  //if page_view doesn't exists, create it
  visitCount = 1;
  localStorage.setItem("page_view", 1); //Add entry for key="page_view"
}
counterContainer.innerHTML = "Views: " + visitCount; // set the page counter
/* Styles for website counter container */
.website-counter {
  font-family: var(--text-font);
  background-color: var(--heading-color);
  height: 50px;
  width: 280px;
  color: var(--dark-color);
  border-radius: 0.3rem;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: .075rem;
}
VickiLanger commented 2 years ago

Used a prebuilt one to start with. I'd still prefer to build one just for OpenGates. Long term, I'd rather not rely on someone else's code.