How to extract analytics information like Google Analytics?
I'm building my own URL shortener service for myself. I'd like to add an admin page which displays some basic analytics information like how Google Analytics displays page views, unique visitors, geographical region, social media referral, etc. I know Google Analytics works by using cookies and pushing each page view to their servers, but I don't think I need to do that in order to get some good information.
What type of analytics information can I extract from a basic HTTP request?
I'm using Ruby, but the answer will probably be applicable to multiple languages.
If you're using Google Analytics, you can use the measurement protocol to send data directly to the GA back-end from any environment where you can make an HTTP request (eg server or client).
When an end user makes a request to one of your short links, you can extract information like the user agent string (if it's from a browser) and the IP address (which gives you geographic location information) and if there are cookies present, you can set the clientId or userId to track unique visits. If you send that info to GA it will automatically process it for you (like, you don't need to determine geo yourself) and allow you to run all the usual reports. (Some things won't apply, like time on site or pages per session, but that should be obvious.)
In terms of building an admin dashboard, you can use the Embed API to do all your reporting. The Embed API handles auth for you and has a pretty easy-to-use API for displaying GA data.
If you aren't using Google Analytics, you can do all the same stuff; you'd just have to process all that data yourself, ie parse the user agent string, translate the IP address to geo data, etc.
链接地址: http://www.djcxy.com/p/31184.html上一篇: Google Analytics事件跟踪