1

I'm building a dashboard that can show me the users for all the Google Analytics account that the user has access to.

So far I've been able to retrieve all the users for my accounts but it also lists users that have been deleted in the last 2 months. The users are listed on the restful api and the javascript api, but aren't listed when using the build-in user management dashboard in google analytics.

I've tried using the documentation example interface: Account User link as well as the javascript api with the same result.

Are the results for the management api cached, and if so can I force them to be updated?

code below:

function queryAccounts() {
    return gapi.client.analytics.management.accountSummaries.list();
}

function queryUsers(accountId) {
        const handle_paging = (res, items) => {
            if (res.result.nextLink !== undefined) {
                return gapi.client.analytics.management.accountUserLinks.list({
                    accountId: accountId,
                    startIndex: res.result.itemsPerPage + res.result.startIndex
                }).then(
                    page_res => handle_paging(page_res, items.concat(res.result.items)),
                    page_err => {
                        console.error(page_err);
                        return items;
                    });
            } else {
                return items.concat(res.result.items);
            }
        }

        return gapi.client.analytics.management.accountUserLinks.list({ accountId: accountId }).then(
            res => handle_paging(res, []),
            err => {
                console.error(err);
                return [];
            }
        )
    }

    function queryUsersAllWebProperties(accountId) {
        const handle_paging = (res, items) => {
            if (res.result.nextLink !== undefined) {
                return gapi.client.analytics.management.webpropertyUserLinks.list({
                    accountId: accountId,
                    webPropertyId: "~all",
                    "start-index": res.result.itemsPerPage + res.result.startIndex
                }).then(
                    page_res => handle_paging(page_res, items.concat(res.result.items)),
                    page_err => {
                        console.error(page_err);
                        return items;
                    });
            } else {
                return items.concat(res.result.items);
            }
        }

        return gapi.client.analytics.management.webpropertyUserLinks.list({
            accountId: accountId,
            webPropertyId: "~all"
        }).then(
            res => handle_paging(res, []),
            err => {
                console.error(err);
                return [];
            });
    }

1 Answers1

0

Account user links lists users with access to an Account Profile user links lists users with access to a profile. A user can have access to a profile without having access to an account. A user with access to an account will by default have access to all the profiles.

I think you should check in Google analytics and see where exactly the users were removed from the account level or the profile level. The google api returns data that exists it doesn't cache data or read from any other place. I would suggest that the users in question have not been deleted from the account.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Thanks for the quick response. First I thought this was the issue, but I've been through all the accounts, webproperties and profiles but cannot find the deleted account anywhere on the analytics management page. Nonetheless he still turns up in the api results. PS: I am retrieving the users for all 3 levels (account, webpropertie and profile) with their permissions on that level. – Joren Van de Vondel Jan 29 '18 at 09:53
  • You are logging in to the api with a user. make sure that its the same user you are logging in with on the Website. If they have different permissions you may not be able to see them. Also for the fun of it make sure your checking the right property :) – Linda Lawton - DaImTo Jan 29 '18 at 11:39
  • I'm using the same account for both the custom site and the Analytics management page. The account I'm using has the manage_users permission enabled on all 3 levels so I am able to see all the users for each level. I've double checked all three levels but cannot find the deleted users on any level in the Analytics management page. – Joren Van de Vondel Jan 29 '18 at 11:54
  • Test it here and verify that you are seeing users that are not in Google analytics web view https://developers.google.com/apis-explorer/#p/analytics/v3/ If you say there here as well i will send off an email to the team. Other wise i still thing its something in your code. Put up a https://stackoverflow.com/help/mcve while you are at it so we have something to test. – Linda Lawton - DaImTo Jan 29 '18 at 12:01
  • The deleted user is also listed on the Google APIs Explorer page. – Joren Van de Vondel Jan 29 '18 at 12:09
  • I sent off an email. I cant tell you how long it will take to hear back, it depends on how busy they are. Please post your code though so that they can see what it is exactly that you are doing. – Linda Lawton - DaImTo Jan 29 '18 at 12:23
  • @JorenVandeVondel can you contact me via this page. https://www.daimto.com/contact/ Google would like the account number so they can check this. They cant recreate it. – Linda Lawton - DaImTo Jan 31 '18 at 07:16