1

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 ?

4
  • 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. Commented 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. Commented Aug 22, 2016 at 23:43
  • Ahh, yes, sorry, I forgot about that one. I'll add an answer explaining the difference. Commented Aug 22, 2016 at 23:46
  • 'k cool. I'm waiting :) Commented Aug 22, 2016 at 23:47

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Ok the thing is when I'm trying to use the Node.js client library I have some conflict with webpack. But I'll open another question for this. thanks.
You probably don't want to use webpack to bundle the node.js library because that would imply you're running it in the browser. If you're going to use the node.js library, you should be running it server side.
hum... not sure if I'm following you correctly. How do I run node.js library on the server side in my local project ?
Something like this: node path/to/script.js. If you're not familiar with that, it's probably worth reading up on running Node.js scripts.
yep thanks a lot ! I've opened another question here stackoverflow.com/questions/39090566/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.