J
J
jazzus2020-06-04 15:59:53
Web development
jazzus, 2020-06-04 15:59:53

How to count unique users?

It is necessary to keep a record of unique visitors of certain entities for a period.

Visitors can be registered users and guests.

I think to do so.
Table
id
ip
user_id
visitable_id
visitable_type
dates

When visiting, we check whether it is authorized or not.
If authorized:
Check if there is such a user in the table of visits for the specified entity
. If so, return false.
If not, we write the user id to communicate with the user, increment the unique_views of the entity.

If it is not authorized, we check the ip address of the visitor of the specified entity
. If it exists, we return false
. If not, we write to the database and increment the unique_views of the entity.

Cron cleans data older than one month.

Errors such as a possible identical ip address for users are not significant.

As a result, you need to show a table of visitors for all articles / other user entities, where related visitor data will be displayed. Perform data queries, filtering, sorting, etc.

Share the experience of who did this, is this logic correct, etc.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sanes, 2020-06-04
@Sanes

Why such difficulties, if a small error is permissible? Set cookies or something like that.

I
Ivan Shumov, 2020-06-04
@inoise

Connect Yandex Metrica and learn how to use it. business

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question