Output the impressions of the sum of the campaign was filtered by campaign name that contains []

215 views
Skip to first unread message

Yu

unread,
Aug 8, 2014, 9:53:54 AM8/8/14
to adwords...@googlegroups.com
Hi everyone,

I want to output the impressions of the sum of the campaign that filter the campaign name that contains the [ABC]. 
If possible, please tell me the way.

Anash Oommen

unread,
Aug 8, 2014, 10:08:53 AM8/8/14
to adwords...@googlegroups.com
Hi Yu,

You could use a modified version of https://developers.google.com/adwords/scripts/docs/examples/campaigns#Get a campaign's stats. The change would be that the query changes to CampaignName CONTAINS 'ABC'

Cheers,
Anash P. Oommen,
AdWords Scripts Team.

Yu

unread,
Aug 8, 2014, 1:55:54 PM8/8/14
to adwords...@googlegroups.com
Thank you. 
However, it did not achieve its purpose in my understanding. 

As an alternative, I can use the AdWordsApp.report, I want to sum ​​the value of each campaign. 
I do not know how to sum ​​of each value in the present case. 
I am writing below the state of the current script.

function main() {
 
var spreadsheet_url = "Sheet URL";
 
var date_range = 'YESTERDAY';
 
var columns = ['Date',
                 
'Clicks',
 
'Impressions',
                 
'Ctr',
 
'AverageCpc',
                 
'Cost',
 
'AveragePosition',
                 
'Conversions',
                 
'CostPerConversion',
 
'ConversionRate'];
 
var columns_str = columns.join(',') + " ";
 
var obuSpreadsheet = SpreadsheetApp.openByUrl(spreadsheet_url);
 
var obuSheet = obuSpreadsheet.getSheetByName("NAME");
 
     
var sheet = obuSpreadsheet.setActiveSheet(obuSheet);
 
if(sheet.getRange('A1:A1').getValues()[0][0] == "") {
    sheet
.clear();
    sheet
.appendRow(columns);
 
}
   
 
var report_iter = AdWordsApp.report(
   
'SELECT ' + columns_str +
   
'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
   
'WHERE CampaignName CONTAINS "ABC" ' +
   
'DURING ' +date_range).rows();
   
 
while(report_iter.hasNext()) {
   
var row = report_iter.next();
   
var row_array = [];
   
for(var i in columns) {
       row_array
.push(row[columns[i]]);
   
}
    sheet
.appendRow(row_array);
 
};
 


}


2014年8月8日金曜日 23時08分53秒 UTC+9 Anash Oommen:

Anash Oommen

unread,
Aug 11, 2014, 3:11:54 PM8/11/14
to adwords...@googlegroups.com
Hi Yu,

If you don't use the Date segment, then each row will have the summed value as stat. If you add Date as a column, the data would be split by date and campaign, so you will need to add up the stats yourself. AdWords Scripts doesn't support the equivalent of SUM() in AdWords Query Language.

Cheers,
Anash P. Oommen,
AdWords Scripts Team.

Yu

unread,
Aug 12, 2014, 10:36:13 PM8/12/14
to adwords...@googlegroups.com
Thank you. I understand. 

function main() {
 
var campaignIterator = AdWordsApp.campaigns()
       
.withCondition('CampaignName CONTAINS "ABC"')
       
.get();
 
 
while (campaignIterator.hasNext()) {
   
var campaign = campaignIterator.next();
   
var stats = campaign.getStatsFor('YESTERDAY');
   
var imp =    stats.getImpressions();
 
   
Logger.log(imp + ' impressions, ');
 
}
}


Display the number of times each campaign has been output as a function of the above.
How do I get the total number of impressions?

2014年8月8日金曜日 23時08分53秒 UTC+9 Anash Oommen:
Hi Yu,

Anash Oommen

unread,
Aug 13, 2014, 11:56:08 AM8/13/14
to adwords...@googlegroups.com
Hi Yu,

You can modify your code something like this:

function main() {
 
var campaignIterator = AdWordsApp.campaigns()
       
.withCondition('CampaignName CONTAINS "ABC"')
       
.get();


 
var totalImpressions = 0;


 
while (campaignIterator.hasNext()) {
   
var campaign = campaignIterator.next();
   
var stats = campaign.getStatsFor('YESTERDAY');
   
var imp =    stats.getImpressions();

    totalImpressions
+= imp;
   
Logger.log(imp + ' impressions, ');
 
}
 
Logger.log("Total Impressions: %s", totalImpressions);
}

Cheers,
Anash P. Oommen,
AdWords Scripts Team.

Yu

unread,
Aug 26, 2014, 9:14:50 AM8/26/14
to adwords...@googlegroups.com
I am sorry. reply was delayed.
I was able to output the desired information.

Thank you.

2014年8月14日木曜日 0時56分08秒 UTC+9 Anash Oommen:
Reply all
Reply to author
Forward
0 new messages