Aggregating campaign report into campaign type

27 views
Skip to first unread message

Nicky Moorhead

unread,
May 12, 2021, 10:47:26 AM5/12/21
to Google Ads Scripts Forum
Hi,

I'm exporting data via a script from the campaign_performance_report. Part of my script looks like this:

function get_data(campaign_dict){
  var perf_data = [["Period","Campaign Type","Engine","Clicks","Impressions","Cost","Conversions","Conversion Value"]]
  var query = "SELECT AdvertisingChannelType, Impressions, Clicks, Cost, Conversions, ConversionValue FROM CAMPAIGN_PERFORMANCE_REPORT WHERE Impressions > 0 DURING LAST_7_DAYS";
   var rows = AdsApp.report(query).rows();
  while(rows.hasNext()){
    var row = rows.next();
    perf_data.push(["This Week",row['AdvertisingChannelType'],"Google",row['Clicks'],row['Impressions'],row['Cost'],row['Conversions'],row['ConversionValue']]);
  }
  return perf_data;
}

I want the data to be aggregated by campaign type which is why I'm not selecting the campaign from the select command but the script is currently returning data for each campaign separetely.

How can I get the data aggregated so the output only has a row for each campaign type?

Thank you.
Nicky 

Google Ads Scripts Forum Advisor

unread,
May 13, 2021, 11:39:55 PM5/13/21
to adwords...@googlegroups.com
Hi Nicky,

Thanks for reaching out. I am Harry from the Google Ads Scripts Team. Allow to assist you on this.

The Campaign Performance Report is aggregated by default at the campaign level, one row per campaign. If other segment fields are used, you may get more than one row per campaign. This would answer why the script would return data for each campaign separately. As the GROUP BY clause is not supported in AWQL, the only way to go about your requirement is to post process the report. You can loop through each value, sum them up, then append them in a new sheet or post process the report inside the Google Sheet directly.

Let me know if you would need further assistance.
 
Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 
 

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