Keen.js是KeenIO的JavaScriptSDK。
安装:
# via npm$ npm install keen-js# or bower$ bower install keen-js配置:
<script type="text/javascript"> var client = new Keen({ projectId: "YOUR_PROJECT_ID", // String (required always) writeKey: "YOUR_WRITE_KEY", // String (required for sending data) readKey: "YOUR_READ_KEY" // String (required for querying data) // protocol: "https", // String (optional: https | http | auto) // host: "api.keen.io/3.0", // String (optional) // requestType: "jsonp" // String (optional: jsonp, xhr, beacon) });</script>记录单个事件:
// Configure an instance for your projectvar client = new Keen({ projectId: "YOUR_PROJECT_ID", writeKey: "YOUR_WRITE_KEY"});// Create a data object with the properties you want to sendvar purchaseEvent = { item: "golden gadget", price: 2550, // track dollars as cents referrer: document.referrer, keen: { timestamp: new Date().toISOString() }};// Send it to the "purchases" collectionclient.addEvent("purchases", purchaseEvent, function(err, res){ if (err) { // there was an error! } else { // see sample response below }});
评论