Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you refer to the <a href="https://developers.google.com/apps-script/service_analytics" rel="nofollow">Analytics Service documentation</a>, you'll find that all the <code>.getItems()</code> methods return "a list of..." whatever, or arrays. Note that the example always referenced the first item of each array, <code>[0]</code>. So you just need to iterate over the returned arrays to get everything. </p> <p>This modified version of the function you referred to does just that, building up then returning an array of <code>allProfiles</code>. <em>(Corresponding changes to the rest of the example would need to be made to complete the reporting of this data.)</em></p> <pre><code>function getAllProfiles() { var accounts = Analytics.Management.Accounts.list(); var allProfiles = []; if (accounts.getItems()) { for (var acct in accounts.getItems()) { var accountId = accounts.getItems()[acct].getId(); var webProperties = Analytics.Management.Webproperties.list(accountId); if (webProperties.getItems()) { for (var prop in webProperties.getItems()) { var webPropertyId = webProperties.getItems()[prop].getId(); var profiles = Analytics.Management.Profiles.list(accountId, webPropertyId); if (profiles.getItems()) { for (var item in profiles.getItems()) { var profile = profiles.getItems()[item]; Logger.log(profile); allProfiles.push(profile); } } else { Logger.log('No profiles found [webProperty="' +webProperties.getItems()[prop].getName() +'"]'); } } } else { Logger.log('No webproperties found [account="' +accounts.getItems()[acct].getName() +'"]'); } } } else { Logger.log('No accounts found.'); } return allProfiles; } </code></pre> <p>Alternatively, if you know exactly what you want, just change the index values, which are all <code>[0]</code> in the example, referencing the first item in the first Webproperties list of the first account.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload