All Projects → vesparny → Fair Analytics

vesparny / Fair Analytics

Licence: mit
📊 An analytics server that doesn't undermine user's privacy

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Fair Analytics

Diztl
Share, discover & download files in your network 💥
Stars: ✭ 162 (-78.54%)
Mutual labels:  p2p, distributed
field-manual
The Offical User's Guide to OrbitDB
Stars: ✭ 178 (-76.42%)
Mutual labels:  p2p, distributed
Arewedistributedyet
Website + Community effort to unlock the peer-to-peer web at arewedistributedyet.com ⚡🌐🔑
Stars: ✭ 189 (-74.97%)
Mutual labels:  p2p, distributed
Orbit
A distributed, serverless, peer-to-peer chat application on IPFS
Stars: ✭ 1,586 (+110.07%)
Mutual labels:  p2p, distributed
Js Ipfs
IPFS implementation in JavaScript
Stars: ✭ 6,129 (+711.79%)
Mutual labels:  p2p, distributed
Crdts
A library of Conflict-Free Replicated Data Types for JavaScript
Stars: ✭ 143 (-81.06%)
Mutual labels:  p2p, distributed
tensorpeers
p2p peer-to-peer training of tensorflow models
Stars: ✭ 57 (-92.45%)
Mutual labels:  p2p, distributed
Cachep2p
"More users = More capacity"
Stars: ✭ 855 (+13.25%)
Mutual labels:  p2p, distributed
Awesome Decentralized
🕶 Awesome list of distributed, decentralized, p2p apps and tools 👍
Stars: ✭ 358 (-52.58%)
Mutual labels:  p2p, distributed
Qtox
qTox is a chat, voice, video, and file transfer IM client using the encrypted peer-to-peer Tox protocol.
Stars: ✭ 3,843 (+409.01%)
Mutual labels:  p2p, distributed
Dat Keyserver
a distributed PGP keyserver project based on the dat protocol
Stars: ✭ 89 (-88.21%)
Mutual labels:  p2p, distributed
Cabal Desktop
Desktop client for Cabal, the p2p/decentralized/local-first chat platform.
Stars: ✭ 632 (-16.29%)
Mutual labels:  p2p, distributed
Clutter
Fully distributed twitter built on holochain
Stars: ✭ 84 (-88.87%)
Mutual labels:  p2p, distributed
Gym Fx
Forex trading simulator environment for OpenAI Gym, observations contain the order status, performance and timeseries loaded from a CSV file containing rates and indicators. Work In Progress
Stars: ✭ 151 (-80%)
Mutual labels:  p2p, distributed
Js Dag Service
Library for storing and replicating hash-linked data over the IPFS network.
Stars: ✭ 81 (-89.27%)
Mutual labels:  p2p, distributed
Eventql
Distributed "massively parallel" SQL query engine
Stars: ✭ 1,121 (+48.48%)
Mutual labels:  analytics, distributed
Distribyted
📂 ➡️ 📺 🎶 🎮 Torrent client with on-demand file downloading as a filesystem.
Stars: ✭ 791 (+4.77%)
Mutual labels:  p2p, distributed
Crate
CrateDB is a distributed SQL database that makes it simple to store and analyze massive amounts of data in real-time.
Stars: ✭ 3,254 (+330.99%)
Mutual labels:  analytics, distributed
Hashview
A web front-end for password cracking and analytics
Stars: ✭ 601 (-20.4%)
Mutual labels:  analytics, distributed
Orbit Db
Peer-to-Peer Databases for the Decentralized Web
Stars: ✭ 6,381 (+745.17%)
Mutual labels:  p2p, distributed

Fair Analytics

An analytics server that doesn't undermine user's privacy

Travis Code Coverage David npm npm JavaScript Style Guide MIT License

Motivations?

Google Analytics is the de-facto standard in the web and mobile analytics service world.

  • It's easy to setup and start tracking users behaviors
  • It provides advanced reporting features.

But it has several serious privacy implications:

  • Most of the time personal data is collected without the explicit consent of the user, hence it undermines user's privacy
  • It's closed-source
  • It does not embrace transparency at all
  • Users cannot access tracked data because data ownership is granted only to the website/app owner (and sadly to Google)
  • It targets specific users and data collected is not anonymous

Inspired by an interesting article from @staltz, and from the awesome work done by the micro-analytics team, I decided to start working on a Google Analytics alternative.

What is Fair Analytics

Fair Analytics is an open, transparent, distributed and fair Google Analytics alternative.

