Project source code can be found here
I’ve been a user of GitHub Pages for a long time. It’s a really great service. You get a free website, with perfect uptime, and you’re even able to use a custom domain. It’s perfect for developers who want to have their own personal space of the Internet. There is a downside though. Because you’re not able to get root access to the web server (that’s unrealistic), you’re not able to implement a load of features that you may want to.
One such feature you will lack is the ability to log visitor traffic. Want to see if recruiters are coming to your website? Want to see if your friends who said they’d visit actually do? You won’t be able to. Or maybe……...maybe you can.
I wrote FireTraffic as a means of tracking when people visit my website. Admittedly it may be the smallest amount of code I’ve ever written to a GitHub repo, but there is a lot of power to it and you can configure it however you like. Setup is very simple, and will be explained below.
Go to Firebase.com. Firebase is an awesome set of tools that you can use in your projects. It provides a variety of features including authentication, a non-relational database, and more. Once you’ve created an account (It’s a Google subsidiary so a Google account will do), click the “Add Firebase to your web app” button. This will show you a couple bits of information including your api key, database URL, project ID, and more. If you are configuring FireTraffic for your website you are going to want to copy all of this information and paste it into the firebase.js file.
Your next task is counter intuitive, dangerous, and should not be done in ANY other projects. I will explain why we do this in the final section. Go to your “Database” tab and go to your DB rules. In here set the “.write” parameter to equal (==) null. Again, I will explain why later.
After your Firebase is all setup you need to configure your website. This is very easy, simply paste the following HTML near the beginning of each page you want to track.
FireTraffic works by having the client (the user's browser) contact our Firebase database every time they visit the website. Through this, we can see when people are browsing every page. Information will be stored in Firebase based on the pathname of the page, so for example, you will see the date, time, ip, city, and country of every visitor who visited your home page. The majority of information uses the API for ip-api.com.
The other concern is that you need to be willing to get dossed at a moments notice. That was why I told you you have to allow write access by anyone. Because anyone on the internet can come to your website, and you’re trying to log everybody coming in, theoretically if a massive group of people started trolling your site, you’d get a massive influx of data. That’s probably the greatest downside.
That being said, I think the rewards greatly outweigh the negatives. With this installed on your website you can monitor the traffic without traditional services such as Google Analytics!