How do I get the number of active users on my django website?

537 Views Asked by At

I want to display the number of active visitors on my website, I tried using django-tracking, django-active-users but none of them worked because they are outdated. I am using Django 3.0.8 and all of those modules aren't supported with django3.

I also tried doing this with Google analytics but their real-time reporting API is in limited beta and not open to everyone. Is there any way I can get this to work using Django active sessions or something?

1

There are 1 best solutions below

0
Leo Uchiha On

Create a DailyCount model which has date(DateField), active_users(PositiveIntegerField).

Then use celery periodic tasks with a function that is triggered at hour=0, minute=0, i.e., every day.

Create a DailyCount instance in the triggered function.


Whenever a user visits the site for the first time that day, increase DailyCount.active_users by 1.