All Projects β†’ sebinsua β†’ express-keenio

sebinsua / express-keenio

Licence: BSD-2-Clause license
πŸ“Š Rapidly install analytics with a middleware.

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to express-keenio

Dashboards
Responsive dashboard templates πŸ“Šβœ¨
Stars: ✭ 10,914 (+25885.71%)
Mutual labels:  analytics, keen-io
keen-sdk-net
A .NET SDK for the Keen IO API
Stars: ✭ 35 (-16.67%)
Mutual labels:  analytics, keen-io
bigquery-kafka-connect
☁️ nodejs kafka connect connector for Google BigQuery
Stars: ✭ 17 (-59.52%)
Mutual labels:  connect
redis-connect-dist
Real-Time Event Streaming & Change Data Capture
Stars: ✭ 21 (-50%)
Mutual labels:  connect
express-boilerplate
ExpressJS boilerplate with Socket.IO, Mongoose for scalable projects.
Stars: ✭ 83 (+97.62%)
Mutual labels:  express-js
acd
ACD helps you download Adobe Connect Sessions Videos and Audios, download files from FTP server, transfer files using Shift I/O
Stars: ✭ 117 (+178.57%)
Mutual labels:  connect
sbb
Semantic Body Browser - a tool for graphically exploring an organism's body.
Stars: ✭ 31 (-26.19%)
Mutual labels:  human
gancio
a shared agenda for local communities (with activitypub support)
Stars: ✭ 21 (-50%)
Mutual labels:  express-js
Awesome-DataScience-Cheatsheets
Collection of cheatsheets for data science, machine learning and deep learning :).
Stars: ✭ 48 (+14.29%)
Mutual labels:  analytics
express-ts-api-boilerplate
Express TypeScript API Boilerplate
Stars: ✭ 15 (-64.29%)
Mutual labels:  express-js
boilerplate-express-api
πŸ”‹Boilerplate Express API w/ Support for ES6 Features
Stars: ✭ 22 (-47.62%)
Mutual labels:  express-js
peasy-js-samples
Showcases business logic built with peasy-js and consumed by multiple clients
Stars: ✭ 19 (-54.76%)
Mutual labels:  express-js
firestore-store
express-session store for Firebase Cloud Firestore
Stars: ✭ 44 (+4.76%)
Mutual labels:  connect
craft-connect
Allows you to connect to external databases and perform db queries
Stars: ✭ 16 (-61.9%)
Mutual labels:  connect
Blogfy API
πŸš€ (WORK IN PROGRESS) Blogfy: API - A simple and ready-to-use Blog CMS for people who just want to write articles without worrying about tech stuff! Watch the project development live on twitch: twitch.tv/wilsonnetodev
Stars: ✭ 21 (-50%)
Mutual labels:  express-js
bdapis
Rest API service. Build with NodeJS, Express, MongoDB
Stars: ✭ 65 (+54.76%)
Mutual labels:  express-js
mern-boilerplate
React + Express + Webpack + Mongo = MERN Stack Boilerplate
Stars: ✭ 39 (-7.14%)
Mutual labels:  express-js
HRM Software
Human resource management C# based with SQL database desktop software.
Stars: ✭ 22 (-47.62%)
Mutual labels:  human
ExpressJS-SocketIO-Boilerplate
πŸ“¦ Simple Express.js & Socket.io Boilerplate
Stars: ✭ 31 (-26.19%)
Mutual labels:  express-js
reddit-clone
A reddit clone written using node.js / express.js / mongodb / passport.js. https://seiya-beddit.herokuapp.com/
Stars: ✭ 84 (+100%)
Mutual labels:  express-js

express-keenio

Build Status npm version

Install Keen IO analytics support into your Node.JS Express.js app in mere seconds and instantly begin capturing data.

Once installed it creates Keen.IO events from HTTP requests based on data intercepted from the calls res.json(), res.jsonp(), res.send(), res.render(), res.redirect(), res.sendfile() and res.download().

Read about why the middleware was made and the use cases it solves here.

Getting Started

Sign up to Keen IO for free here. And then install the package from the command line with:

$ npm install express-keenio

Usage

It's possible to use the middleware with specific routes decorator-style, like so:

var express = require("express"),
    keenio = require('express-keenio');

var app = express();

keenio.configure({ client: { projectId: '<test>', writeKey: '<test>'} });
keenio.on('error', console.warn); // There are 'error', 'info', 'warning', 'debug', 'track', and 'flush' events which are emitted.

app.get('/test', keenio.trackRoute('testCollection'), function (req, res) {
  // You code goes here.
});

app.post('/payment', keenio.trackRoute("payments",
                                      { query: ['userId', 'itemId', 'type', 'quantity', 'price'],
                                        reaction: ['receipt.status', 'receipt.tax'] }), function (req, res) {
  // Your code goes here.
});

app.listen(3000);

It's also possible to make the middleware handle all routes by useing it against the app:

var express = require("express"),
    bodyParser = require("body-parser"),
    keenio = require('express-keenio');

var app = express();

keenio.configure({ client: { projectId: '<test>', writeKey: '<test>' } });
app.configure(function () {
   app.use(bodyParser.json());
   app.use(keenio.handleAll());
});

app.get('/test', function (req, res) {
   // Your code goes here.
});

app.listen(3000);

Additionally, the standard Keen.IO Node.JS client is exposed on middleware.keenClient.

What will an event look like?

The middleware will create something that looks sort of like this:

