Keen IO
Machine LearningGetting Started with Keen.io API
Keen.io is a powerful analytics platform that allows you to collect and analyze data from different sources. In order to access Keen.io's data, you will need to use their API which provides a set of RESTful endpoints.
In this guide, we will walk you through the steps of using Keen.io API to collect and analyze data. We will also provide you with some example code snippets in JavaScript to help you get started.
Prerequisites
- Keen.io account
- Basic knowledge of JavaScript
Creating a Project
To get started with Keen.io, you will need to create a project on their website. Once you have created a project, you will be provided with a projectId
and an apiKey
that you will need to use to access your data.
Collecting Data
Keen.io API provides a /events
endpoint that allows you to send event data to your project. Events are structured data that include information about a user's action or interaction with your website or app. Here's an example of how to send an event using the Keen.io API:
const keen = require('keen.io');
const client = keen({
projectId: 'YOUR_PROJECT_ID',
writeKey: 'YOUR_WRITE_KEY'
});
client.addEvent('eventCollection', {
'property1': 'value1',
'property2': 'value2'
}, (err, res) => {
if (err) {
console.log(err.message);
} else {
console.log('Event sent successfully!');
}
});
In this example, we are using the addEvent
method to send an event to Keen.io. The first argument is the name of the event collection, which you can create on your Keen.io project. The second argument is an object that includes the properties and values you want to include in the event.
Querying Data
Once you have collected data using Keen.io API, you can use their powerful query capabilities to analyze the data. Keen.io allows you to perform complex queries on your data using their Query API.
Here's an example of how to query data using Keen.io API:
const keen = require('keen.io');
const client = keen({
projectId: 'YOUR_PROJECT_ID',
readKey: 'YOUR_READ_KEY'
});
const query = new keen.Query('count', {
eventCollection: 'eventCollection',
timeframe: 'this_14_days',
groupBy: 'property1'
});
client.query(query, (err, res) => {
if (err) {
console.log(err.message);
} else {
console.log(res.result);
}
});
In this example, we are using the Query
class to create a new query. We are using the count
analysis type to count the number of events that match our query. The eventCollection
property specifies the name of the collection we want to query, and timeframe
specifies the time range for the query. Finally, we are grouping the results by property1
.
Conclusion
Keen.io API provides a powerful set of tools that you can use to collect and analyze data from different sources. In this guide, we have provided you with an overview of how to use Keen.io API to collect and query data. We also provided you with some example code snippets in JavaScript to help you get started.