I'm trying to create a Keen event from parse.com cloud code (node.js). I'm using a JS module ( https://github.com/roycef/keen-parse ) which seems to be set up OK. To test things, I've set up a simple test and here is the complete main.js (credentials removed):
var express = require('express');
var app = express();
// Global app configuration section
app.use(express.bodyParser());
var Keen = require('cloud/keen.js');
var keen = Keen.configure({
projectId: "xxxxxxxx",
writeKey: "xxxxxxxx"
});
app.get('/kiss', function (req, res) {
var resp = {};
var respCode = 404;
var testObj = {"firstname": "John", "surname": "Doe"};
// send single event to Keen IO
keen.addEvent("Testola", testObj, function (err, res) {
if (err) {
resp = err;
respCode = 500;
} else {
resp = res.data;
respCode = 200;
}
}).then(function () {
// send something back to the app
res.setHeader('Content-Type', 'application/json');
res.send(resp, respCode);
});
});
app.listen();
When I GET /kiss:
So, 2 questions:
It looks like keen-parse is using the old node-specific SDK for Keen. That SDK was deprecated quite a while ago, and I believe there have been some breaking changes in the API since then.
You probably want to use keen-js directly, instead. It's super simple to set up, and I don't think you really lose any functionality from keen-parse.
Give keen-tracking.js a try. This is a new tracking-only SDK that is a full drop-in replacement for keen-js. Here is a quick rewrite of your example code w/ the new SDK in place:
var express = require('express');
var app = express();
// Global app configuration section
app.use(express.bodyParser());
var Keen = require('keen-tracking');
var keen = new Keen({
projectId: "xxxxxxxx",
writeKey: "xxxxxxxx"
});
app.get('/kiss', function (req, res) {
var resp = {};
var respCode = 404;
var testObj = {"firstname": "John", "surname": "Doe"};
// send single event to Keen IO
keen.recordEvent("Testola", testObj, function (err, res) {
res.setHeader('Content-Type', 'application/json');
if (err) {
res.send(err, 500);
}
else {
res.send(res, 200);
}
});
});
app.listen();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.