I always thought of logging page hits as complimentary to
By adding a SessionId cookie which expires when the browsing session ends and
ASP.NET Core SignalR
for monitoring active connections (online users), I have gotten closer to a Google Analytics alternative.
This series will explore some of the issues and considerations for collecting and analyzing usage metrics.
This project is designed and organized to allow easy integration with existing projects. I have been tweaking
the project as I integrate it with my live sites and real-world data. The
KenHaggerty. Com. SingleUser
NuGet package segregates the user logic. I have developed SQL scripts to create the schema, tables,
and default data which are included in the download package.
from Microsoft. AspNetCore. CookiePolicy to request user consent for
cookie which expires when the browsing session ends as essential. Because of the confusion and
interpretations of the GDPR and other privacy laws, my code includes an option to set the SessionId
cookie's essential state. See
The 2020 Guide to Google Analytics and GDPR Compliance
Analytic Data Collection
I capture whether the user is authenticated and the request's method, path, query string, and user agent.
I capture the HttpContext. Connection. RemoteIpAddress but I make it anonymous by blanking the Host ID
(the last segment) with zero. See
How-To Geek - How Do IP Addresses Work?
I developed a middleware service to store the data with a PageHit entity. I display
the PageHits on a page which filters on properties. By adding a Session entity, I can capture the first or landing
page the user browses on my site.
Not Found Errors
I used to send myself an email every time the Error page was requested. See
ASP.NET Core 2.2 - Error and Exception Handling
After getting too many emails for not found errors generated by probing robots, I developed a
NotFoundError entity and log rather than emailing not found errors.
I have upgraded the PageHit entity's UserAgent property from a string to an int. The UserAgentId
relates to a child UserAgent entity with a Preferred property. Rather than trying to detect robot page hits,
I can filter on Preferred UserAgents. I developed a UserAgents page which displays the UserAgent's PageHits
count and provides the functions to add or remove the preferred status.
I developed a Dashboard to display Session and PageHit properties with frequency counts filtered by 1, 3, 7,
or 30 previous days. The Dashboard implements links to the Sessions and PageHits pages with the filter for the
related property applied. The Dashboard includes links to the default PageHits, Sessions, NotFoundErrors,
and UserAgents pages.
I use Google Analytics' Active Users feature mainly to detect if any users are online before I take the site offline for
updates. I implemented and deployed an online user feature based on a couple of examples I found which count
online users with SignalR. I have been analyzing and comparing the feature with Google's Active Users. The project
has an option to enable SignalR and the online user feature. The option is disabled by default.
Before I implemented Google reCAPTCHA v3 on the contact and register pages, I was getting emails and
users created by robots. Since, I haven't noticed any. You must register your site to receive an API key and secret.
You set the secret, key, and a pass/fail threshold in appsettings.json. reCAPTCHA v3 returns a score (1.0 is very
likely a good interaction, 0.0 is very likely a bot). The project has an option to enable Google reCAPTCHA.
The option is disabled by default.
Online log maintenance like purging old records are usually long running tasks. Hangfire is better than
Background tasks with hosted services for fire and forget tasks. Hangfire is easy to implement. The Hangfire
dashboard provides detailed status on running, completed, and failed jobs. The project has an option to
enable Hangfire. The option is disabled by default.