2

I need to get the number of unique visitors(say, for the last 5 minutes) that are currently looking at an article, so I can display that number, and sort the articles by most popular.

ex. Similar to how most forums display 'There are n people viewing this thread'

How can I achieve this on Google App Engine? I am using Python 2.7.

Please try to explain in a simple way because I recently started learning programming and I am working on my first project. I don't have lots of experience. Thank you!

lambo
  • 21
  • 2

3 Answers3

1

Create a counter (property within entity) and increase it transactionally for every page view. If you have more then a few pageviews a second you need to look into sharded counters.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks. But I don't want to increase the counter every time someone requests the page. I need to know the number of _unique visitors_ and the number should decrease when someone leaves the page.GAE gives you information about your visitors when you manage your application in admin panel. I was wondering if it's possible to use those logs from my application. – lambo Apr 18 '12 at 21:45
1

There is no way to tell when someone stops viewing a page unless you use Javascript to inform the server when that happens. Forums etc typically assume that someone has stopped viewing a page after n minutes of inactivity, and base their figures on that.

For minimal resource use, I would suggest using memcache exclusively here. If the value gets evicted, the count will be incorrect, but the consequences of that are minimal, and other solutions will use a lot more resources.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
0

Did you consider Google Analytics service for getting statistics? Read this article about real-time monitoring using this service. Please note: a special script must be embedded on every page you want to monitor.

Vladimir Obrizan
  • 2,538
  • 2
  • 18
  • 36