简体   繁体   English

使用Python Bottle框架进行分析

[英]Analytics with Python bottle framework

I know how to log IP for each request with bottle : 我知道如何使用bottle记录每个请求的IP:

from bottle import Bottle, request

@app.route('/index')
def index():
    client_ip = request.environ.get('REMOTE_ADDR')

What else is possible, with bottle (no google analytics), to get more details about user visits? 使用bottle (没有Google Analytics(分析))还有什么可能获得有关用户访问的更多详细信息? (eg user agent, recurrent or new visitor => useful to count the number of unique visitors per month) (例如,用户代理,常客或新访客=>可用于计算每月的唯一身份访问者人数)

What is "knowable" about a web request is precisely what is sent on the request: all the HTTP headers and the request body. 关于Web请求的“已知”正是在请求上发送的:所有HTTP标头和请求正文。

It isn't useful to talk about the body without specifics, so let's turn to the headers. 谈论没有细节的正文是没有用的,因此让我们来看一下标题。 They will generally include the user agent, the referrer, the user's IP address (technically not an HTTP header but you can think of it as one for this purpose). 它们通常包括用户代理,引荐来源网址,用户的IP地址(技术上不是HTTP标头,但您可以将其视为一个目的)。

A good place to start would be to look at the fields available in the Combined Log Format: 一个好的开始是查看“组合日志格式”中可用的字段:

http://publib.boulder.ibm.com/tividd/td/ITWSA/ITWSA_info45/en_US/HTML/guide/c-logs.html#combined http://publib.boulder.ibm.com/tividd/td/ITWSA/ITWSA_info45/zh_CN/HTML/guide/c-logs.html#combined

host rfc931 username date:time request statuscode bytes referrer user_agent cookie 主机rfc931用户名日期:时间请求状态码字节引荐来源网址user_agent cookie

Note that HTTP headers are in the complete control of your visitors, so treat their values with due suspicion. 请注意,HTTP标头完全由访问者控制,因此请谨慎对待其标头。 That said, most users do not manipulate their headers and let the browser send "reasonable" values, so most sites to indeed perform analytics on the header values. 也就是说,大多数用户不操纵其标头,而是让浏览器发送“合理的”值,因此大多数站点确实对标头值执行分析。 But YMMV depending on your particular use. 但是YMMV取决于您的特定用途。

To estimate how many visitors return to your site, there are several techniques of varying sophistication, but a place to start is to cookie each visitor with a unique ID, then (using using your analytics software) count how many times each unique cookie visited. 要估算有多少访问者返回您的站点,有几种技巧可以改变,但是首先要为每个访问者添加唯一ID,然后(使用您的分析软件)计算每个唯一Cookie的访问次数。 (Note that this has implications if you have a privacy policy.) (请注意,如果您有隐私政策,这将产生影响。)

BTW your question isn't specific to Bottle; 顺便说一句,您的问题并非只针对Bottle; this is true of any web framework. 任何Web框架都是如此。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM