アナリティクス管理サービスを使用すると、Apps Script で Google Analytics Admin API v1 を使用できます。Google アナリティクス Admin API を使用すると、Google アナリティクス 4(GA4)の設定データにプログラムでアクセスできます。この API は GA4 プロパティとのみ互換性があります。
/** * Logs the Google Analytics accounts accessible by the current user. */functionlistAccounts(){try{accounts=AnalyticsAdmin.Accounts.list();if(!accounts.items||!accounts.items.length){console.log('No accounts found.');return;}for(leti=0;i < accounts.items.length;i++){constaccount=accounts.items[i];console.log('Account: name "%s", displayName "%s".',account.name,account.displayName);}}catch(e){// TODO (Developer) - Handle exceptionconsole.log('Failed with error: %s',e.error);}}