I have many Analytics properties and accounts.
I am now working on JavaScript to get the reports from the Google Analytics API.
In order to make these requests I need the view idea for the account i wish to access so that i can load the related data from the backed.
The only way i have found to find these view ids is to use the Official GA Query Explorer every time to get the id by selecting Account and Property.
This is quite annoying. Because it involves human action.
Is there any way I can look up the id by the UA-xxxx
string?
If you are already using the Google Analtyics API to get the reports why not use the Management APi to get a list of all the accounts the user has access to
Account summeries.list will give you that.
I am not a Javascript developer but the code should be something like this.
function queryAccounts() {
// Load the Google Analytics client library.
gapi.client.load('analytics', 'v3').then(function() {
// Get a list of all Google Analytics accounts for this user
gapi.client.analytics.management.accountSummaries.list().then(handleAccounts);
});
}
Code shamelessly ripped from Hello Analytics API: JavaScript quickstart for web applications and altered a bit using a wild guess.