React : Get data from Google Analytics API - javascript

I'm creating an application using React and Laravel.
I integrated successfuly Google Analytics using this react-ga so when I check my Analytics dashboard the statistics of the pages of my project are there.
Now I want to display those data in my application to the users.
I've searched alot and I found that I need to use Embed API. The problem here is that it request an authentification each time a user want to access to the data. Searched some more and the solution was apparently to setup a service account as a user in Google Analytics.
Now that I have the account set, the API key generated, I don't know how to call the data from the server to my application.
There is this guide for javascript but I had a hard time implementing in React.

Related

Accessing google anyaltics API in my aaplication

I am currently working with the Google Analytics API. I have implemented ga react package, so the analytics tool can show me the required data.
As per my understanding, Google uses OAuth 2.0 to identify the user and grant access. As my application has it's own user(s) and every user is not available in google.
Is it possible to access the Google analytics API inside my application?. API should get called using an only the API key.
So is it possible to access Google analytics API with the only key?
First off let me start by saying im not sure i understand this statement
As my application has it's own user(s) and every user is not available in google.
I am going to assume that you are trying to show the users of your application the analytics data from a single analytics account which they dont have access to.
API Keys
Api keys are used to access public data only. Public data is data that is not owned by any user. Public Videos on YouTube, Google analytics meta data API, Holiday calendars on google calendar these are all examples of Public data not owned by any user.
Private data
In order to access private user data you must have the permission of the user who has access to that data. Google analytics data is private user data you own the data associated with your account. In order for your application to access that data it must have your permission to do so. Permission is grated using Oauth2.
If you will only ever be accessing your own account and you will not be accessing data owned by other users then you could consider using a service account. Service accounts are dummy users you can share your google analytics account with the service account there by preauthorizing its access and it will then be able to access the data without needing to be logged in all the time. The issue with service accounts is that it cant be used client side you will need to use server sided code for this. I am not a react developer so im not sure if thats one of the JavaScript frameworks that can also run server-sided or not.

Downloading Google Analytics Data By Client_id

I'm allowing users of my site to download their google analytics data at their free will for transparency sake and I don't want to deal with CCPA requests for data myself.
I'm using Node.js as my backend and was wondering if it's possible to download google analytics by client_id. I'm using a service account for my google console access.
If there's some documented api endpoint that I'm not seeing that would help a lot.
Sure you have, it came in for that purpose
The User Activity API allows a Google Analytics property owner to
retrieve all analytics measurement data associated with a single user.
Specifically, the API retrieves all of the measurement data associated
with a particular User ID or Client ID.
https://developers.google.com/analytics/devguides/reporting/core/v4/user-reporting

Google Analytcs Data without login

I have an application made with Angular 5 and I want to show some Google Analytcs data on the page.
The problem is that the analytcs reporting API needs authentication and I need to everyone who access application to see it.
Is there a way to make that possible?

Access Google Analytics API via javascript with service account

Title pretty much says it all - I need to access Analytics data for a site, using the Javascript API and authenticating via a service account. Is this possible, if so, how? Have spent hours running in circles in the Google docs to no avail.
I'm looking to build a dashboard to publically display stats for the site, hence the need for the service account.
Javascript is a must - I need a completely client-side solution.
Any ideas?

Google analytics credentials

I am currently new for Google analytics API throu Javascript.
I am implementing some of charts and for first load, page is redirecting me to google site to login with Analytics account and then returning to my orignal page, refresh & chart show.
Now, instead of redirecting to google analytics, is there any other way that I can store credentials on either in code behind or in config file and it will be read from there when page get loaded?
Let me know if there are any other ways/ ideas around?
I can give you some help.
Initially we need to authenticate the users, For that purpose we are redirecting the user to Google.[Mostly using Oauth]
After the authentication done. Google will redirect to your site with the access Token.
Access token is the key to fetch the analytics data from Google's database by using Management API and core reporting API.
You have to do some exchanges with google to make the token as permanent and you can store it your database.But based on some conditons this token may expire.
Visit this url : https://developers.google.com/analytics/devguides/ and understand the Google Analytics, Core Reporting API and Oauth Process
Down load this useful PHP client library for Google Analytics https://code.google.com/p/google-api-php-client/ and have fun.

Categories

Resources