I'm building a dashboard using React, Redux and D3. I would like to display some data from the Google Analytics API. I already have my React and Redux app. It's working fine. I'm now trying to import data from my google analytics account. What should I use Javascript or Node-js libraries ? What the differences between them ?
-
Which libraries are you talking about? As far as I know the node.js client library is the only official JavaScript library for accessing Google Analytics data.Philip Walton– Philip Walton2016-08-22 23:39:55 +00:00Commented Aug 22, 2016 at 23:39
-
ok. so I don't understand what is this developers.google.com/analytics/devguides/reporting/core/v3/… ? It's isn't the node.js client library ? Sorry I'm confused.Simon Breton– Simon Breton2016-08-22 23:43:00 +00:00Commented Aug 22, 2016 at 23:43
-
Ahh, yes, sorry, I forgot about that one. I'll add an answer explaining the difference.Philip Walton– Philip Walton2016-08-22 23:46:49 +00:00Commented Aug 22, 2016 at 23:46
-
'k cool. I'm waiting :)Simon Breton– Simon Breton2016-08-22 23:47:23 +00:00Commented Aug 22, 2016 at 23:47
1 Answer
If you want to get data from one of the Google Analytics Reporting APIs via JavaScript, you have two choices:
They both have essentially the exact same reporting capabilities, the only difference is one runs in Node.js on the server and one runs in the browser.
An advantage of the JavaScript client library (which runs in the browser), is it can be easier to authenticate the current user (especially if they're already signed in to their Google account on that browser. (This Hello Analytics guide for JavaScript shows how to get started reporting on your data with the JavaScript client library) Of course, this assumes you want to get data for a view the current user has read access to.
If you want to display Google Analytics data on your website for a view that you have access to, but for which a visitor to your site may not, then you should run your query server side (via Node.js) and then pass the results to your existing D3 code.
To query the Google Analytics reporting API from the server you'll probably want to use a service account to authenticate your requests. This Hello Analytics guide for Python shows the concepts. I know it's not Node.js, but the basic ideas should all be the same.
5 Comments
node path/to/script.js. If you're not familiar with that, it's probably worth reading up on running Node.js scripts.