Get started

  • You can launch your first script in both Google Ads accounts and Manager accounts by navigating to "Scripts" under "Bulk actions" in the Tools menu.

  • Adding a script involves pressing the '+' icon, selecting "New script" (or a template), and optionally naming it.

  • You need to copy and paste the provided code into the editor area and authorize the script to access your account.

  • Scripts can be run in preview mode to check results before running them officially.

  • The Script history page shows the status and results of recently run scripts, with detailed changes and logs available by clicking the link in the "Changes" column.

Follow these steps to launch your first script.

  1. Sign in to your Google Ads account.
  2. 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.
  3. Press the + iconblue circle with white plusto add a script. You can browse script templates from the drop-down menu, but for the sake of this exercise, select "New script".
  4. 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.
  5. 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 
     ); 
      
     } 
     } 
     
    
  6. When prompted, click Authorizeso the script can access the account on your behalf. This has to be done once for each script.

  7. Click Previewto run the script in preview mode . Results will appear in the Changes/ Logspanel. For this example, you should see your campaign names displayed in the Logs.

  8. When you're happy with the preview results, click Runto run your script and open the Script historypage. This page displays the most recently run scripts, with information on their status and results.

  9. To get a detailed view of changes and logs, click the link in the Changescolumn 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.

  1. Sign in to your Google Ads manager account.
  2. 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.
  3. Press the + iconblue circle with white plusto add a script. You can browse script templates from the drop-down menu, but for the sake of this exercise, select "New script".
  4. 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.
  5. 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 
     () 
     } 
     ` 
     ); 
      
     } 
     } 
     
    
  6. When prompted, click Authorizeso the script can access the account on your behalf. This has to be done once for each script.

  7. Click Previewto run the script in preview mode . Results will appear in the Changes/ Logspanel. For this example, you should see your children accounts and their metrics displayed in the Logs.

  8. When you're happy with the preview results, click Runto run your script and open the Script historypage. This page displays the most recently run scripts, with information on their status and results.

  9. To get a detailed view of changes and logs, click the link in the Changescolumn 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 .

Design a Mobile Site
View Site in Mobile | Classic
Share by: