Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #15 from rowanu/master

Added support for multiple metrics/dimensions per request
  • Loading branch information...
commit b5c1503edce6708e8baa6d09adabb40e6127b2e3 2 parents 7bf92b8 + 1c44cb5
@ncb000gt authored
Showing with 16 additions and 12 deletions.
  1. +16 −12 lib/ga.js
View
28 lib/ga.js
@@ -116,38 +116,42 @@ GA.prototype.get = function(options, cb) {
});
res.on('end', function() {
var entries = []
- ,metric_index
- ,metric
- ,dimension
- ,dimension_index;
+ ,metric_indexes = []
+ ,metrics = []
+ ,dimensions = []
+ ,dimension_indexes = [];
var data_data = combineChunks(chunks, length).toString();
- console.log(data_data)
+ // console.log(data_data)
var parsed_data = JSON.parse(data_data);
for (var col=0; col<parsed_data.columnHeaders.length; col++){
if(parsed_data.columnHeaders[col]['columnType'] === "METRIC"){
- metric_index = col;
- metric = parsed_data.columnHeaders[col];
+ metric_indexes.push(col);
+ metrics.push(parsed_data.columnHeaders[col]);
}
if(parsed_data.columnHeaders[col]['columnType'] === "DIMENSION"){
- dimension_index = col;
- dimension = parsed_data.columnHeaders[col];
+ dimension_indexes.push(col);
+ dimensions.push(parsed_data.columnHeaders[col]);
}
}
- for (i=0; i<parsed_data.rows.length; i++){
+ for (var i=0; i<parsed_data.rows.length; i++){
var entry = {metrics:[], dimensions:[]};
var object_metric = {};
- object_metric[metric.name] = parseInt(parsed_data.rows[i][metric_index], 10);
+ for (var j=0; j<dimensions.length; j++){
+ object_metric[metrics[j].name] = parseInt(parsed_data.rows[i][metric_indexes[j]], 10);
+ }
entry.metrics.push(object_metric);
var object_dimension = {};
- object_dimension[dimension.name] = parsed_data.rows[i][dimension_index];
+ for (var j=0; j<dimensions.length; j++){
+ object_dimension[dimensions[j].name] = parsed_data.rows[i][dimension_indexes[j]];
+ }
entry.dimensions.push(object_dimension);
self.emit('entry', entry);
Please sign in to comment.
Something went wrong with that request. Please try again.