我需要开发一个内部实时分析解决方案(例如类似于 GA 或 mixpanel)来收集:
- 来自网站本身的信息 (URL)
- 来自用户浏览器的信息(语言、设备、操作系统等)
- 来自引用来源等的信息。
.. 并通过单像素图像请求将此数据发送到服务器。与 GA 和其他解决方案的工作方式类似:
Google Analytics works by the inclusion of a block of JavaScript code on pages in your website. When users to your website view a page, this JavaScript code references a JavaScript file which then executes the tracking operation for Analytics. The tracking operation retrieves data about the page request through various means and sends this information to the Analytics server via a list of parameters attached to a single-pixel image request.
我想知道是否有任何可用的开源项目可以完成这部分工作,我可以将其用作进一步构建的基础。有 Piwik
但它的功能太丰富而且对我的要求来说太重了。
编辑添加:我正在对数据做一些特定的事情,否则我只会使用现有的解决方案。
最佳答案
试试
var img = new Image;
img.width = img.height = "1px";
var res = window.navigator;
var data = {};
var _plugins = {};
Array.prototype.slice.call(navigator.plugins).forEach(function(v, k) {
_plugins[v.name.toLowerCase().replace(/\s/, "-")] = {
"name": v.name,
"description": v.description,
"filename": v.filename
}
});
delete res.plugins && delete res.mimeTypes;
data.url = window.location.href;
data.ref = document.referrer;
data.nav = res;
data._plugins = _plugins;
// set `img` `dataset` with `data` ,
// send `img` to server , decode `img` `dataset` at server
img.dataset.stats = JSON.stringify(data);
var img = new Image;
img.width = img.height = "1px";
var res = window.navigator;
var data = {};
var _plugins = {};
Array.prototype.slice.call(navigator.plugins).forEach(function(v, k) {
_plugins[v.name.toLowerCase().replace(/\s/, "-")] = {
"name": v.name,
"description": v.description,
"filename": v.filename
}
});
delete res.plugins && delete res.mimeTypes;
data.url = window.location.href;
data.ref = document.referrer;
data.nav = res;
data._plugins = _plugins;
img.dataset.stats = JSON.stringify(data);
document.write(
img.dataset.stats
);
关于javascript - 使用 Javascript 进行实时基本 Web 分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27581199/