简体   繁体   中英

Google API Client Libraries for react project, Javascript or Node-js ?

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM