You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Configure instance. Only projectId and writeKey are required to send data.
23
-
var keen =keen.configure({
23
+
var keen =Keen.configure({
24
24
projectId:"<project_id>",
25
25
writeKey:"<write_key>",
26
26
readKey:"<read_key>",
@@ -31,20 +31,20 @@ var keen = keen.configure({
31
31
You can also have multiple instances if you are connecting to multiple KeenIO accounts in the one project (probably edge case).
32
32
33
33
```javascript
34
-
varkeen=require('keen.io');
34
+
varKeen=require('keen.io');
35
35
36
36
// Configure instance with API Key
37
-
var keen1 =keen.configure({...});
38
-
var keen2 =keen.configure({...});
37
+
var keen1 =Keen.configure({...});
38
+
var keen2 =Keen.configure({...});
39
39
```
40
40
41
41
In the future there will be the ability to pass options into the initialisation such as batching inserts, etc. The structure of this hasn't been defined yet but will look something like the following.
42
42
43
43
```javascript
44
-
varkeen=require('keen.io');
44
+
varKeen=require('keen.io');
45
45
46
46
// Configure instance with API Key and options
47
-
var keen =keen.configure({
47
+
var keen =Keen.configure({
48
48
projectId:"<project_id>",
49
49
batchEventInserts:30
50
50
});
@@ -53,8 +53,8 @@ var keen = keen.configure({
53
53
### Send Events
54
54
55
55
```javascript
56
-
varkeen=require("keen.io");
57
-
var keen =keen.configure({
56
+
varKeen=require("keen.io");
57
+
var keen =Keen.configure({
58
58
projectId:"<project_id>",
59
59
writeKey:"<write_key>"
60
60
});
@@ -82,26 +82,148 @@ keen.addEvents({
82
82
```
83
83
84
84
### Generate Scoped Key
85
+
85
86
```javascript
86
-
varkeen=require("keen.io");
87
+
varKeen=require("keen.io");
87
88
var apiKey ="YOUR_API_KEY";
88
-
var scopedKey =keen.encryptScopedKey(apiKey, {
89
+
var scopedKey =Keen.encryptScopedKey(apiKey, {
89
90
"allowed_operations": ["read"],
90
91
"filters": [{
91
92
"property_name":"account.id",
92
93
"operator":"eq",
93
94
"property_value":"123"
94
95
}]
95
96
});
96
-
var keen =keen.configure({
97
+
var keen =Keen.configure({
97
98
projectId:"<project_id>";
98
99
readKey: scopedKey
99
100
});
100
101
```
101
102
103
+
## Queries
104
+
105
+
Analyses are first-class citizens, complete with parameter getters and setters.
106
+
107
+
The `<Client>.run` method is available on each configured client instance to run one or many analyses on a given project. Read more about running multiple analyses below.
108
+
109
+
**Format:**
110
+
111
+
```
112
+
var your_analysis = new Keen.Query(analysisType, params);
113
+
```
114
+
115
+
### Example Usage
116
+
117
+
```
118
+
var Keen = require('keen.io');
119
+
var keen = Keen.configure({
120
+
projectId: "your_project_id",
121
+
readKey: "your_read_key"
122
+
});
123
+
124
+
var count = new Keen.Query("count", {
125
+
event_collection: "pageviews",
126
+
group_by: "property",
127
+
timeframe: "this_7_days"
128
+
});
129
+
130
+
// Send query
131
+
keen.run(count, function(err, response){
132
+
if (err) return console.log(err);
133
+
// response.result
134
+
});
135
+
```
136
+
137
+
138
+
### Query Analysis Types
139
+
140
+
All of the following analyses require an `event_collection` parameter. Some analyses have additional requirements, which are noted below.
141
+
142
+
`count`
143
+
144
+
`count_unique`
145
+
146
+
`sum` requires a `target_property` parameter, where value is an integer
147
+
148
+
`average` requires a `target_property` parameter, where value is an integer
149
+
150
+
`maximum` requires a `target_property` parameter, where value is an integer
151
+
152
+
`minimum` requires a `target_property` parameter, where value is an integer
153
+
154
+
`select_unique` requires a `target_property` parameter
155
+
156
+
`extraction`
157
+
158
+
**A note about extractions:** supply an optional `email` attribute to be notified when your extraction is ready for download. If email is not specified, your extraction will be processed synchronously and your data will be returned as JSON.
159
+
160
+
`Keen.Funnel` requires a `steps` attribute
161
+
162
+
**A note about funnels:** funnels require a `steps` as an array of objects. Each step requires an `event_collection` and `actor_property` parameter.
163
+
164
+
```
165
+
var funfunfunnel = new Keen.Query('funnel', {
166
+
steps: [
167
+
{
168
+
event_collection: "view_landing_page",
169
+
actor_property: "user.id"
170
+
},
171
+
{
172
+
event_collection: "signed_up",
173
+
actor_property: "user.id"
174
+
},
175
+
],
176
+
timeframe: "this_6_months"
177
+
});
178
+
```
179
+
180
+
181
+
Learn more about funnels in the [API reference](https://keen.io/docs/data-analysis/funnels/#steps)
182
+
183
+
### Run multiple analyses at once
184
+
185
+
The `<Client>.run` method accepts an individual analysis or array of analyses. In the latter scenario, the callback is fired once all requests have completed without error. Query results are then returned in a correctly sequenced array.
186
+
187
+
Query results are also attached to the query object itself, and can be referenced as `this.data`.
188
+
189
+
```
190
+
var avg_revenue = new Keen.Query("average", {
191
+
event_collection: "purchase",
192
+
target_property: "price",
193
+
group_by: "geo.country"
194
+
});
195
+
var max_revenue = new Keen.Query("maximum", {
196
+
event_collection: "purchase",
197
+
target_property: "price",
198
+
group_by: "geo.country"
199
+
});
200
+
201
+
var mashup = keen.run([avg_revenue, max_revenue], function(err, res){
202
+
if (err) return console.log(err);
203
+
// res[0].result or this.data[0] (avg_revenue)
204
+
// res[1].result or this.data[1] (max_revenue)
205
+
});
206
+
```
207
+
208
+
209
+
### Get/Set Parameters and Refresh Queries
210
+
211
+
```
212
+
// Based on previous example
213
+
214
+
// Update parameters
215
+
avg_revenue.set({ timeframe: "this_21_days" });
216
+
max_revenue.set({ timeframe: "this_21_days" });
217
+
218
+
// Re-run the query
219
+
mashup.refresh();
220
+
```
221
+
222
+
223
+
102
224
## Future Updates
103
225
104
-
Future module updates are planned to introduce the remaining API calls. You can see some of the spec for that in [examples/queries.js](https://github.com/keenlabs/KeenClient-Node/blob/master/examples/queries.js). Also, as mentioned above, specifying options when creating an instance to configure the behaviour of the instance (ie, batching event submissions).
226
+
Future module updates are planned to introduce the remaining API calls. You can see some sketches for these in the [examples directory](https://github.com/keenlabs/KeenClient-Node/blob/master/examples/). Also, as mentioned above, specifying options when creating an instance to configure the behaviour of the instance (ie, batching event submissions).
0 commit comments