0

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

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

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

4

1 回答 1

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

于 2017-06-29T19:29:04.887 回答