I think I finally found a nice easy analytics that works for static web sites, is free to use, and is privacy friendly not requiring GDPR warnings.
I've always struggled to even setup G Analytics. I've always given up not able to make it work. I also hated that it used cookies and had to deal with getting user consent. I just don't want to worry about that. I've looked for a way to get basic usage details of my website. What pages are being visited what browsers and on what size screens. Basic things that that. I don't even care about who the people are and frankly I would love to respect their privacy. Those basics are useful for knowing how best to design and update the site, what content people like to generate more of. Things like that. I do not need a unique identifier.
Goatcounter
I found goatcounter.com Give it a read. It is Open Source has a Live Demo is light weight (<4KB) and claims to respect privacy and not require a GDPR notice:
Privacy-aware; doesn’t track users with unique identifiers and doesn't need a GDPR notice. Fine-grained control over which data is collected. Also see the privacy policy and GDPR consent notices.
It also claims only a single line of Javascript is required:
<script data-goatcounter="https://MYCODE.goatcounter.com/count"
async src="//gc.zgo.at/count.js"></script>
So I decided to give it a try and set it up.
Setting it up
Getting a code
On the main page I clicked "Sign Up". I filled in the fields requested. For code I just typed in what I wanted as a code and for domain I entered the domain without the https://. I did use a valid email and it sent a verification link. Though, I set up my site before I noticed and clicked verify. If you are using something like github pages try entering your site url without the protocol maybe? I am unclear if this works.
Be sure to write down your code and save the login url for your dashboard. If you forget your code, you can find it again under "help" in your dashboard. But it is also in the url you use to login.
Any SSG
These are some generic instructions.
Integrations: Wordpress, Gatsby, Schlix, Write.as
Under the HELP page in your dashboard, there is a link called "Endpoint."
https://MYCODE.goatcounter.com/count
You will use this link and click on the button below it corresponding to your tool to see the sample code to add a plugin.
Obsidian Webpage Html Export
This discusses setup in the Obsidian Plugin WebPage Html Export Plugin for Obsidian .
I created a new file inside my repo (VAULT)/privatestuff/goatcounter.txt to contain the and copied the generated script into that file. Note it is a .txt files not an .md file. Contents:
<script data-goatcounter="https://MYCODE.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
Since it is a .txt file it does not show up in Obsidian at all and hence won't export. But I am sure to not check the privatestuff folder on export since I do not want to show that folder on the website.
Export Dev
Then I went into Settings > Webpage Html Export > Page Features > Custom Head Content and browsed to find the file. Then, I generated my dev site (export mode: HTML Documents to a local folder site_dev) and opened the index.html in a text editor and searched for "goat" and it found it.
Export Prod
So I again exported my prod version (Export Mode: Online Web Site and exported to my prod folder site_prod). I pushed up my changes up to my repo using git. git add...; git commmit...; git push...
For advanced users only: Render.com allows for preview enviroments. Once enabled in your settings, you just push up a new branch and create a merge request but do not merge it. It will auto deploy a preview site at a different URL. As long as the merge request is open I can push changes up to my branch and it redeploys. It claims charges are based on the standard charges. Which as I read it is free for static sites. When I visited this preview environment I could see a user show up in the counter. Very cool.
Check my Stats
First I log into goatcounter.com and visit the dashboard link provided when I signed up (https://MYCODE.goatcounter.com/). No visitors as expected. Then I open my site in the browser and refhresh the dashboard page and vioala I have 1 visit. If you aren;t seeing visitors check your ad-blocker and look at the After-Setup Documentation
Page Counter
If you want to display the number of users who have visited on your site see Page Counter . Though, I do not see a way to include that in this plugin.
What Else
- Wait and Watch the Dashboard (https://MYCODE.goatcounter.com/)
- Check out the FAQ
- There is a Page Counter available if you want to display the number of visitors on your website. You need a way to inject this into your static side in the
<body>> I do not see a way on Webpage Html Export but likely available for potehr SSGs. - If you can't use javascript, there is a 1x1 pixel image Tracking Pixel option available but it doesn't capture referrer or screen size.
- Read how unique visitors are estimated via session fingerprints without collecting private details.
- Setup MFA under your account profile.
- Consider a contribution
Conclusion
I really like this. I get basic website usage details without a complex setup and no privacy issues or consent to worry about. It was really simple to add in the headers and get started. If you are looking for similar it's work a try.