How to access a campaigns targetCPA

262 views
Skip to first unread message

CR EG

unread,
Aug 9, 2018, 12:55:27 AM8/9/18
to AdWords API and Google Ads API Forum
Hey all!

I am having some difficulty trying to pull the targetCPA for a specific campaign. Here is what I have, I am using the selector to pull the campaign that I need but when I look at the attributes returned it does not provide the bidding strategy details. 

campaign_service = client.GetService('CampaignService', version='v201802')

    selector = {
        'fields': ['Name'],
        'predicates': {
            'field': 'Id',
            'operator': 'EQUALS',
            'values': campaignID
        }
    }

    campaign = campaign_service.get(selector)



Here is What is returned

{
    'totalNumEntries': 1,
    'Page.Type': 'CampaignPage',
    'entries': [
        {
            'id': *********,
            'campaignGroupId': None,
            'name': '***********',
            'status': None,
            'servingStatus': None,
            'startDate': None,
            'endDate': None,
            'budget': None,
            'conversionOptimizerEligibility': None,
            'adServingOptimizationStatus': None,
            'frequencyCap': None,
            'settings': [],
            'advertisingChannelType': None,
            'advertisingChannelSubType': None,
            'networkSetting': None,
            'labels': [],
            'biddingStrategyConfiguration': None,
            'campaignTrialType': None,
            'baseCampaignId': None,
            'forwardCompatibilityMap': [],
            'trackingUrlTemplate': None,
            'finalUrlSuffix': None,
            'urlCustomParameters': None,
            'vanityPharma': None,
            'selectiveOptimization': None
        }
    ]
}


Anyone have any idea? 


Peter Oliquino (AdWords API Team)

unread,
Aug 9, 2018, 2:39:23 AM8/9/18
to AdWords API and Google Ads API Forum
Hi,

Using the CampaignService.get(), you will need to include the BiddingStrategyConfiguration in your selected fields then once retrieved through the Campaign object, create an object of its type. You can then extract its BiddingScheme that would then allow you to identify whether it is a TargetCpaBiddingScheme and then get its TargetCpa value.

Thanks and regards,
Peter
AdWords API Team

华阳

unread,
Aug 10, 2018, 5:58:32 AM8/10/18
to AdWords API and Google Ads API Forum
Get an exception when trying to add "" as select field.

AdWordsApiException: Exception of type 'Google.Api.Ads.AdWords.Lib.AdWordsApiException' was thrown.
The field name is not valid.. (Error: SelectorError.INVALID_FIELD_NAME, FieldPath: serviceSelector, Trigger: biddingStrategyConfiguration)


Selector selector = new Selector()
                                        {
                                            fields = new[] { "biddingStrategyConfiguration" },
                                            predicates = new Predicate[] { Predicate.Equals(Campaign.FilterableFields.Status, "ENABLED"), },
                                            paging = Paging.Default
                                        };

Peter Oliquino (AdWords API Team)

unread,
Aug 13, 2018, 3:07:41 AM8/13/18
to AdWords API and Google Ads API Forum
Hi,

My apologies for the mistake. In your Selector, you need to include the "BiddingStrategyType" and "TargetCpa" campaign fields. When processing the results, you may then provide a condition to filter only those bidding strategies that are of type TARGET_CPA, if you have strategies aside from the one I mentioned.

Using Java, I was able to extract the information by using the code snippet below :

if (campaign.getBiddingStrategyConfiguration().getBiddingStrategyType().toString().equals("TARGET_CPA")) {
           
            BiddingScheme biddingScheme = campaign.getBiddingStrategyConfiguration().getBiddingScheme();
            TargetCpaBiddingScheme targetCPAScheme = (TargetCpaBiddingScheme) biddingScheme;
            String targetCpaValue = targetCPAScheme.getTargetCpa().toString();
            
            System.out.printf("Campaign with name '%s' and ID %d and targetCpa '%s' was found.%n", campaign.getName(),
                campaign.getId(), targetCpaValue);
            
          }

Let me know if this helps.

Thanks and regards,
Peter
AdWords API Team


shean

unread,
Aug 29, 2018, 6:29:34 AM8/29/18
to AdWords API and Google Ads API Forum
Hi,

i have the same issue

after use the code, i always get instance no attribute 'getBiddingStrategyConfiguration'

i use python
more_pages = True
while more_pages:
    page
= service.get(selector)


   
# Display results
    if 'entries' in page:
       
for campaign in page['entries']:

               
print('Campaign with id "%s", name "%s", and status "%s" was '
                      'found, url "%s".' % (campaign['id'], campaign['name'], campaign['status']))

            if campaign.getBiddingStrategyConfiguration():
               
print('in')
   
else:
       
print ('No campaigns were found')
    offset
+= PAGE_SIZE
    selector
['paging']['startIndex'] = str(offset)
    more_pages
= offset < int(page['totalNumEntries'])

response
Campaign instance has no attribute 'getBiddingStrategyConfiguration'


thanks

Peter Oliquino (AdWords API Team)於 2018年8月13日星期一 UTC+8下午3時07分41秒寫道:

Peter Oliquino (AdWords API Team)

unread,
Aug 30, 2018, 2:17:53 AM8/30/18
to AdWords API and Google Ads API Forum
Hi,

Your issue appears to be more related to the Python client library. Also, we currently have no sample codes or documentation that demonstrates how the field is retrieved using Python. You may try and contact the library owners via this link for further assistance.

Thanks and regards,
Peter
AdWords API Team

Reply all
Reply to author
Forward
0 new messages