3

In Django, how can I see the number of current visitors? Or how do I determine the number of active sessions?

Is this a good method?

use django.contrib.sessions.models.Session, set the expiry time short. Every time when somebody does something on the site, update expiry time. Then count the number of sessions that are not expired.

Jack Ha
  • 19,661
  • 11
  • 37
  • 41

4 Answers4

7

You might want to look into something like django-tracking for this.

django-tracking is a simple attempt at keeping track of visitors to Django-powered Web sites. It also offers basic blacklisting capabilities.

Edit: As for your updated question... [Answer redacted after being corrected by muhuk]

Alternatively, I liked the response to this question: How do I find out total number of sessions created i.e. number of logged in users?

You might want to try that instead.

Community
  • 1
  • 1
bchang
  • 1,402
  • 8
  • 19
  • 2
    No, Django doesn't store session as cookies, it stores session id's in cookies. And session expiration is stored in session storage. Therefore you can count. – muhuk Jun 16 '09 at 19:22
  • Thanks. django-tracking seems to work! (except the part with the fancy map) It looks like an interesting package – Jack Ha Jun 16 '09 at 20:24
3

django-tracking2 can be helpful to track the visitors.

As specially this is easy to configure in the deployment like AWS, because it is not required any dependency and environment variables.

django-tracking2 tracks the length of time visitors and registered users spend on your site. Although this will work for websites, this is more applicable to web applications with registered users. This does not replace (nor intend) to replace client-side analytics which is great for understanding aggregate flow of page views.

Niraj Chapla
  • 2,149
  • 1
  • 21
  • 34
  • the stats for django-tracking 2 won't appear ont he dashboard for me. Idk what it is. Do you have any clue? – Fabio Jul 04 '16 at 19:43
0

There is also a little application django-visits to track visits https://bitbucket.org/jespino/django-visits

sultan
  • 5,978
  • 14
  • 59
  • 103
-2

Edit: Added some more information about why I present this answer here. I found chartbeat when I tried to answer this same question for my django based site. I don't work for them.

Not specifically Django, but chartbeat.com is very interesting to add to a website as well.

django-tracking is great, +1 for that answer, etc.

Couple of things I could not do with django-tracking, that chartbeat helped with; tracked interactions with completely cached pages which never hit the django tracking code and pages not delivered through django (e.g. wordpress, etc.)

dar
  • 6,520
  • 7
  • 33
  • 44