我有一个看起来像这样的JSON对象:
{
"field": "value",
"field2": "value",
"field3": "value"
}
如何将此作为类似于" keen"的属性添加到敏锐事件中?对象,所以我可以引用单个字段,即。 my_property.field1
答案 0 :(得分:1)
Keen活动的属性基于您首次发布活动时发送的任何JSON。您可以发布历史事件,但无法向已发布的事件添加新属性。这是一个用JavaScript发送事件的示例。说你的活动是一条推文。
var client = new Keen({
projectId: 'PROJECT_ID',
writeKey: 'WRITE_KEY'
});
var tweet_event = {
keen: {
timestamp: new Date().toISOString(), // time the tweet happened
},
field: "value", // values you mentioned
field2: "value",
field3: "value,
tweet: { // other properties you might have
author: "@michellewetzler",
text: "Dwell on the beauty of life. Watch the stars, and see yourself running with them. (Marcus Aurelius)"
}
}
// Record the event (send it to Keen IO)
client.recordEvent('tweets', tweet_event, function(err, res){ // name your collection here
if (err) {
document.getElementById('yeah').innerHTML = "Something is amiss. Check console for errors. Did you forget a comma perhaps? Or a curly brace?"
}
else {
document.getElementById('yeah').innerHTML = "You just sent an event to Keen IO!"
}
});

然后您可以在以下查询中引用这些属性:
var client = new Keen({
projectId: "PROJECT_ID",
readKey: "READ_KEY"
});
// count the number of tweets where field = value
var count = new Keen.Query("count", {
event_collection: "tweets",
timeframe: "this_14_days",
filters: [
{
property_name: "field",
operator: "eq",
property_value: value
}
]
});
// Send query
client.run(count, function(err, response){
// if (err) handle the error
console.log('result is: ', response.result);
});