Permalink
Browse files

bugfix, more metrics in example

  • Loading branch information...
1 parent 6cebb29 commit a02537f3fcc6049a0f113cf2c16bf0c133b0df36 @qzaidi qzaidi committed Nov 30, 2012
Showing with 31 additions and 8 deletions.
  1. +29 −6 examples/basic.js
  2. +2 −2 lib/ga.js
View
35 examples/basic.js
@@ -1,3 +1,5 @@
+"use strict";
+
var ga = require('../lib/ga');
var profile='';
@@ -8,19 +10,40 @@ var GA = new ga.GA({
user: username,
password: password
});
+
+var dimensions = [
+ 'ga:date'
+];
+
+var metrics = [
+ 'ga:pageviews',
+ 'ga:visitors',
+ 'ga:transactions',
+ 'ga:transactionRevenue'
+];
+
GA.login(function(err, token) {
var options = {
'ids': 'ga:'+profile,
- 'start-date': '2012-07-01',
- 'end-date': '2012-08-10',
- 'dimensions': 'ga:pagePath',
- 'metrics': 'ga:pageviews',
- 'sort': '-ga:pagePath'
+ 'start-date': '2012-07-01',
+ 'end-date': '2012-07-02',
+ 'dimensions': dimensions.join(','),
+ 'metrics': metrics.join(','),
+ 'sort': 'ga:date'
};
+
GA.get(options, function(err, entries) {
if (!err) {
+ console.log('date,pageviews,visitors,transactions,sales');
entries.forEach(function(entry) {
- console.log(entry);
+ var buf = entry.dimensions[0]['ga:date'];
+
+ metrics.forEach(function(metric) {
+ buf += ',' + entry.metrics[0][metric];
+ });
+
+ console.log(buf);
+
});
} else {
console.log(err);
View
4 lib/ga.js
@@ -123,7 +123,7 @@ GA.prototype.get = function(options, cb) {
var data_data = combineChunks(chunks, length).toString();
- // console.log(data_data)
+ //console.log(data_data)
var parsed_data = JSON.parse(data_data);
@@ -151,7 +151,7 @@ GA.prototype.get = function(options, cb) {
var entry = {metrics:[], dimensions:[]};
var object_metric = {};
- for (var j=0; j<dimensions.length; j++){
+ for (var j=0; j<metrics.length; j++){
object_metric[metrics[j].name] = parseInt(parsed_data.rows[i][metric_indexes[j]], 10);
}
entry.metrics.push(object_metric);

0 comments on commit a02537f

Please sign in to comment.