Failed to update bid_modifier as 0.0 to opt out device with CampaignCriterionService

66 views
Skip to first unread message

Wenjun Yang

unread,
Nov 17, 2022, 4:17:40 AM11/17/22
to Google Ads API and AdWords API Forum
Hi Team,

Below is my code to opt out some Tablet and Desktop from Display Campaign

from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException
from google.api_core import protobuf_helpers

campaign_criterion_service = src_client.get_service("CampaignCriterionService")
ops = []
criterion_id_list = ['30000', '30002']
for criterion_id in criterion_id_list:
    criterion_rname = campaign_criterion_service.campaign_criterion_path(
        src_customer_id, src_campaign_id, criterion_id
    )
    print(f"criterion_rname={criterion_rname}")
    campaign_criterion_operation = src_client.get_type("CampaignCriterionOperation")
    campaign_criterion = campaign_criterion_operation.update
    campaign_criterion.resource_name = criterion_rname
    campaign_criterion.bid_modifier = 0.0       # 设置为0.0 进行排除
    src_client.copy_from(
        campaign_criterion_operation.update_mask,
        protobuf_helpers.field_mask(None, campaign_criterion._pb),
    )
    ops.append(campaign_criterion_operation)

result_res_names = []
for row in campaign_criterion_service.mutate_campaign_criteria(
        customer_id=src_customer_id, operations=ops
).results:
    print(
        "Update Campaign Criteria with resource name: "
        f'"{row.resource_name}".'
    )
    result_res_names.append(row.resource_name)


Script run without error message, but it does not work. From UI, the device part does not opt out Desktop and Tablet as below screenshot.
error-sample-2022-11-17.png

I query with SQL as below, the bid value is not 0.0 as expected
query = f"""
select
    campaign.id,
    campaign_criterion.resource_name,
    campaign_criterion.type,
    campaign_criterion.status,
    campaign_criterion.criterion_id,
    campaign_criterion.bid_modifier,
    campaign_criterion.display_name,
    campaign_criterion.negative
from campaign_criterion
WHERE campaign.id = {src_campaign_id}
      and campaign_criterion.type = DEVICE
"""

I made a sample request and log as below. please help with this.
2022-11-17 09:01:23,095 [INFO] logging_interceptor.py@228 - log_successful_request(): Request made: ClientCustomerId: xxxxxx, Host: googleads.googleapis.com, Method: /google.ads.googleads.v11.services.CampaignCriterionService/MutateCampaignCriteria, RequestId: MCjVF87FC6PjR08Zc0Gkzw, IsFault: False, FaultMessage: None

customer id is replaced with xxxxx


Thanks!
Wenjun

Google Ads API Forum Advisor

unread,
Nov 17, 2022, 8:31:56 AM11/17/22
to wenju...@webeye.com, adwor...@googlegroups.com

Hi Wenjun,

Thanks for reaching out to the Google Ads API Forum.

Since you mentioned that Python script runs without error messages, it does not work as Ads UI, the device part does not opt out Desktop and Tablet. To investigate further, could you provide us the following details via reply privately to author option?

  • Complete logs in the format of the request and response logs generated for CampaignCriterionService(without redacted)
  • Complete Ads UI screenshot without cropping


For you to enable complete logs on your end for the Python client library, logging can be enabled by navigating to the Client libraries > Your client library (select Python) > Logging documentation, which you can access from this link.  

Regards,

Google Logo
Yasar
Google Ads API Team
 


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