Skip to content

Commit

Permalink
Adds alltime stats
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed Mar 11, 2019
1 parent 6e1245c commit f5add4d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
37 changes: 37 additions & 0 deletions api/analytics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"thisWeek": [
175,
21
],
"lastWeek": [
227,
370,
453,
500,
373,
370,
193
],
"thisYear": [
9602,
8037,
2745
],
"lastYear": [
4118,
4949,
5646,
5775,
5740,
5635,
5655,
5550,
6306,
7670,
7067,
5737
],
"allTime": [
529067
]
}
8 changes: 6 additions & 2 deletions misc/ga-analytics-generate/analytics.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"thisWeek": [
151
175,
21
],
"lastWeek": [
227,
Expand All @@ -14,7 +15,7 @@
"thisYear": [
9602,
8037,
2716
2745
],
"lastYear": [
4118,
Expand All @@ -29,5 +30,8 @@
7670,
7067,
5737
],
"allTime": [
529067
]
}
17 changes: 15 additions & 2 deletions misc/ga-analytics-generate/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ const lastYear = query({
"expression":"ga:users"
}]
});

const allTime = query({
viewId,
"dateRanges": [{
'startDate': "2012-01-01",
'endDate': moment(now).date(1).month(0).subtract(1, 'day').format('YYYY-MM-DD')
}],
"metrics":[{
"expression":"ga:pageViews"
}]
});

function query(request) {
const req = {
Expand All @@ -121,16 +132,18 @@ function query(request) {
});
}

Promise.all([thisWeek, lastWeek, thisYear, lastYear]).then((results) => {
Promise.all([thisWeek, lastWeek, thisYear, lastYear, allTime]).then((results) => {
const thisWeek = results[0].data.reports[0].data.rows.map((row) => { return +row.metrics[0].values; });
const lastWeek = results[1].data.reports[0].data.rows.map((row) => { return +row.metrics[0].values; });
const thisYear = results[2].data.reports[0].data.rows.map((row) => { return +row.metrics[0].values; });
const lastYear = results[3].data.reports[0].data.rows.map((row) => { return +row.metrics[0].values; });
const allTime = results[4].data.reports[0].data.rows.map((row) => { return +row.metrics[0].values; });
const data = {
thisWeek,
lastWeek,
thisYear,
lastYear
lastYear,
allTime
}
fs.writeFileSync('analytics.json', JSON.stringify(data, null, 2));
});

0 comments on commit f5add4d

Please sign in to comment.