Accessing Google Analytics Reports using the API - google-analytics

I know how to use the Google API to access different metrics and dimensions to query for specific data. However, I am faced with a different scenario. I would like to know if there is any mechanism to access the reports/custom reports that are already created using the Google Analytics web user interface.
Our client has created about 15 different reports and now wants us to simply get the data into his own database rather than having to log into the Google Analytics website and run the report and export the data.
Can anyone please guide me on this?

Not sure if this is exactly what you are thinking, but you can always use the Reporting API to extract the data using python/javascript/etc and then store the data locally in your database. For more info, check out the Google Analytics Query Explorer and try out different combinations of dimensions and metrics to be able to extract the data. You can then use any number of different Core Reporting API Client libraries to access the analytics database.

Related

Get access to clients data using API

Is it possible to make a platform where client can sign up and log in using their Google accounts, and accept that their Google Analytics data will be used for calculations.
They should accept the use only once, and then the program should download and process the Google Analytics data every day.
Please point me in the correct direction for documentation
Yes, you need to create a project in Google Cloud Platform, then go to : API and Services > Library > Google Analytics API. (This is to get analytics from an user). Then you need to create a project inside Firebase, allowing email authentication and you will be able to do your task.

Can we access the benchmarking report/data from Google Analytics reporting API?

I am trying to access the Google analytics data for Benchmarking reports via API or programmatically
I couldn't find this in the reporting API or metadata API. Am I missing something?
The google analytics website uses the Google analytics api to get its data. So as long as you find the exact same dimensions and metrics you used in the report you are talking about then yes you could recreate the report using the Reporting API. Some of the reports contain calculated fields which you will have to calculate yourself by requesting the data that is needed for the calculation in order to get the correct results.
If you want the actual results to be computed for you and see the graph itself the answer is no. The api is just raw data you have to do all the calculations and display yourself.

Google Core Analytics API - Data accuracy

I have a Console App. which downloads the Acquisitions Report by querying the Google Analytics Core API.
Here is a screenshot of my query as shown on Google Analytics Query Explorer:
I am unable to obtain a complete match of Goal Completions data between the API Data Output and the Analytics web interface. The variance is not too high but it exists. The Query Explorer and my Code Extract both match, but again, both of them mismatch with the data shown on the Analytics Web Interface.
All query parameters match 100%; including dates, Profile ID, ..etc.
I read articles online such as this one and this one, which elaborate on the inaccuracy of the Goal Completions data in google analytics, I wonder, could this be likely what is happening here?
Could this be related to bots and spiders? How do I exclude these from the query by using code?
Many thanks.

How to query Google Analytics using Javascript

We're want to query Google Analytics remotely, to retrieve (and display) a list of most popular pages (in a certain period) on a website. The examples I've looked at, for querying Analytics using Javascript, seem to require an user/person to login. Is this correct? Is there a way of skipping this step, and querying Analtyics unattended?
Thanks,
Toby
No. the data inside Google Analytics is potentially strategic and the tool doesn't provide non-logged in access at any time.
In order to do what you want the best approach is probably to query the data using your credentials on the server side and store the data on a database. Run that again every night or so.
Then you just query the database and generate the count to display on the frontend.
You don't want to do that on javascript because you would be exposing your credentials to anyone visiting your site to query all your Google Analytics data.

How can I generate a GA tracking code programmatically?

How to generate Google Analytics tracking code programmatic-ally?
I am new to Google Analytics API, can someone please help
It is NOT possible to create new Google Analytics accounts or profiles programmatically using the existing APIs.
There are two APIs available, the Data Export API and the Management API. However, they are bot read-only.
With the Google Analytics Data Export API, you can develop client applications to request data from an existing Analytics profile for an authorized user, and refine the results of the request using query parameters. Currently, the Data Export API supports read-only access to your Google Analytics data.
Currently, the Management API supports read-only access to five components of the Google Analytics Management system: Account data,Profile data, Web property data, Goal data, Advanced segments
Seems like it's finally possible in 2021 with alpha api.
https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties/create#authorization-scopes
It's not currently possible to create Google Analytics accounts automatically at the moment but generating the tracking code is possible.
The only real variation between the tracking code generated each time you create a profile for a new domain is the web property ID. This is in the format UA-XXXXXXX-X. Each X is a number - the first 7 numbers are the account number and the number after the last dash relates to each web property set up for the account.
You can use the accounts feed of the API to get a list of accounts and their profiles. If an account only has one profile then it's possible to use the web property ID of it to automatically generate the tracking code. However, if there's multiple web properties then you would need a way to decide which one to use (present the user with a selection list etc).

Resources