{
  "identity": {
    "user": {
      "name": "Joe Bloggs",
      "email": "[email protected]",
      "age": 17
    },
    "session": {
      "id": "some-identifier"
    },
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36"
  },
  "intention": {
    "method": "POST",
    "path": "/pay-user/5",
    "params": {
      "userId": 5
    },
    "body": {
      "price": 5.00
    },
    "query": {},
    "referer": "http://keen.io/"
  },
  "reaction": {
    "success": true,
    "userAddress": "..."
  },
  "httpStatus": 200,
  "environment": {
    "library": "express-keenio"
  }
}

Configuration

Keen.IO Client Configuration

See KeenClient-Node#initialization.

{
  client: {
    projectId: '<test>',
    writeKey: '<test>'
  }
}

Event Property Limitation

Keen.IO has a set limit of 1000 on the number of event properties belonging to an Event Collection and after this it will begin to drop events.

Once you are reliant on analytics I STRONGLY recommend switching to explicit whitelists.

However by default this middleware provides a fallback in the form of eventually rigid schemas. Firstly, by default we accept up to 30 properties in the intention.query, 80 properties in a intention.body, and 120 properties in a reaction. Secondly, after a route receives 500 requests or exists for a week it stops accepting new event properties. Once these properties are discovered we cache them in a file given by options.defaults.eventualSchemas.cachePath (normally, './route-schemas.cache') however this feature can be switched off by giving options.defaults.eventualSchemas.cache the value false or specifying a complete explicit whitelist against a route.

Whitelist Properties

There are some default property whitelists in the form of whitelistProperties.query, whitelistProperties.body, whitelistProperties.reaction. Whitelists can also exist against each route definition or be passed into the second argument of the keenio.trackRoute() function.

Example 1:

{
  client: {
    projectId: '<test>',
    writeKey: '<test>'
  },
  whitelistProperties: {
    query: ['id', 'userId', 'name', 'type'],
    body: [],
    reaction: ['description']
  }
}

NOTE 1: An empty array means nothing is whitelisted while a missing whitelist key means no whitelist should be applied to the data.

NOTE 2: whitelistProperties.query, whitelistProperties.body and whitelistProperties.reaction can take deep property identifiers (e.g. 'deep.array[].name' or 'deep.property.value'.)

Example 2:

app.get('/test', keenio.trackRoute("testEventCollection", { query: ['id', 'userId', 'name', 'type'], body: [] }), function (req, res) {
   // Your code goes here.
});

Blacklist Properties

By default we delete any 'password' properties. If you wish you can pass in a list of other properties you wish to explicitly blacklist as shown below:

{
  client: {
    projectId: '<test>',
    writeKey: '<test>'
  },
  blacklistProperties: ['passwordHash', 'apiKey', 'authToken', 'userKey']
}

NOTE: blacklistProperties takes a property name that can be found anywhere inside an object. This means that 'passwordHash' would delete properties like intention.query.passwordHash and reaction.passwordHash. It does not allow you to specify exact properties at a particular depth like whitelistProperties.query, whitelistProperties.body and whitelistProperties.reaction each allow.

Route Configuration

If you are not using the decorator-style version of the middleware, and would like either (a) more control over which event collections exist or (b) the ability to disable specific event collections you may configure the routes upfront.

You must pick either 'routes' or 'excludeRoutes' but not both.

Excluding routes from default middleware operation

{
  client: {
    projectId: '<test>',
    writeKey: '<test>'
  },
  excludeRoutes: [
    { method: 'GET', route: 'route-name' }
  ]
}

Defining route configuration for middleware operation

{
  client: {
    projectId: '<test>',
    writeKey: '<test>'
  }
  routes: [
    { method: 'GET', route: 'route-name-1', eventCollectionName: '', whitelistProperties: {} },
    { method: 'POST', route: 'route-name-2', eventCollectionName: '' }
  ]
}

Defaults

It's also possible to override some of the default values used by validators, route schemas, etc.

{
  client: {
    projectId: '<test>',
    writeKey: '<test>'
  },
  defaults: {
    addons: {
      ipToGeo: false,
      userAgentParser: false
    },
    MAX_PROPERTY_HIERARCHY_DEPTH: 10,
    MAX_STRING_LENGTH: 1000,
    MAX_PROPERTY_QUANTITY: 300,
    eventualSchemas: {
      cache: true,
      cachePath: './route-schemas.cache',
      query: {
        MAX_PROPERTIES: 30,
        NUMBER_OF_INSTANCES: 500,
        NUMBER_OF_DAYS: 7
      },
      body: {
        MAX_PROPERTIES: 80,
        NUMBER_OF_INSTANCES: 500,
        NUMBER_OF_DAYS: 7
      },
      reaction: {
        MAX_PROPERTIES: 120,
        NUMBER_OF_INSTANCES: 500,
        NUMBER_OF_DAYS: 7
      }
    }
  }
}

Data Enrichment Addons

Keen IO supports two data enrichment addons: IP-to-GEO conversion and UserAgent parsing. If you would like to activate these addons for your project, just ask! The team is available in HipChat, IRC, or at [email protected].

Middleware Overrides

While not recommended it's possible to override some of the internal behaviours of the middleware like so:

{
  client: {
    projectId: '<test>',
    writeKey: '<test>'
  },
  handlers: {
    generateIdentity: function (req) {},
    generateEventCollectionName: function (route) {},
    parseRequestBody: function (body) {},
    parseRequestObject: function (req) {},
    parseResponseBody: function (body) {}
  }
}

Support

Feel free to submit issues and pull requests.

Tests

$ npm install --dev
$ npm test

Contributors

License

BSD 2-Clause License

Copyright (c) 2014, Seb Insua All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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].