Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added support for multiple metrics/dimensions per request #15

Merged
merged 2 commits into from

2 participants

@rowanu

Library was accepting multiple metrics/dimensions in each request, but not parsing/returning the additional data (only the first value of each was being parsed).

rowanu added some commits
@rowanu rowanu stopped debug output, fixed global leake of counter variable fa78834
@rowanu rowanu supressed debug output to console, added support for multiple metrics…
… and dimensions per request (metrics and dimensions were being accepted, but not returned) - have kept style as consistent as possbile
1c44cb5
@rowanu

Whoops, hold off this one just yet -- worked in test environment, but not in production... Will update.

@rowanu

Just a checkout issue - changes look good to me.

Thanks for the lib!

@ncb000gt ncb000gt merged commit b5c1503 into ncb000gt:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2012
  1. @rowanu
Commits on Nov 15, 2012
  1. @rowanu

    supressed debug output to console, added support for multiple metrics…

    rowanu authored
    … and dimensions per request (metrics and dimensions were being accepted, but not returned) - have kept style as consistent as possbile
This page is out of date. Refresh to see the latest.
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);
Something went wrong with that request. Please try again.