0
我有一個JSON對象,看起來像這樣:添加JSON作爲財產
{
"field": "value",
"field2": "value",
"field3": "value"
}
我如何添加這類似於「熱衷」對象敏銳的事件作爲一個屬性,所以我可以參考各個領域,即。 my_property.field1
我有一個JSON對象,看起來像這樣:添加JSON作爲財產
{
"field": "value",
"field2": "value",
"field3": "value"
}
我如何添加這類似於「熱衷」對象敏銳的事件作爲一個屬性,所以我可以參考各個領域,即。 my_property.field1
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);
});