Key features

  • Fair - It's meant to provide lightweight and anonymous analytics about traffic and usage, not to track behaviors nor geographical locations of users
  • Distributed - Raw traffic data is written in an append-only, secure, and distributed log. It uses hypercore under the hood
  • Transparent - Raw traffic data is accessible to anyone. This makes it auditable and gives back its ownership to the crowd
  • Easy - It's easy to setup
  • Flexible - Even though Fair Analytics only stores raw data, it's pretty easy to listen to incoming events, enabling the user to manipulate/aggregate raw data in order to provide graphs or charts. Get fancy if you want to.

Setup

There are 2 ways of running Fair Analytics

CLI

npm install -g fair-analytics

fair-analytics

The command accepts some options:

$ fair-analytics --help

  Usage: fair-analytics [options] [command]

  Commands:

    help  Display help

  Options:

    -h, --help                       Output usage information
    -H, --host [value]               Host to listen on (defaults to "0.0.0.0")
    -m, --memory                     Use in-memory storage (disabled by default)
    -o, --origin [value]             Accepts POST requests only from a specified origin (defaults to "*")
    -p, --port <n>                   Port to listen on (defaults to 3000)
    -s, --storage-directory [value]  Storage directory (defaults to process.cwd())
    -v, --version                    Output the version number

The instance is now running at http://localhost:3000

Programmatically

Add fair-analytics as a dependency to your project

const path = require('path')
const fa = require('fair-analytics')

const server = fa({
  storageDirectory: path.resolve(__dirname)
})
const { feed } = server

feed.on('ready', () => {
  server.listen(3000, '0.0.0.0')
})

The instance is now running at http://localhost:3000

Deploy

TODO

  • nginx
  • docker

Usage

Track events

The quickest way to start tracking usage is to use fair-analytics-client-api

Example usage:

import fairAnalytics from 'fair-analytics-client-api'

// create a fa instance
const fa = fairAnalytics({
  url: 'https://fa.yoursite.com' // the URL of your hosted Fair Analytics instance
})

// track events
fa.send({
  event: 'pageView', // event is mandatory and can be anything
  pathname: window.location.pathname
})
.then(res => {
  if (res.ok) {
    console.log('success')
  }
})
.catch(err => {
  console.error(err.message)
})

Please refer to the fair-analytics-client-api documentation for further details

Endpoints

Fair Analytics responds to 3 endpoints:

GET /

Responds with a basic homepage, displaying the feed.key

POST /

Used to POST tracked events. Responds with 204 in case of success (the body MUST be an object containing at least an event parameter)

GET /_live

Gets realtime updates via server sent events Useful to create real-time dashboards

Consuming real-time data is as easy as:

if (window.EventSource) {
  const source = new window.EventSource('https://fa.mysite.com/_live')

  source.addEventListener('fair-analytics-event', (e) => {
    console.log(e)
  })

  source.addEventListener('open', () => {
    console.log('Connection was opened')
  })

  source.addEventListener('error', e => {
    if (e.readyState === window.EventSource.CLOSED) {
      console.log('Connection was closed')
    }
  })
}
GET /_stats

Provides an aggregated view of all the events stored, grouped by event and pathname In this case data is persisted to a local JSON file using lowdb

Here is an example response:

{  
   "pageView":{  
      "/home":{  
         "times":640,
         "last":"2017-05-04T12:36:31.514Z"
      },
      "/about":{  
         "times":40,
         "last":"2017-05-04T12:36:31.514Z"
      }
   }
}

Replicate raw data

As we said Fair Analytics is distributed. It's easily possible to replicate raw data.

const hypercore = require('hypercore')
const swarm = require('hyperdiscovery')
const KEY = 'A FAIR ANALYTICS FEEED KEY'
const LOCALPATH = './replicated.dataset'

const feed = hypercore(LOCALPATH, KEY, {valueEncoding: 'json'})
swarm(feed)

feed.on('ready', () => {
  // this configuration will download all the feed
  // and process new incoming data
  // via the feed.on('data') callback
  // in case you want to process all the feed (old and new)
  // use only {tail: true, tail: true}

  feed.createReadStream({
    tail: true,
    live: true,
    start: feed.length,
    snapshot: false
  })
  .on('data', console.log) // Use this callback to precess data as you like
})

Tests

$ npm test

Change Log

This project adheres to Semantic Versioning.
Every release, along with the migration instructions, is documented in the CHANGELOG.md file.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].