counting unique visitors with flask

情到浓时终转凉″ 提交于 2021-01-21 07:58:13

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/37870361/counting-unique-visitors-with-flask

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!