Search term script

26 views
Skip to first unread message

Daniel Brandes

unread,
Jul 17, 2024, 11:41:55 AM (10 days ago) Jul 17
to Google Ads Scripts Forum
I'm looking to create a script that will display my search terms on a spreadsheet for my performance max campaign, however, the following code is only generating the first column of labels with no info on actual search terms that triggered my ad. Can you confirm that this code is accurate. (I have not included the URL to the spreadsheet so please disregard that aspect of the code.

_______________________________________________________________________________________

function main() { // Define the output spreadsheet URL var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL_HERE'; // Open the spreadsheet and select the first sheet var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL); var sheet = spreadsheet.getSheets()[0]; // Clear any existing data sheet.clear(); // Set up the headers for the report sheet.appendRow([ 'Campaign ID', 'Campaign Name', 'Ad Group ID', 'Ad Group Name', 'Search Term', 'Impressions', 'Clicks', 'Cost' ]); // Define the query to retrieve Performance Max campaign data var query = ` SELECT campaign.id, campaign.name, ad_group.id, ad_group.name, search_terms.query, metrics.impressions, metrics.clicks, metrics.cost_micros FROM search_term_view WHERE campaign.advertising_channel_type = 'PERFORMANCE_MAX' ORDER BY metrics.impressions DESC `; // Execute the query and process the results var report = AdsApp.report(query); var rows = report.rows(); while (rows.hasNext()) { var row = rows.next(); var cost = row['metrics.cost_micros'] / 1000000; // Convert micros to currency sheet.appendRow([ row['campaign.id'], row['campaign.name'], row['ad_group.id'], row['ad_group.name'], row['search_terms.query'], row['metrics.impressions'], row['metrics.clicks'], cost.toFixed(2) ]); } Logger.log('Report completed successfully!'); }  

Google Ads Scripts Forum Advisor

unread,
Jul 17, 2024, 2:11:34 PM (10 days ago) Jul 17
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

I would like to inform you that the field “search_terms.query” you are using in the ‘query’ variable. I would suggest that you use “search_term_view.search_term” in place of the above field. Also, refer to the Google Ads Query Builder document build and validate a sample query for the available fields and metrics.

I hope this helps! Kindly reach out to us with the below details if you still face any issue.

  • Google Ads account ID/CID
  • Name of the affected script
  • Shareable spreadsheet link that you are using in the script
You can share the requested details via Reply privately to the author option or a direct private reply to this email. If this option is not available on your end, you may send it through our email (googleadsscr...@google.com) instead.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vDkCT:ref" (ADR-00252898)

Thanks,
 
Google Logo Google Ads Scripts Team


Reply all
Reply to author
Forward
0 new messages