如何使用多个应用程序设置分析系统?(How to setup a analytics system using multiple apps?)

编程入门 行业动态 更新时间:2024-10-26 06:30:16
如何使用多个应用程序设置分析系统?(How to setup a analytics system using multiple apps?)

我有一个在Rails 4 + Postgres上运行的前端应用程序。 我们称之为FRONT_APP 。 我有一个运行Rails 4 + Mongodb的统计应用程序。 我们称之为STATISTICS_APP 。

在我的FRONT_APP ,我使用此代码的骨架XHR查询:

$.ajax({ url: "http://localhost:3000/hits", type: "POST", crossDomain: true, data: { user_data: "Value", token: "TokenString"} })

我正在向STATISTICS_APP发送POST请求并创建具有适当数据的Hit实例。 通过这种方式,我将在Mongodb上收集数百万行数据。

在STATISTICS_APP的工作人员中,我将评估所有数据并直接连接到我的生产Postgres数据库,我将更新各自的表。

因此,我将通过我的Postgres数据库显示统计信息。

你觉得这是一个方便的工作方式吗?

或者你有更好的工作流程?

谢谢

I have a front-end application runs on Rails 4 + Postgres. Let's call it FRONT_APP. I have an application for statistics run Rails 4 + Mongodb. Let's call it STATISTICS_APP.

In my FRONT_APP, I use this skeleton XHR query with this code:

$.ajax({ url: "http://localhost:3000/hits", type: "POST", crossDomain: true, data: { user_data: "Value", token: "TokenString"} })

I'm sending a POST request to STATISTICS_APP and creating a Hit instance which has proper data. By this way I will collect millions of rows data at my Mongodb.

And in a worker of my STATISTICS_APP, I will evaluate all data and with a direct connection to my production Postgres db, I will update respective tables.

As a result, I will show statistics information via my Postgres db.

Do you think that it's a convenient way to do this job?

Or do you have a better workflow?

Thank you

最满意答案

您所指的是标准analytics内容 - 向另一个系统发送请求,该系统在分析服务器上发起请求(因此将请求记录为hit或类似)


虽然你的结构是正确的(将请求异步发送到另一个应用程序),但我仍然不会使用ajax - 更好的方法是从其他服务器请求资源(通常是像Google分析这样的1px gif ):

跟踪代码的工作原理

通常,Google Analytics跟踪代码(GATC)会检索网页数据,如下所示:

浏览器请求包含跟踪代码的网页。 创建名为_gaq的JavaScript数组,并将跟踪命令推送到阵列上。 创建一个元素并启用异步加载(在后台加载)。 获取ga.js跟踪代码,并自动检测适当的协议。 获取并加载代码后,将执行_gaq数组上的命令,并将数组转换为跟踪对象。 后续跟踪调用将直接发送给Google Analytics。 将脚本元素加载到DOM。 跟踪代码收集数据后,GIF请求将发送到Analytics数据库以进行日志记录和后处理。


我们已经做了类似的事情,但由于我们的应用程序仍在开发中,我们实际上仍在使用xmlhttprequest (伪装成ajax ):

//v0.0.230 //authenticates with server (function(token) { var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST","http://*******.herokuapp.com/data",true); xmlhttp.setRequestHeader("Authorization", "Token " + token); xmlhttp.send(); })(tracker);

数据

在存储数据方面,我们实际上在Redis中捕获所有裸数据,然后在Postgres(heroku)中存储

我们没有长期开发,但至于数据保留,你一定要考虑存储“短期”数据和“长期”数据

希望这能给出一些方向吗?

What you're referring to is standard analytics stuff - send a request to another system, which initiates a request on the analytics server (hence recording the request as a hit or similar)


Although your structure is correct (send requests asynchronously to the other app), I would stay clear of ajax -- a better way will be to request a resource from the other server (typically a 1px gif like Google analytics):

How the Tracking Code Works

In general, the Google Analytics Tracking Code (GATC) retrieves web page data as follows:

A browser requests a web page that contains the tracking code. A JavaScript Array named _gaq is created and tracking commands are pushed onto the array. A element is created and enabled for asynchronous loading (loading in the background). The ga.js tracking code is fetched, with the appropriate protocol automatically detected. Once the code is fetched and loaded, the commands on the _gaq array are executed and the array is transformed into a tracking object. Subsequent tracking calls are made directly to Google Analytics. Loads the script element to the DOM. After the tracking code collects data, the GIF request is sent to the Analytics database for logging and post-processing.


We've done something similar, but since our app is in development still, we're actually still using an xmlhttprequest (ajax in disguise):

//v0.0.230 //authenticates with server (function(token) { var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST","http://*******.herokuapp.com/data",true); xmlhttp.setRequestHeader("Authorization", "Token " + token); xmlhttp.send(); })(tracker);

Data

In terms of storing data, we actually capture all naked data in Redis & then store in Postgres (heroku) afterwards

We've not developed for long with it, but as for data retention, you should definitely look at storing "short term" data & "long term" data

Hope this gives some direction?

更多推荐

本文发布于:2023-07-25 19:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1265157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何使用   应用程序   系统   setup

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!