Get started Stay organized with collections Save and categorize content based on your preferences.
Follow these steps to launch your first script.
Google Ads accounts
- Sign in to your Google Ads account.
- From the Tools menu in the left navigation, selectBulk actions, thenScripts. You can also navigate to this page by searching for "Scripts"in the Google Ads search bar.
- Press the + icon
to add ascript. You can browse script templates from the drop-down menu, but forthe sake of this exercise, select "New script".
- You can optionally provide a name for your script in the "Script name" textfield. This can help you stay organized and remember what the script does.
Copy and paste the following code into the editor area, replacing the mainfunction:
functionmain(){// Get the campaign names from all the campaignsconstrows=AdsApp.search('SELECT campaign.name FROM campaign');console.log('My campaigns:');// Iterate through the campaigns and print the campaign namesfor(constrowofrows){console.log(row.campaign.name);}}
When prompted, clickAuthorize so the script can access the account onyour behalf. This has to be done once for each script.
ClickPreview to run the script inpreview mode.Results will appear in theChanges /Logs panel. For this example,you should see your campaign names displayed in the Logs.
When you're happy with the preview results, clickRun to run yourscript and open theScript history page. This page displays themost recently run scripts, with information on their status and results.
To get a detailed view of changes and logs, click the link in theChanges column that corresponds to the script you just ran. You shouldsee the same log output that was previewed before.
Manager accounts
You must first have aGoogle Ads manageraccount to run Ads Manager scripts.
- Sign in to your Google Ads manageraccount.
- From the Tools menu in the left navigation, selectBulk actions, thenScripts. You can also navigate to this page by searching for "Scripts"in the Google Ads search bar.
- Press the + icon
to add ascript. You can browse script templates from the drop-down menu, but forthe sake of this exercise, select "New script".
- You can optionally provide a name for your script in the "Script name" textfield. This can help you stay organized and remember what the script does.
Copy and paste the following code into the editor area, replacing the mainfunction:
functionmain(){// Retrieve all children accounts.constaccountIterator=AdsManagerApp.accounts().get();// Iterate through the account list.for(constaccountofaccountIterator){// Get stats for the child account.conststats=account.getStatsFor("THIS_MONTH");// And log it.console.log(`${account.getCustomerId()},${stats.getClicks()},`+`${stats.getImpressions()},${stats.getCost()}`);}}
When prompted, clickAuthorize so the script can access the account onyour behalf. This has to be done once for each script.
ClickPreview to run the script inpreview mode.Results will appear in theChanges /Logs panel. For this example,you should see your children accounts and their metrics displayed in theLogs.
When you're happy with the preview results, clickRun to run yourscript and open theScript history page. This page displays themost recently run scripts, with information on their status and results.
To get a detailed view of changes and logs, click the link in theChanges column that corresponds to the script you just ran. You shouldsee the same log output that was previewed before.
For more sample script snippets, check out ourexamplespage.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-11 UTC.