PS: Since I have upgraded my website and hosted on GitHub, I have changed the platform from Java to simple HTML. It’s no longer dynamic on my current site.
One fine day, I thought of capturing the unique visitor count and displaying on website/ web app (www.vdharam.com). How is it possible to achieve in the best possible way? Then I found out that there are various third-party options are available to achieve the same but I don’t like the idea of depending on other services. So, the next question that popped up in my mind that how could I achieve this.
Let’s see how to do this.
boolean uniqueVisitor: true
long Integer countOfVisitor: This should be loaded at the time of application startup from database/property file so that it can be persisted.
- Check the cookies with the tracking id.
- if it is present then visiting user is not the unique one and set uniqueVisitor to false.
- if uniqueVisitor is True then countOfVisitor++
- create the cookies with max age limit and tracking id and set it in the response.
- Display the countOfVisitor on the page.
When the application destroyed/undeployed from the server, the value of countOfVisitor, save it in database/properties file again.
The above Algorithm is pretty simple.
- Implementation of above algorithm in java web app.
2. Loading and saving the value of counter
Though this implementation is in Java, similar can be done in any technology stack.
Feel free to contact me or suggest an appropriate change in this post. I am not the perfect guy.