Zach
Zach

Reputation: 1185

Google Analytics API (per day pageviews)

I'm using the Analytics API within my Node application, and have the following so far:

const result = await google.analytics('v3').data.ga.get({ 'auth': jwt, 'ids': 'ga:' + viewId, 'start-date': '30daysAgo', 'end-date': 'today', 'metrics': 'ga:pageviews', });

Returns:

... rows: [ [ '168' ] ] }

This works great so far! But, instead of grabbing the total number of pageviews, I'm looking to have the data returned so I can see hits per day as I'd like to create a graph within my application to show this off using a chart library. Any push in the right direction would be greatly appreciated. Thanks!

Upvotes: 0

Views: 1664

Answers (1)

Zach
Zach

Reputation: 1185

This will do it!

const result = await google.analytics('v3').data.ga.get({ 'auth': jwt, 'ids': 'ga:' + viewId, 'start-date': '30daysAgo', 'end-date': 'today', 'dimensions': 'ga:date', 'metrics': 'ga:pageviews', });

Produces:

````

rows: [ [ '20181102', '0' ],
 [ '20181103', '2' ],
 [ '20181104', '0' ],
 [ '20181105', '0' ],
 [ '20181106', '2' ],
 [ '20181107', '12' ],
 [ '20181108', '10' ],
 [ '20181109', '11' ],
 [ '20181110', '7' ],
 [ '20181111', '20' ],
 [ '20181112', '6' ],
 [ '20181113', '16' ],
 [ '20181114', '8' ],
 [ '20181115', '8' ],
 [ '20181116', '4' ],
 [ '20181117', '9' ],
 [ '20181118', '2' ],
 [ '20181119', '2' ],
 [ '20181120', '7' ],
 [ '20181121', '4' ],
 [ '20181122', '3' ],
 [ '20181123', '3' ],
 [ '20181124', '4' ],
 [ '20181125', '0' ],
 [ '20181126', '3' ],
 [ '20181127', '6' ],
 [ '20181128', '2' ],
 [ '20181129', '3' ],
 [ '20181130', '0' ],
 [ '20181201', '6' ],
 [ '20181202', '9' ] ]

Upvotes: 2

Related Questions