Server side analytics
I wanted to keep trace of visitors and know the usual stuff of web analytics: visitors, source, nationality, behaviour and so on.
And client side analytics are not so reliable:
- Ad Blockers interfere with them
- Using a third party service require to annoy the user with those huge cookie consent banners
- They drastically increase the loading time of the web application
- They don't register API calls and any other not-html calls like web api
So i developed by myself a very simple server side analytics system for AspNet Core, which is running is also here my website.
SSA is an AspNet Core middleware that inserted in to the task pipeline of the application will be invoked every time a new request is recieved.
Here you can find a Live Demo of the system.
If you find a bug or you got an idea on to improve the system, please contribute to the GitHub Repository
How to use
To insert the middleware into the task pipeline import the NuGet package and invoke the extension method UserServerSideAnalytics in your application Startup:
This method requires an IAnalyticStore interface that is gonna be the place where our recieved request will be stored.
Implementing your own store is quite simple but if you're lazy you can use one of mine:
- ServerSideAnalytics.Mongo : to store requests in Mongo DB
- ServerSideAnalytics.SqLite : to store requests in SqLite
- ServerSideAnalytics.SqlServer : to store requests in SqlServer
By default SSA record every request coming to the server, which can produce a lot of bloat data.
You can configure SSA to exclude some request or to limit is recording to specific sets of requests by using fluid extension methods during the assigment in application Startup.
One of the most interesting data of every analytic system is to know where your user come from.
This can be a quite annoying operation due to difficulties of find a reliable an cheap database of countires and their relative ip address ranges.
For this reason i wrote other three analytic stores that acts as wrappers around an existing one to provide fallback geo-IP resolution.
If the first repository doesn't contains a valid IP range ffor the client It will ask to the second one and so on.
If at the end the chain a valid geo-IP has been found this i saved into the main store.
I wrote three of them, if you want to add more, please contribute on GitHub.
You can find those analytic store in ServerSideAnalytics.Extensions
- IpApiAnalyticStore : add ip-geocoding using Ip Api (ip-api.com)
- IpInfoAnalyticStore : add ip-geocoding using Ip Stack (ipinfo.io)
- IpStackAnalyticStore : add ip-geocoding using Ip Stack (ipstack.com)