Page Summary
-
Demand Gen campaigns offer unique audience targeting features not found in other campaign types.
-
You can use Lookalike audience segments to target users similar to existing audiences.
-
Audience targeting can be configured at the ad group level using
AdGroupCriterion.
Demand Gen campaigns offer unique audience targeting features not supported by other campaign types.
For example, you can use Lookalike audience segments to target users who share characteristics with your existing customers. Read more about Lookalike segments in the Help Center article Use Lookalike segments to grow your audience.
Additionally, you can configure audience targeting at the ad group
level using AdGroupCriterion.
AudienceInfo targeting criteria
Targeting an audience in a Demand Gen ad group requires the following steps:
- When creating the target
AdGroup, setaudience_setting.use_audience_groupedtotrue(this setting is immutable after the ad group is created). You can also optionally setcampaign.audience_setting.use_audience_groupedtotruewhen creating the campaign to prevent segment and demographic exclusions at the campaign level. - Create or retrieve an
Audienceresource usingAudienceServiceand obtain its resource name or ID. - Create an
AdGroupCriterionwith anAudienceInfocriterion whoseaudiencefield is set to the audience's resource name.
Inspect MutateAudienceResult and attach AudienceInfo
When creating an audience with AudienceService.MutateAudiences,
each operation returns a MutateAudienceResult. You can
obtain the audience_id by parsing the returned resource_name, and you can
inspect mutable fields (such as name) on the returned audience object when
response_content_type is set to MUTABLE_RESOURCE. Then assign the
resource_name to an AdGroupCriterion on an AdGroup
created with audience_setting.use_audience_grouped set
to true, and wrap the AdGroupCriterion in an
AdGroupCriterionOperation passed to
AdGroupCriterionService.MutateAdGroupCriteria:
# Step 1: Inspect MutateAudienceResult to get resource_name and audience_id.
for result in response.results:
resource_name = result.resource_name
# Format: customers/{customer_id}/audiences/{audience_id}
audience_id = audience_service.parse_audience_path(resource_name)[
"audience_id"
]
print(
f"Created audience with resource_name '{resource_name}' "
f"and audience_id '{audience_id}'."
)
# Access mutable fields on result.audience when MUTABLE_RESOURCE is set:
if result.audience.resource_name:
print(f"Audience name from mutable resource: {result.audience.name}")
# Step 2: Target the audience at the ad group level with AdGroupCriterion.
# The target AdGroup must have audience_setting.use_audience_grouped = True
# set when the ad group is created.
ad_group_criterion_operation = client.get_type("AdGroupCriterionOperation")
ad_group_criterion = ad_group_criterion_operation.create
ad_group_criterion.ad_group = ad_group_resource_name
ad_group_criterion.audience.audience = resource_name
ad_group_criterion_service = client.get_service("AdGroupCriterionService")
ad_group_criterion_service.mutate_ad_group_criteria(
customer_id=customer_id,
operations=[ad_group_criterion_operation],
)