Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:49:16+00:00 2026-06-12T11:49:16+00:00

I am using Googles Analytics api in Javascript. They provide a method that gets

  • 0

I am using Googles Analytics api in Javascript.

They provide a method that gets the result of a list, once the execution is done it calls a callback method with the result.

Looks something like this:

gapi.client.analytics.management.accounts.list().execute(handleAccounts);

…

function handleAccounts(results) {
        if (!results.code) {
        if (results && results.items && results.items.length) {

// See this code below.

        } else {
            console.log('No accounts found for this user.')
        }
    } else {
        console.log('There was an error querying accounts: ' + results.message);
    }
}

Generally this is fantastic, however… I need a flattened list of all child items so I keep calling like this:

 $.each(results.items, function (index, value) {

gapi.client.analytics.management.webproperties.list({ 'accountId': value.Id}).execute(handleWebproperties);
// and so on..
            })

The problem being if at any level you have more than one item you end up with multiple asynchronous calls shooting off, and I won’t know when they have all finished to get the final list.

Other than writing something to keep track of how many calls have been made then waiting for that total to come back.

How can I easily know when they have all completed?

Thanks.

In summary:

A user can have multiple accounts, accounts can have multiple properties and properties can have multiple profiles.

I need all the profiles for all the accounts of a user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:49:17+00:00Added an answer on June 12, 2026 at 11:49 am

    You can use the jQuery Deferred features to do this sort of thing. Basically if you wrap the callbacks in a Deferred object, then use $.when(...) to group them all together.

    Something like this (the exact structure that will make the most sense for you will depend on how you’re using it, this code assumes you need to do something specific in each callback as well as know when they’re all done):

    var promises = [];
    $.each(results.items, function (index, value) {
        var deferred = new $.Deferred();
        gapi.client.analytics.management.webproperties.list({ 'accountId': value.Id}).execute(function(results) {
            handleWebproperties(results);
            deferred.resolve();
        });
        promises.push(deferred.promise());
        // and so on...
    });
    
    $.when.apply(this, promises).done(function() {
        alert("Everything is finished!");
    });
    

    Note I’m just coding straight into the browser window, so this may not be 100% functioning. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a Google Analytics API Class in PHP made by Doug Tan to
I'm using GAPI library (in PHP) for querying Google Analytics API. I request 2
I am using the Google API Client to access Google Analytics. I want to
I've been trying to retrieve Google analytics reports using their provided .NET api and
I am using google analytics event tracking to track 2 Facebook canvas application. (they
I wanna start using Google Analytics PHP API. I found 2 libraries and I
I am using the Google Analytics Api to get web property information from my
I'm trying to download the 'User Defined' variables using the google analytics API. The
I am using the GA Data Export API to interact with Google Analytics and
I was using Google Analytics API to show users of my CMS their visitor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.