2017-06-29 56 views
0

我有一个JSON对象,看起来像这样:添加JSON作为财产

{ 
    "field": "value", 
    "field2": "value", 
    "field3": "value" 
} 

我如何添加这类似于“热衷”对象敏锐的事件作为一个属性,所以我可以参考各个领域,即。 my_property.field1

回答

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); 
 
});