Stay organized with collections
Save and categorize content based on your preferences.
The Analytics Admin service allows you to use the Google Analytics Admin API v1
in Apps Script. The Google Analytics Admin API allows for programmatic access
to the Google Analytics 4 (GA4) configuration data and is only compatible with GA4 properties.
Like all advanced services in Apps Script, the AnalyticsAdmin service uses the
same objects, methods, and parameters as the public API. For more information,
see How method signatures are determined.
/** * 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);}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-18 UTC."],[[["\u003cp\u003eThe Analytics Admin service in Apps Script enables programmatic access to Google Analytics 4 (GA4) configuration data using the Google Analytics Admin API v1.\u003c/p\u003e\n"],["\u003cp\u003eIt is an advanced service that requires enabling before use and is exclusively compatible with GA4 properties.\u003c/p\u003e\n"],["\u003cp\u003eThis service mirrors the objects, methods, and parameters of the public API, providing consistent functionality.\u003c/p\u003e\n"],["\u003cp\u003eSupport and issue reporting can be found on the Google Analytics Admin API v1 support page.\u003c/p\u003e\n"],["\u003cp\u003eA provided sample code demonstrates listing all Google Analytics accounts accessible to the current user.\u003c/p\u003e\n"]]],[],null,["# Analytics Admin Service\n\nThe Analytics Admin service allows you to use the [Google Analytics Admin API v1](/analytics/devguides/config/admin/v1)\nin Apps Script. The Google Analytics Admin API allows for programmatic access\nto the Google Analytics 4 (GA4) configuration data and is only compatible with GA4 properties.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the [Google Analytics Admin API v1](/analytics/devguides/config/admin/v1/rest).\n\nLike all advanced services in Apps Script, the AnalyticsAdmin service uses the\nsame objects, methods, and parameters as the public API. For more information,\nsee [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Google Analytics Admin API v1 support page](/analytics/devguides/config/admin/v1/help).\n\nSample code\n-----------\n\n### Run a report\n\nThe sample lists all the Google Analytics accounts available to a user by calling\nthe [accounts.list()](/analytics/devguides/config/admin/v1/rest/v1alpha/accounts/list)\nmethod. \nadvanced/analyticsAdmin.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/analyticsAdmin.gs) \n\n```javascript\n/**\n * Logs the Google Analytics accounts accessible by the current user.\n */\nfunction listAccounts() {\n try {\n accounts = AnalyticsAdmin.Accounts.list();\n if (!accounts.items || !accounts.items.length) {\n console.log('No accounts found.');\n return;\n }\n\n for (let i = 0; i \u003c accounts.items.length; i++) {\n const account = accounts.items[i];\n console.log('Account: name \"%s\", displayName \"%s\".', account.name, account.displayName);\n }\n } catch (e) {\n // TODO (Developer) - Handle exception\n console.log('Failed with error: %s', e.error);\n }\n}\n```"]]