javascript - 使用 Javascript 进行实时基本 Web 分析

标签 javascript google-analytics analytics

我需要开发一个内部实时分析解决方案(例如类似于 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/

相关文章:

javascript - gulp-image 出现 ENOENT 错误

Firebase 控制台 : Using screen_view as event for audience possible?

javascript - 如何跟踪一个 Facebook 广告在不同页面上的多次转化?

javascript - 跟踪页面访问作为别名

google-analytics - 谷歌分析测量协议(protocol)批量发送不起作用

javascript - 谷歌分析是否有设置禁止未经同意的用户使用 cookie

javascript - 角色层次映射器/生成器(递归)

JavaScript 正则表达式 : How to pluck certain matches out of string?

javascript - 如何开发phonegap SQLite数据库

android - 每次更改 Google 标签管理器标签时,我们是否需要在 Android 端更新容器 json 文件