Skip to content

Demand Gen campaigns and multi-asset image ads - #147

Merged
kLOsk merged 3 commits into
kLOsk:mainfrom
palermomarco:feat/demand-gen-campaign
Dec 1, 2026
Merged

kLOsk merged 3 commits into
kLOsk:mainfrom
palermomarco:feat/demand-gen-campaign

Conversation

@palermomarco

@palermomarco palermomarco commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Third of the four PRs agreed in #142. It uses the asset ids from draft_library_image_assets (#146), so it is most useful after that one; the code does not depend on it.

What

draft_campaign(channel_type="DEMAND_GEN") builds budget + campaign (PAUSED) + one ad group in one GoogleAdsService.Mutate, following Google's "Create a Demand Gen campaign" guide:

  • Budget not shared; campaign DEMAND_GEN with no sub type.
  • Ad group created without a type, with audience_setting.use_audience_grouped = true. It is immutable, and an Audience can only be attached to an ad group created with it (the next PR attaches one).
  • Locations and languages as ad group criteria, where Demand Gen targets; both required.
  • channels sets demand_gen_ad_group_settings.channel_controls.selected_channels, stating every flag as Google asks. Empty leaves Google's default, all channels including the Display Network, and the preview warns.
  • start_date / end_date as start_date_time / end_date_time.
  • Bidding: Maximize clicks (optional max_cpc), Maximize conversions, Target CPA. Budget cap, blocked operations and the usual checks apply.

Optimized targeting is off by default. optimized_targeting_enabled has no presence, so False is not sent on create, and Google refuses an update of a temporary id inside the same request (RESOURCE_NOT_FOUND, found with validate-only). It is switched off with a follow-up update of the created ad group. As you suggested, a failure there raises PartialApplyError with the created budget, campaign and ad group, so the apply ends as PARTIAL_APPLY and the plan is retired.

draft_demand_gen_ad creates a DemandGenMultiAssetAdInfo ad (PAUSED) from library image assets:

  • Text limits: headlines 1-5, ≤40; descriptions 1-5, ≤90; business name ≤25 (counted with the existing _counted_length).
  • Images: at least one landscape (1.91:1) or square (1:1); logos 1-5 (1:1); optional portrait (4:5); at most 20 marketing images. Each id is read from the account (asset resource) and its ratio checked for its slot (±1%).
  • final_url checked with _validate_urls; optional call_to_action.
  • Google opts multi-asset ads into generating videos and animated images from their images and texts (GENERATE_VIDEOS_FROM_OTHER_ASSETS, GENERATE_ANIMATED_IMAGES_FROM_OTHER_ASSETS), which then serve as extra ads. The tool opts the new ad out unless generated_videos / animated_images is true. In Demand Gen this lives on the ad (AdGroupAd.ad_group_ad_asset_automation_settings): on the campaign Google answers VALUE_MUST_BE_UNSET.

Operations create_demand_gen_campaign and create_demand_gen_ad: dispatch, approval card lines (created paused), tool descriptions, and rules (.cursor/rules/adloop.mdc, synced).

Tests

  • tests/test_demand_gen.py: draft validation for both tools (inputs, budget cap, blocked operation, text limits, image ratios against the library, unreachable URL), the campaign mutate (operation order, no ad group type, use_audience_grouped, criteria on the ad group, channel flags, bidding), the follow-up raising PartialApplyError, the ad mutate (slots, PAUSED, asset automation opt-out).
  • uv run pytest: 2632 passed, 2 skipped.

Validate-only against a live account

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

Call Result
Demand Gen campaign, Maximize clicks, dates, 3 channels DRY_RUN_SUCCESS (1 validated, the follow-up update skipped: it builds on the new ad group)
Same with Maximize conversions DRY_RUN_SUCCESS
Same with Target CPA DRY_RUN_SUCCESS
Multi-asset ad in an existing Demand Gen ad group, with existing square image and logo DRY_RUN_SUCCESS (1 validated)

The follow-up that switches optimized targeting off was validated on its own against an existing Demand Gen ad group (DRY_RUN_SUCCESS).

🤖 Generated with Claude Code

palermomarco and others added 2 commits December 1, 2026 17:32
draft_campaign(channel_type="DEMAND_GEN") builds budget + campaign (PAUSED) +
one ad group in one mutate, following Google's Demand Gen guide: no ad group
type, audience_setting.use_audience_grouped (immutable, needed to attach an
Audience later), locations and languages on the ad group, channel controls,
start and end date. Bidding: Maximize clicks, Maximize conversions, Target CPA.

Optimized targeting is off by default. The field has no presence, so False
cannot be sent on create, and Google refuses an update of a temporary id in
the same request: it is switched off by a follow-up update, and a failure
there raises PartialApplyError with the created resources so the plan is
retired.

draft_demand_gen_ad creates a DemandGenMultiAssetAdInfo ad (PAUSED) from
library image assets, checking text lengths, each image's ratio for its slot
against the account's assets, and the final URL. Google-generated videos and
animated images are opted out on the ad unless asked for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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

kLOsk commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thanks, Marco. #146 and #148 are merged, which left this one with conflicts in write.py (dispatch), card_view.py (effect lines) and server.py (tool registrations). I merged main into your branch and kept both sides in all three places (fe2692a); nothing of yours changed. The suite passes on the result.

I'll merge this now and follow up on main with a few things from the review, so you don't need to do another round:

  • draft_campaign refuses arguments that don't apply to the channel instead of dropping them (start_date / end_date on Search, keywords / geo_exclude_ids / ad_schedule on Demand Gen).
  • The Demand Gen branch also honours a blocked create_campaign.
  • A 9:16 slot on the ad (tall_portrait_marketing_images), since draft_library_image_assets already classifies those.
  • A second confirmation when draft_demand_gen_audience attaches to an ad group that is serving.

One question, if you know it from your account: does a Demand Gen ad group without an audience serve to everyone in its locations, or not at all? The preview says it cannot serve, and I could not confirm that from Google's docs.

@kLOsk
kLOsk merged commit 1e3efbc into kLOsk:main Dec 1, 2026
3 checks passed
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