How to use GG Script to get Ad report daily any syn to google sheet

168 views
Skip to first unread message

Xindy

unread,
Mar 30, 2023, 8:56:40 AM3/30/23
to Google Ads Scripts Forum
Hello  Google Ads Scripts,

I'm new with script and don't have any skills in dev (Not good in english)
And I need your help

A MCC report for all campaigns  that will be updated every day (I think that I can set on frequency on script menu)

- Auto sync to google sheet (Publich share : Edit)
- Google sheet include header colum : Date | Campaign name | Cost
- Sheet name : RAW_REPORT
- Period : 1 JAN 2023 - 31 DEC 2023

So I'm try some code that from ChatGPT and it not show the result of report but show like this If everybody have a script any close to this it would be great.

Date Campaign name Cost
Date Campaign name Cost
Date Campaign name Cost
Date Campaign name Cost
Date Campaign name Cost
Date Campaign name Cost


let settings = {
  url: 'https://docs.google.com/spreadsheets/d/?????????/edit',
  sheetName: 'RAW_REPORT'  
}

function main() {
  let accIter = AdsManagerApp.accounts().get();
  let data = [];
  while (accIter.hasNext()) {
    let account = accIter.next();
    AdsManagerApp.select(account);
    let query =
      `SELECT
         segments.date,
         campaign.name,
         metrics.cost_micros
       FROM
         campaign
       WHERE
         metrics.cost_micros > 0
       AND
            segments.date >= '20230101'
       AND
            segments.date <= '20231231'`;
       
    let response = AdsApp.report(query);
    let rows = response.rows();
    while (rows.hasNext()) {
      let row = rows.next();
      if (row.length > 0) {
        let date = row['segments.date'];
        let campaignName = row['campaign.name'];
        let cost = row['metrics.costMicros'];
        data.push([date, campaignName, cost]);
      }
    }
  }
  data.unshift(['Date', 'Campaign name', 'Cost']);
  let ss = SpreadsheetApp.openByUrl(settings.url);
  let sheet = ss.getSheetByName(settings.sheetName);
  sheet.getRange(1, 1, data.length, data[0].length).setValues(data);
}

Google Ads Scripts Forum

unread,
Mar 30, 2023, 9:42:40 AM3/30/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/EuNBVlCFo0g) from the forum as it wasn't routed to our support queue. 

Regards, 
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Mar 31, 2023, 4:33:33 AM3/31/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/EuNBVlCFo0g) from the forum as it wasn't routed to our support queue.

Regards,
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Mar 31, 2023, 4:43:11 AM3/31/23
to Google Ads Scripts Forum
Hi, Thank you for reaching out to the Google Ads Scripts Team. Please excuse us for only getting back now as your message failed to be routed to our support queue. Kindly see my insights below:


  • First, if you are executing this script at the Manager account-level, I would suggest checking out this guide explaining how to work on client accounts for you to properly do so.
  • Next, I would like to recommend this link for an example on how you can create a report via Google Ads Scripts. To help you in creating a query with the campaign report type, you can check this query builder of the said report type from the Google Ads API documentation. After building your query, you may implement it within your script's query.
  • After that, I could recommend for you to follow this guide on how to export a report's results to a spreadsheet after creating a report.
For a guide on how you can set the frequency of a script, you can check this Ads help center article under Scheduling a script. Let us know if you have any further clarifications. Best regards, Google Ads Scripts Team
Reply all
Reply to author
Forward
0 new messages