Hello,
We try to make programatic Performance Max campaign through Ads API with Listing Groups filter by conditions.
def create_listing_group_filter_operation(client, customer_id):
operations = []
operations.append(create_root(client, customer_id))
new_dimension = client.get_type("ListingGroupFilterDimension")
new_dimension.product_custom_attribute.index = (
client.enums.ListingGroupFilterCustomAttributeIndexEnum.INDEX2
)
new_dimension.product_custom_attribute.value = "xxxxxx"
operations.append(create_unit(client, customer_id, new_dimension, _TEMPORARY_ID_LISTING_GROUP_ROOT, 1))
empty_dimension = client.get_type("ListingGroupFilterDimension")
empty_dimension.product_custom_attribute._pb.SetInParent()
operations.append(
create_unit(client, customer_id, empty_dimension, _TEMPORARY_ID_LISTING_GROUP_ROOT, 0,
)
)
return operations
def create_root(client, customer_id):
googleads_service = client.get_service("GoogleAdsService")
mutate_operation = client.get_type("MutateOperation")
asset_group_listing_group_filter = (
mutate_operation.asset_group_listing_group_filter_operation.create
)
asset_group_listing_group_filter.resource_name = googleads_service.asset_group_listing_group_filter_path(
customer_id, _ASSET_GROUP_TEMPORARY_ID, _TEMPORARY_ID_LISTING_GROUP_ROOT
)
asset_group_listing_group_filter.asset_group = googleads_service.asset_group_path(
customer_id, _ASSET_GROUP_TEMPORARY_ID
)
asset_group_listing_group_filter.type_ = (
client.enums.ListingGroupFilterTypeEnum.SUBDIVISION
)
asset_group_listing_group_filter.vertical = (
client.enums.ListingGroupFilterVerticalEnum.SHOPPING
)
return mutate_operation
def create_unit(client, customer_id, dimension, parent, onoff):
global _next_temp_id
googleads_service = client.get_service("GoogleAdsService")
mutate_operation = client.get_type("MutateOperation")
asset_group_listing_group_filter = (
mutate_operation.asset_group_listing_group_filter_operation.create
)
asset_group_listing_group_filter.resource_name = googleads_service.asset_group_listing_group_filter_path(
customer_id, _ASSET_GROUP_TEMPORARY_ID, _next_temp_id
)
asset_group_listing_group_filter.asset_group = googleads_service.asset_group_path(
customer_id, _ASSET_GROUP_TEMPORARY_ID
)
asset_group_listing_group_filter.parent_listing_group_filter = googleads_service.asset_group_listing_group_filter_path(
customer_id, _ASSET_GROUP_TEMPORARY_ID, parent
)
ce = client.enums.ListingGroupFilterTypeEnum.UNIT_INCLUDED
if onoff == 0:
ce = client.enums.ListingGroupFilterTypeEnum.UNIT_EXCLUDED
asset_group_listing_group_filter.type_ = (
ce
)
asset_group_listing_group_filter.vertical = (
client.enums.ListingGroupFilterVerticalEnum.SHOPPING
)
asset_group_listing_group_filter.case_value = dimension
_next_temp_id -= 1
return mutate_operation
Also if we use other dimension from ListingGroupFilterDimension (like product_condition) to custom the Listing Group this code is working.
There is any custom aproach for filter by Custom Label ?
Many thanks for any suggestions,
Radu.