If you plan to sell ads on the blog or sell the blog itself at a future point of time, you will need to use some company acceptable to them. Google Analytics, Adobe Analytics, ....
If it is just to know more about your visitors, then there are plenty of options.
Piwik (now named as Matomo) is a very popular open-source option. I would argue, it is the most popular one out there. If you run into a problem, you will find support out there.
If you use a CDN like CloudFlare, they provide analytics sometimes, like Cloudflare Web Analytics.
If you use a shared web host, most of them support AWStats or something similar, where you can find out more about your visitors.
If you like tinkering with stuff, use an open source option.
If you want a free option, choose an open source option or go with CDN-provided or host-provided options.
If you want to run with minimal fuss, choose one of the popular options.
If you want to write one yourself, pick one from Github, fork and get going. It is not too difficult. I have written one from scratch once and used to use it on my sites, and it wasn't too difficult.