How to get a campaign performance report for list of campaign IDs?

303 views
Skip to first unread message

Nellle Rickchards

unread,
May 9, 2018, 5:19:11 PM5/9/18
to AdWords API and Google Ads API Forum
Hello,

I have a list of campaign ID's and I need to download the campaign performance report for them

Here is my code:
campaign_performance_report = [(adwords.ReportQueryBuilder()
                                       .Select('Date', 'CampaignId', 'AdNetworkType2',
                                               'Impressions', 'Clicks', 'Ctr', 'AverageCpc', 'Cost',
                                               'Conversions', 'ConversionRate', 'AllConversionValue', 'ClickAssistedConversions',
                                               'AveragePosition', 'CampaignStatus')
                                       .From('CAMPAIGN_PERFORMANCE_REPORT')
                                       .Where('CampaignStatus').In('ENABLED', 'PAUSED')
                                       .During('YESTERDAY')
                                       .Build()),
                               # report name
                               "campaign_performance_report",
                               # report zerp imp
                               False]

Do I need to run that through a loop and specify the campaignID as my Where argument?

I don't want to download the reports for my entire account.

Luis Xander Talag (AdWords API Team)

unread,
May 9, 2018, 11:56:45 PM5/9/18
to AdWords API and Google Ads API Forum
Hi Nellle,

If you have a list of campaignIds, you can use the IN operator or .In operator in Python then put your campaignIds as its values just like the CampaignStatus sample in your code snippet. Let me know if this works.

Thanks and regards,
Luis
AdWords API Team

Nellle Rickchards

unread,
Jun 1, 2018, 9:38:25 AM6/1/18
to AdWords API and Google Ads API Forum
Hello,

Thanks! I'm running into a small issue.

Causes Error:
campaign_ids = ['11111','11112','11113']   
query = (adwords.ServiceQueryBuilder()
             .Select('Id')
             .Where('Id').In(campaign_ids)
             .Build())

No Errors:
query = (adwords.ServiceQueryBuilder()
             .Select('Id')
             .Where('Id').In('11111','11112','11113')
             .Build())

Is  there a way to add a list of campaign ids to the where clause? 

Vincent Racaza (AdWords API Team)

unread,
Jun 3, 2018, 11:00:19 PM6/3/18
to AdWords API and Google Ads API Forum
Hi Nellle,

Yes, I can confirm that passing a variable to AWQL type of generating reports in Python would generate an error. If you really want to use a variable in storing your campaign IDs as filter, then I would recommend to use the selector type in generating reports. Below is a sample code snippet which works on my end:

  campaign_ids = ['XXXXXXXX', 'XXXXXXXX'];


 
# Create report definition.
  report
= {
     
'reportName': 'Last 7 days CAMPAIGN_PERFORMANCE_REPORT',
     
'dateRangeType': 'LAST_7_DAYS',
     
'reportType': 'CAMPAIGN_PERFORMANCE_REPORT',
     
'downloadFormat': 'CSV',
     
'selector': {
         
'fields': ['CampaignId','Clicks', 'Cost'],
         
'predicates': {
             
'field': 'CampaignId',
             
'operator': 'IN',
             
'values': campaign_ids
         
}
     
}
 
}

Kindly do this and let me know how it goes.

Thanks,
Vincent
AdWords API Team
Reply all
Reply to author
Forward
0 new messages