Skip to content

bibanul/KeenClient-Node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keen IO - NodeJS

Build Status

Keen IO is an online service to collect, analyze, and visualize your data.

Getting Started

npm install keen.io

Examples

Initialisation

var keen = require('keen.io');

// Configure instance. Only projectId and writeKey are required to send data.
var keen = keen.configure({
	projectId: "<project_id>",
	writeKey: "<write_key>",
	readKey: "<read_key>",
	masterKey: "<master_key>"
});

You can also have multiple instances if you are connecting to multiple KeenIO accounts in the one project (probably edge case).

var keen = require('keen.io');

// Configure instance with API Key
var keen1 = keen.configure({...});
var keen2 = keen.configure({...});

In the future there will be the ability to pass options into the initialisation such as batching inserts, etc. The structure of this hasn't been defined yet but will look something like the following.

var keen = require('keen.io');

// Configure instance with API Key and options
var keen = keen.configure({ 
	projectId: "<project_id>",
	batchEventInserts: 30 
});

Send Events

var keen = require("keen.io");
var keen = keen.configure({
	projectId: "<project_id>",
	writeKey: "<write_key>"
});

// send single event to Keen IO
keen.addEvent("my event collection", {"property name": "property value"}, function(err, res) {
	if (err) {
		console.log("Oh no, an error!");
	} else {
		console.log("Hooray, it worked!");
	}
});

// send multiple events to Keen IO
keen.addEvents({
	"my first event collection": [{"property name": "property value"}, ...],
	"my second event collection": [{"property name2": "property value 2"}]
}, function(err, res) {
	if (err) {
		console.log("Oh no, an error!");
	} else {
		console.log("Hooray, it worked!");
	}
});

Generate Scoped Key

var keen = require("keen.io");
var apiKey = "YOUR_API_KEY";
var scopedKey = keen.encryptScopedKey(apiKey, {
	"allowed_operations": ["read"],
	"filters": [{
		"property_name": "account.id",
		"operator": "eq",
		"property_value": "123"
	}]
});
var keen = keen.configure({
	projectId: "<project_id>";
	readKey: scopedKey
});

Future Updates

Future module updates are planned to introduce the remaining api calls. You can see some of the spec for that in examples/queries.js. Also as mentioned above specifying options when creating an instance to configure the behaviour of the instance (ie, batching event submissions).

Contributing

Please feel free to contribute, pull requests very welcome. The aim is to build up this module to completely represent the API provided by Keen IO which quite extensive so the more contributions the better.

Further Reading

Keen IO - Website: https://keen.io/

Keen IO - API Technical Reference: https://keen.io/docs/api/reference/

Release History

0.0.3

  • Support generating Scoped Keys.

0.0.2

  • Change error for blank write key.

0.0.1

  • Add write/read keys.
  • Reworked interface - not backwards compatible with 0.0.0!

0.0.0

  • First release.

License

Licensed under the MIT license.

About

Official NodeJS client for the Keen IO API. Build analytics features directly into your NodeJS apps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%