How to count unique visitors on webpage

Viewed 5959

I want to know how to count unique visitors on webpage with Javascript (ReactJS + NodeJS(Express) i mean when user loads page it should send user's data to validate and if it is unique add it to database. there are this options (what i figured out)

  1. Use client's IP address as validator.

  2. Set Cookie

first one is not good because many device can share same network and many visitors will be lost.

Second one is not good option because cookie can be manipulated & deleted (if it is httpOnly then only deleted)

So what is best way to count visitors? my aim is to make something like . this

2 Answers

You can add a field in your database schema in which you can update it by adding 1 or something similar when a user visits a page. If you want to go further you can then store the user IP in the database or use cookies to avoid counting page visits for the same person multiple times.

You can use e.g. Google Analytics and their core reporting API. After you included GA in your site, the query explorer will get you started.

Related