gads_attach_audience_to_ad_group
Google Ads write medium risk
Part of the Google Ads Audience Agent.
What it does
Attach an audience criterion (user_list, user_interest, or custom_audience) to an ad group via AdGroupCriterionService, in TARGETING (restrict traffic to the audience) or OBSERVATION (collect data without restricting) mode. Mode is applied via the ad group's targeting_setting.target_restrictions for the AUDIENCE dimension: OBSERVATION => bid_only=true, TARGETING => bid_only=false. CRITICAL: Google overwrites the ENTIRE targeting_setting on update, so the tool first reads existing target_restrictions and preserves all non-AUDIENCE dimensions before writing. Optional bid_modifier. WRITE with preview->approve->commit: preview = criterion mutate validate_only=true + diff (ad group, audience, mode, bid_modifier) + preview_id; commit = the same call plus that preview_id after the user approves in a later message + the preserving targeting_setting update + audit. A full resource name (.../userLists/, /customAudiences/, /userInterests/) sets the audience type. With targeting_mode, the preview shows the ad group's current target_restrictions and warns when its audiences switch from OBSERVATION to TARGETING. The commit returns the ad group, audience type, mode and the created resource_names. PREVIEW SEMANTICS: the first call (no preview_id) is sent to the Google Ads API in validation mode — field, enum, policy and permission errors surface AT PREVIEW, nothing is changed, and the response returns a preview_id. To apply, show the preview to the user, get their approval, and re-call with that preview_id and IDENTICAL arguments within 30 minutes; changed arguments or an expired token fail closed to a fresh preview.
When to use it
Use to add an audience to an ad group for bidding or restriction. Default to OBSERVATION on Search unless the user explicitly wants to restrict. Preview validate_only first, show current vs new targeting_setting, confirm mode and any bid_modifier, then commit. Find affinity and in-market ids with gads_search_audiences; for a whole campaign use gads_add_campaign_audience.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
customer_id | string | yes | 10-digit CID; strip dashes. |
ad_group_id | string | yes | Target ad group ID. |
audience_id | string | yes | Audience resource name or bare ID. A full resource name (customers/{cid}/userLists/{id}, /userInterests/{id}, /customAudiences/{id}) is unambiguous: its type is used, and an audience_type that contradicts it is refused. For a bare ID, set audience_type to disambiguate (defaults to USER_LIST). |
audience_type | string | no | USER_LIST (default) / USER_INTEREST / CUSTOM_AUDIENCE. Set this when audience_id is a bare ID so the right criterion type is used; a full resource name sets it. |
targeting_mode | string | no | TARGETING (restrict) or OBSERVATION (observe only), case-insensitive. Omitted: the ad group's targeting setting is left as it is (prefer OBSERVATION on Search). |
bid_modifier | number | no | Optional multiplier (e.g., 1.2 = +20%, 0.8 = -20%); range ~0.1-10. Applies to the audience criterion. Ratio, not micros. |
manager_id | string | no | Optional MCC login-customer-id. |
validate_only | boolean | no | Optional. true forces another preview even with a preview_id; false is DEPRECATED and no longer commits — only a valid preview_id applies the write. |
preview_id | string | no | Omit it to preview: nothing is applied, and the call returns a preview_id bound to this exact request. Pass it only after the user approves that preview in a later message, with the same arguments (leave out validate_only, and add any confirmation flag the preview names). Single-use, expires in 30 minutes; changed arguments need a fresh preview. |
Safeguards
A change in two steps. The first call previews and changes nothing; Claude shows you the preview and applies it only after you approve, within 30 minutes and with the same arguments. Every applied change goes to the audit log. How changes are approved.
Policy
Audience targeting must respect privacy and Customer Match terms; for employment/housing/education/credit campaigns do not use audiences to include or exclude protected classes. TARGETING mode silently narrows reach — confirm intent. Do not use audiences to evade a disapproval (Circumventing Systems).
Reminder
Respect customer-data terms and anti-discrimination rules; TARGETING restricts who sees the ad — confirm before applying.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
INVALID_ARGUMENT | Bad audience resource type/ID, or invalid bid_modifier. | Surface the platform message; supply a full resource name and a bid_modifier in range, then re-preview. | no |
CRITERION_ERROR | The audience criterion is invalid or duplicates an existing one on the ad group. | Check for an existing identical criterion; fix targeting parameters. | no |
TOKEN_REVOKED | OAuth token expired/revoked. | Refresh and retry once; else prompt reconnect (needs_reauth). | yes |
CUSTOMER_NOT_FOUND | Customer ID not found/accessible. | Verify the CID is authorized. | no |
PERMISSION_DENIED | No access or out-of-bearer-scope write. | Confirm access and write scope; else refuse. | no |
RESOURCE_EXHAUSTED | Rate/quota exceeded (HTTP 429). | Backoff 5/10/20s cap 60s, then retry. | yes |
INTERNAL_ERROR | Transient Google server error (5xx). | Retry after backoff. | yes |
Edge cases
- targeting_setting is overwritten wholesale by Google -> the tool MUST read+preserve existing target_restrictions or other dimensions are wiped.
- Switching an existing audience from OBSERVATION to TARGETING can sharply cut impressions -> the preview warns.
- Bare numeric audience_id defaults to USER_LIST -> set audience_type (or pass a full resource name) for USER_INTEREST/CUSTOM_AUDIENCE.
- Attaching a TARGETING audience to a campaign already using audience exclusions may conflict -> surface the platform error.
- Performance Max has no ad groups -> add an audience signal to the asset group with gads_add_audience_signal.
- Preview creates nothing; preview_id TTL expiry -> re-preview; expired token -> refresh once and retry.