Keen.js 是 Keen IO 的 JavaScript SDK。
安装:
# via npm
$ npm install keen-js
# or Bower
$ bower install keen-js
配置:
记录单个事件:
// Configure an instance for your project
var client = new Keen({
projectId: "YOUR_PROJECT_ID",
writeKey: "YOUR_WRITE_KEY"
});
// Create a data object with the properties you want to send
var purchaseEvent = {
item: "Golden gadget",
prICE: 2550, // Track dollars as cents
referrer: document.referrer,
keen: {
timestamp: new Date().toISOString()
}
};
// Send it to the "purchases" collection
client.addEvent("purchases", purchaseEvent, Function(err, res){
if (err) {
// there was an error!
}
else {
// see sample response below
}
});