Skip to content

Demand Gen audiences: custom segments, lookalike lists, audiences - #148

Merged
kLOsk merged 1 commit into
kLOsk:mainfrom
palermomarco:feat/demand-gen-audiences
Dec 1, 2026
Merged

kLOsk merged 1 commit into
kLOsk:mainfrom
palermomarco:feat/demand-gen-audiences

Conversation

@palermomarco

Copy link
Copy Markdown
Contributor

Fourth of the four PRs agreed in #142. Independent of the others in code; it attaches audiences to the Demand Gen ad groups that #147 creates.

What

Three draft tools in a new module ads/audience_create.py, each with its own operation, dispatch entry and apply:

  • draft_custom_segment (create_custom_segment): a CustomAudience with URL and keyword members. CustomAudience is not part of GoogleAdsService.Mutate in v25, so the apply uses CustomAudienceService.MutateCustomAudiences. segment_type is AUTO (default) or SEARCH; INTEREST and PURCHASE_INTENT are refused, because Google rejects them on new segments. URLs get a scheme when missing; URL length, keyword length (10 words, 80 characters), duplicates and the name's uniqueness are checked.
  • draft_lookalike_list (create_lookalike_list): a UserList with lookalike_user_list (seed_user_list_ids, expansion_level NARROW / BALANCED / BROAD, country_codes). Seeds are read from the account: unknown ids are refused; closed seeds, seeds below 100 people together, and missing countries are warned. The preview says lookalikes only work in Demand Gen and cannot be edited later.
  • draft_demand_gen_audience (create_demand_gen_audience), renamed from draft_audience as you suggested: an Audience (scope CUSTOMER) with all custom segments and user lists in one AudienceSegmentDimension, where a person in any segment is in the audience. With ad_group_id, the same GoogleAdsService.Mutate also creates the AdGroupCriterion.audience that attaches it, referring to the new audience by its temporary resource name. The draft refuses an ad group that is not in a Demand Gen campaign, one created without audience_setting.use_audience_grouped (immutable), and one that already has an audience: Google allows one (ONE_AUDIENCE_ALLOWED_PER_AD_GROUP, found with validate-only).

Rules updated in .cursor/rules/adloop.mdc (three rows, and the audience pattern no longer says creating audiences is unsupported), synced. One approval card line for lookalikes (filled over one to two days, not editable).

Tests

  • tests/test_audience_create.py: validation for each tool (names, members, segment types, unknown seeds and ids, small and closed seeds, ad group checks including the one-audience rule, blocked operations) and each apply building the right protos; the custom segment and audience applies also run through ValidateOnlyClient.
  • uv run pytest: 2634 passed, 2 skipped.

Validate-only against a live account

confirm_and_apply(dry_run=True) on a real account; nothing was created:

Call Result
Custom segment with one URL and one keyword DRY_RUN_SUCCESS (1 validated)
Lookalike list from a rule-based seed list, country IT DRY_RUN_SUCCESS (1 validated)
Audience from that list, not attached DRY_RUN_SUCCESS (1 validated)
Audience attached to a Demand Gen ad group that already has one refused at draft (Google's own dry run answered ONE_AUDIENCE_ALLOWED_PER_AD_GROUP before the check)

Not covered live: attaching to an ad group without an audience, because every Demand Gen ad group in the account already had one. The audience part of that mutate validates on its own; the temporary resource name for Audience inside one mutate is the assumption left.

🤖 Generated with Claude Code

draft_custom_segment creates a CustomAudience from URL and keyword members
(CustomAudienceService; AUTO or SEARCH, as Google refuses INTEREST and
PURCHASE_INTENT on new segments). draft_lookalike_list creates a UserList
with lookalike_user_list from seed lists read from the account.
draft_demand_gen_audience creates an Audience whose segments share one
dimension (a person in any of them is in it) and, with ad_group_id, attaches
it to a Demand Gen ad group in the same mutate through a temporary resource
name. The draft refuses ad groups outside Demand Gen, without
use_audience_grouped, or with an audience already attached (Google:
ONE_AUDIENCE_ALLOWED_PER_AD_GROUP).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
palermomarco added a commit to palermomarco/adloop that referenced this pull request Dec 1, 2026
Same changes as in kLOsk#147 and kLOsk#148: draft_audience is renamed
draft_demand_gen_audience (operation create_demand_gen_audience), and a failed
optimized-targeting follow-up after a Demand Gen create raises
PartialApplyError so the plan is retired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kLOsk
kLOsk merged commit 8669e5e into kLOsk:main Dec 1, 2026
3 checks passed
kLOsk added a commit to palermomarco/adloop that referenced this pull request Dec 1, 2026
Conflicts with kLOsk#146 and kLOsk#148 in write.py (dispatch), card_view.py (effect
lines) and server.py (tool registrations): both sides kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jr3T22aqqRobKScfCwiyfY
kLOsk added a commit that referenced this pull request Dec 1, 2026
…, and a second confirmation for narrowing a running ad group

Follow-up to #146, #147 and #148.

draft_campaign refuses an argument it does not use instead of dropping it:
start_date, end_date, channels and optimized_targeting on a Search campaign
(an end date that is dropped leaves a campaign that never stops), and
keywords, geo_exclude_ids, ad_schedule, target_roas and the network, location
and URL options on a Demand Gen campaign. The Demand Gen branch also honours
a blocked create_campaign.

draft_demand_gen_ad takes tall portrait (9:16) images, which
draft_library_image_assets already classifies, and checks that the ad group
belongs to a Demand Gen campaign before it reads the images.

draft_demand_gen_audience asks for a double confirmation when it attaches to
an ad group that is running (campaign and ad group enabled), as targeting mode
in draft_audience_attachment does: reach shrinks at once.

The approval card states what creating a custom segment and creating or
attaching an audience does. The campaign preview no longer says a campaign
cannot serve without an audience, which Google's documentation does not
state. The rules gain a Demand Gen pattern with the order of steps.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jr3T22aqqRobKScfCwiyfY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants