Steal my 'Script 101' Template

Use this basic template to pull data on virtually anything from Google Ads & push that data to a Sheet.

You don’t need to know any code at all.

Paste this script into your Google Ads account, use the Query Builder (see Mastery section) to create the SQL for the data you need, create a new blank Sheet, paste in the URL & hit ‘Run’.

That’s it.

Here’s the code:

// Enter your Google Sheet URL here between the single quotes
const SHEET_URL = '';
const GAQL_QUERY = `

{replace this with your SQL}

`;
function main() {
  let sheet = SpreadsheetApp.openByUrl(SHEET_URL).getActiveSheet();  
  let query = AdsApp.report(GAQL_QUERY);
  query.exportToSheet(sheet); 
}


Just delete the line ‘{replace this with your SQL}’
And paste your SQL from Query Builder in that space - just make sure not to delete the 2 ` (called backticks) above & below that section.


And here’s a slightly more complicated example - just so you can see what’s possible:

// ------------------------------
// USER CONFIGURATION SECTION
// ------------------------------

// Enter your Google Sheet URL here between the single quotes
const SHEET_URL = '';

// Enter the name of the sheet/tab where you want the data to be exported
const TAB_NAME = 'Sheet1';

// Enter your GAQL query here
const GAQL_QUERY = `
  SELECT 
    search_term_view.search_term, 
    search_term_view.status, 
    campaign.name,
    metrics.impressions, 
    metrics.clicks, 
    metrics.cost_micros, 
    metrics.conversions, 
    metrics.conversions_value
  FROM 
    search_term_view
  WHERE 
    segments.date DURING LAST_30_DAYS
    AND metrics.cost_micros > 1000000
    AND campaign.advertising_channel_type = "SEARCH"
`;

function main() {
  let ss = SpreadsheetApp.openByUrl(SHEET_URL);  
  let sheet = ss.getSheetByName(TAB_NAME);  
  let query = AdsApp.report(GAQL_QUERY);
  query.exportToSheet(sheet);
  
}