List of clientIds of active users with Google Analytics API - google-analytics

I'm looking for a way to get the list of client ids of users that are currently on the website. Realtime reporting API seems to be giving just the metrics like the number of currently active users.
Is there any way to get actual client ids?

No, you cannot get that information with the Realtime Reporting API. Here is a list of all the dimensions and metrics that API allows you to query:
https://developers.google.com/analytics/devguides/reporting/realtime/dimsmets/
To expand on this a bit, none of the reporting APIs give you access to the client ID. You can, however, store the client ID in a custom dimension and send that along with all your hits. This will give you access to the client ID through the Core Reporting API, but it still won't give you access through the Realtime Reporting API.

Related

Google Analytics - a way to submit query from Query Explorer via API

There is an API in place and available to me (v4 compatible), but for various reasons it's not working correctly and there is not much time to fix it (too many other fires). So the idea was floated that that to bypass most of the issues with API here it might be a quick-fix to send whole query to GA.
It needs to be automated and results stored in our DB (Webservice on MS Stack), else we would do it manually all the way, which is out of the question at this time.
Hence the question:
IS there a way to submit a query that is exactly the product of a Query Explorer via API or any other way and retrieve it's results?
The API Query URI returned by the Query Explorer
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A78110423&start-date=30daysAgo&end-date=yesterday&metrics=ga%3Ametric1
Is for the Google Analytics v3 api. To use this in your own code you must simply attach a valid access token to the end of the request.
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A78110423&start-date=30daysAgo&end-date=yesterday&metrics=ga%3Ametric1&access_token=XXXX
This is not going to be using the Google Analytics v4 API that is a different call entirely.
Access tokens can be retrieved from either service account authentication or Oauth2 authentication and must be valid for the view you are requesting data for.

Get Google Analytics Data without Client Secrets

I am looking to make a web based app which creates a monthly report that has Google Analytics information in i.e. organic searches etc. Some clients will have their own Google Analytics accounts and wont be own mine.
I managed to get the OAuth 2 authorization working with my account however it wont work for clients as I needed to get the client_secret.json file from Google Developers website. I have seen a service like cyfe.com which just gets the google login information and outs the Google Analytics information in graphs and such.
Does anyone know how they manage this is possible without getting the client_secret.json file ?
oAuth2 is designed to let you access to users data with their permission, without requiring to access their password.
You should use your own client Id and client secret, these identify your application, not your users ("client" here means client of the API).
You then need to create an interface where users can allow your application to access to their data, from this you'll get an access token, allowing to your application to access to Google Analytics data of your user on their behalf.
Read "Using OAuth 2.0 to Access Google APIs", and identify the scenario that matches to what you want to achieve.
I strongly suggest that you use a library managing the authentication flow, you don't need to reinvent the wheel. Here's a list from Google: Google API Client Libraries.

How to GET data for multiple profile_ids in Google Analytics Reporting API?

Is there a way to fetch information for multiple ids in a single GA Reporting API query? See here for reference to the tool I am using: http://ga-dev-tools.appspot.com/explorer/
Tthe Google Analtyics core Reporting API is a little confusing. Core Reporting API - Reference Guide - Ids calls the Query Parameter ids but it is in fact singular. You can only send one id at a time.
Anwser: There is no way to send more then one view (profile_id) to the Core reporting api as a single request. You will need to loop over your request and send it multiple times.
Example:
https://www.googleapis.com/analytics/v3/data/ga?ids=ga:34896749&dimensions=ga:date&metrics=ga:entrances&start-date=2014-05-12&end-date=2014-05-22&oauth_token={OauthToken}
https://www.googleapis.com/analytics/v3/data/ga?ids=ga:34896744&dimensions=ga:date&metrics=ga:entrances&start-date=2014-05-12&end-date=2014-05-22&oauth_token={OauthToken}

Accessing Google Analytics Reports using the API

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.

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