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 [];
});
}