Search code examples
google-analyticsgoogle-apigoogle-analytics-api

Query multiple ID's on Google Analytics Javascript API


I'm using Google Analytic's API for javascript.

I'm performing a query for the user's count of a data range, and passing the view ID to the query:

gapi.client.analytics.data.ga.get({
    'ids': 'ga:XXXXXXXX',
    'start-date': '2014-10-01',
    'end-date': '2014-10-15',
    'metrics': 'ga:users'
}).execute(function (results) {
    if (results.rows && results.rows.length)
        console.log(results.rows[0][0]);
});

However, since I'm dealing with the quotas of usage, and I needed to query for multiple views.

Is there a way to request the report for more than one id in the same query?

Something like:

 gapi.client.analytics.data.ga.get({
    'ids': 'ga:XXXXXXXX, ga:XXXXXXXXX, ga:XXXXXXXXXX', //Which obviously doesn't work

Solution

  • Answer: No there is no way to request more then one profile id

    Google Analtyics Reporting API reference

    ids=ga:12345 The unique table ID of the form ga:XXXX, where XXXX is the Analytics view (profile) ID for which the query will retrieve the data.

    Even though it is called IDS does not mean that you can send more then one. You can't you can only send one at a time. It is a unique value you are going to have to run your request several times. If you think about it this makes sense as the data you would be getting back would be mixed up between the different profile id's you wouldn't be able to tell which profile the data came from as profile is not a dimension.