Script MCC for a daily report

422 views
Skip to first unread message

MyOrigines “MyOrigines” France

unread,
Jan 20, 2023, 1:12:59 AM1/20/23
to Google Ads Scripts Forum
    Hi everyone, 

I'm new with script and don't have any skills in dev....
I've tried to find existing scripts that I could adjust to my need but, so far, it is a big fail !


Here is what I'm looking for :

A MCC report for all campaigns (Perf max, shopping...) that will be updated every day while keeping previous data. 

Must have :
- ID Account
- Account name
- Campaign name
- Date 

- Impressions
- Clicks
- Cost + only take campaigns if cost >0
- Conversions
- Conversions Value
- Impression Share 

Nice to have :
- Campaign status (like limited by the budget....)
- Campaign daily budget
- Campaign recommanded budget (from the budget simulator, not sure this is possible...)

If someone have a script any close to this it would be great !

Thanks, 







Sigurd Fabrin

unread,
Jan 20, 2023, 7:04:40 AM1/20/23
to Google Ads Scripts Forum
You can build a report and add it to a spreadsheet daily.
Take a look at a campaign report to see what's available https://developers.google.com/google-ads/api/fields/v12/campaign_query_builder

Below is an example script you can modify. It logs (some of) yesterday's stats  across all accounts to a spreadsheet - below the stats from the day before

let settings = {
  url: 'https://docs.google.com/spreadsheets/etc',
  sheetName: 'Name of sheet'  
}
function main() {
  let accIter = AdsManagerApp.accounts()
    .get();
  while (accIter.hasNext()) {
    let account = accIter.next();
    AdsManagerApp.select(account) 
    let query =
       `SELECT
          segments.date,
          customer.id,
          customer.currency_code,
          campaign.id,
          metrics.clicks,
          metrics.cost_micros,
          metrics.conversions_value,
          campaign_budget.amount_micros        
        FROM
          campaign
        WHERE
          metrics.cost_micros > 0
        AND
          segments.date DURING YESTERDAY`
    let response = AdsApp.search(query);
    let data = [];
    while (response.hasNext()) {
      let row = response.next();
      let costs = (row.metrics.costMicros/1000000).toFixed(0);
      let revenue = (row.metrics.conversionsValue).toFixed(0);
      let roas = 0;
      if (revenue > 0) {roas = (revenue/costs).toFixed(1)};
      data.push([
        row.segments.date,
        row.customer.id,
        row.customer.currencyCode,
        row.campaign.id,
        (row.campaignBudget.amountMicros/1000000),
        row.metrics.clicks,
        costs,
        revenue,
        roas
        ])
    }
    data.unshift([ // headlines
      'Date',
      'Customer id',
      'Currency',
      'Campaign id',
      'Campaign budget',
      'Clicks',
      'Costs',
      'Revenue',
      'Roas'
    ])  
    let ss = SpreadsheetApp.openByUrl(settings.url);
    let sheet = ss.getSheetByName(settings.sheetName);
    let nextRow = sheet.getLastRow()+1;
    if (nextRow !== 1) {data.shift()} // only. headlines on 1st row
    sheet.getRange(nextRow,1,data.length,data[0].length).setValues(data);
  }
}



sigurd

Google Ads Scripts Forum

unread,
Jan 25, 2023, 1:39:52 AM1/25/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/IbfMx7dsTic) from the forum as it wasn't routed to our support queue. 

Cheers, 
James
Google Ads Scripts Team

Google Ads Scripts Forum Advisor

unread,
Jan 25, 2023, 4:01:02 AM1/25/23
to adwords...@googlegroups.com

Hello,

I'm James, a member the Google Ads Scripts Team. Thank you for raising your concern to our forum channel.

I believe that the code snippet provided by Sigurd are correct and can satisfy the needs of your use-case. However, if you have any further questions or concerns, please let us know. We’re here to assist you.

@Sigurd - Thank you for sharing your insights here. We greatly appreciate your continued support to our users here in our forum channel.

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2iNUhR:ref
Reply all
Reply to author
Forward
0 new messages