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, select Bulk actions, then Scripts. You can also navigate to this page by searching for "Scripts" in the Google Ads search bar.
- Press the + icon
to add a script. You can browse script templates from the drop-down menu, but for the sake of this exercise, select "New script".
- You can optionally provide a name for your script in the "Script name" text field. This can help you stay organized and remember what the script does.
Copy and paste the following code into the editor area, replacing the main function:
function main() { // Get the campaign names from all the campaigns const rows = AdsApp.search('SELECT campaign.name FROM campaign'); console.log('My campaigns:'); // Iterate through the campaigns and print the campaign names for (const row of rows) { console.log(row.campaign.name); } }
When prompted, click Authorize so the script can access the account on your behalf. This has to be done once for each script.
Click Preview to run the script in preview mode. Results will appear in the Changes / Logs panel. For this example, you should see your campaign names displayed in the Logs.
When you're happy with the preview results, click Run to run your script and open the Script history page. This page displays the most recently run scripts, with information on their status and results.
To get a detailed view of changes and logs, click the link in the Changes column that corresponds to the script you just ran. You should see the same log output that was previewed before.
Manager accounts
You must first have a Google Ads manager account to run Ads Manager scripts.
- Sign in to your Google Ads manager account.
- From the Tools menu in the left navigation, select Bulk actions, then Scripts. You can also navigate to this page by searching for "Scripts" in the Google Ads search bar.
- Press the + icon
to add a script. You can browse script templates from the drop-down menu, but for the sake of this exercise, select "New script".
- You can optionally provide a name for your script in the "Script name" text field. This can help you stay organized and remember what the script does.
Copy and paste the following code into the editor area, replacing the main function:
function main() { // Retrieve all children accounts. const accountIterator = AdsManagerApp.accounts().get(); // Iterate through the account list. for (const account of accountIterator) { // Get stats for the child account. const stats = account.getStatsFor("THIS_MONTH"); // And log it. console.log(`${account.getCustomerId()},${stats.getClicks()},` + `${stats.getImpressions()},${stats.getCost()}`); } }
When prompted, click Authorize so the script can access the account on your behalf. This has to be done once for each script.
Click Preview to run the script in preview mode. Results will appear in the Changes / Logs panel. For this example, you should see your children accounts and their metrics displayed in the Logs.
When you're happy with the preview results, click Run to run your script and open the Script history page. This page displays the most recently run scripts, with information on their status and results.
To get a detailed view of changes and logs, click the link in the Changes column that corresponds to the script you just ran. You should see the same log output that was previewed before.
For more sample script snippets, check out our examples page.