【问题标题】:adding JSON as property添加 JSON 作为属性
【发布时间】:2017-06-29 19:13:10
【问题描述】:

我有一个如下所示的 JSON 对象:

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

如何将它作为类似于“敏锐”对象的属性添加到敏锐事件中,以便我可以引用单个字段,即。 my_property.field1

【问题讨论】:

    标签: json keen-io


    【解决方案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);
    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 2021-05-24
      • 2016-02-06
      • 2015-01-26
      • 1970-01-01
      相关资源
      最近更新 更多