Implementing Unique Visitor Count on website or webApp.

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.

For tracking the unique user, we can use cookies for the most accurate measure.

Algorithm :

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. 

  1.  Check the cookies with the tracking id.
  2.  if it is present then visiting user is not the unique one and set uniqueVisitor to false.
  3. if uniqueVisitor is True then countOfVisitor++
  4. create the cookies with max age limit and tracking id and set it in the response.
  5. 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.

Code Example:

  1.  Implementation of above algorithm in java web app.

unique site visit logic implementation in Filter of java dynamic web app

2. Loading and saving the value of counter

initializing and storing the count of visitors at startup and destroy of web app

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. 😀 🙂 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.