Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

counting unique visitors with flask

Tags:

flask

I would like to count the number of unique visitors and store that number in my database. I know that I can get the ip address with

request.remote_addr

so my default plan would be to store this address with a timestamp in my database. For any new visitor I would than compare whether this ip address has already been added with a timestamp less than 1 day old. This would give me the number of visitors per day.

However, I have the feeling this is a problem where others probably came up with better solutions already? Any suggestion how to do this better?

p.s. I just need a rough estimate for the number of unique visits, so the fact that ip addresses are not a good measure is not that concerning to me... but if you have better suggestions I am definitely interested

like image 691
carl Avatar asked Jun 16 '16 22:06

carl


1 Answers

To get a faster more reliable solution, simply offload this functionality to another service like Google Analytics. They provide a very detailed/in-depth view of the traffic on your website without you having to worry about the intricate details.

Regardless, if you're dead set on using flask, take a look at this wonderful blog post explaining how to build an analytics app in Flask. Here is the complete source code of that app.

like image 54
oxalorg Avatar answered Oct 16 '22 12:10

oxalorg