gads_set_campaign_ad_rotation
Google Ads write medium risk
Part of the Google Ads Manager Agent.
What it does
Set a campaign's ad rotation (ad_serving_optimization_status): OPTIMIZE / CONVERSION_OPTIMIZE / ROTATE / ROTATE_INDEFINITELY (aliases: rotate_evenly -> ROTATE, rotate_forever -> ROTATE_INDEFINITELY). SCALIX SOP: a `reason` is REQUIRED (error_class 'reason_required') and is written to the audit log; selecting a non-optimizing rotation (ROTATE / ROTATE_INDEFINITELY) returns a prominent warning that it serves every ad equally regardless of performance and is intended for A/B tests only. PREVIEW->APPROVE->COMMIT. 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. validate_only=true forces another preview; validate_only=false alone never commits.
When to use it
Ask whether this is a controlled experiment or a production campaign. Optimize is the recommended default for production; Rotate Evenly is for experiments only.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
customer_id | string | yes | 10-digit CID, dashes/spaces stripped. Tenant context server-derived. |
campaign_id | string | yes | Numeric campaign ID. |
rotation_mode | string | yes | OPTIMIZE / CONVERSION_OPTIMIZE / ROTATE / ROTATE_INDEFINITELY (aliases ROTATE_EVENLY -> ROTATE, ROTATE_FOREVER -> ROTATE_INDEFINITELY); enum-normalized uppercase. Maps to Campaign.ad_serving_optimization_status — all four are settable in v24. Non-optimizing modes (ROTATE / ROTATE_INDEFINITELY) draw an experiments-only warning. |
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. |
reason | string | no | Why the rotation is changing (experiment vs production). Required; audit-logged. |
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
Ad rotation is content-neutral; setting it must not be used to force-serve a borderline/disapproved creative by evening rotation. Apply only the mode the user approved.
Reminder
State the performance trade-off of disabling optimization; don't retain account settings beyond this request.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
CUSTOMER_NOT_FOUND | Customer ID not found or not linked. | Verify CID (dashes stripped); re-auth if stale. | no |
TOKEN_REVOKED | Authorization revoked / refresh token expired. | Trigger re-auth (needs_reauth); do not retry with the dead token. | no |
INVALID_AD_ROTATION_MODE | rotation_mode is a deprecated/unsupported enum (e.g. CONVERSION_OPTIMIZE/ROTATE) or unset. | Accept only OPTIMIZE or ROTATE_FOREVER; surface the platform message. | no |
OPERATION_NOT_PERMITTED_FOR_CAMPAIGN_TYPE | Campaign type doesn't allow changing rotation (e.g. PMax/Smart force OPTIMIZE). | Explain the channel-type restriction; do not retry. | no |
INVALID_ARGUMENT | Operation rejected (bad update_mask). | Surface platform message; fix input. | no |
PERMISSION_DENIED | Missing scope or read-only role. | Report missing scope / role; do not retry. | no |
MANAGER_ACCOUNT_WRITE | Target CID is a manager (MCC) account. | Ask which child serving account to target. | no |
RESOURCE_EXHAUSTED | Rate/quota limit (HTTP 429). | Backoff 5->10->20s cap 60s, honor retryDelay; retry. | yes |
PLATFORM_UNAVAILABLE | Google Ads 5xx / INTERNAL / DEADLINE_EXCEEDED. | Idempotent retry with backoff. | yes |
Edge cases
- Setting the same mode already in place -> no-op; report 'already set' (count:0 change).
- PMax/Smart/automated campaigns only support OPTIMIZE -> OPERATION_NOT_PERMITTED on ROTATE_FOREVER.
- Deprecated CONVERSION_OPTIMIZE/ROTATE values -> reject with INVALID_AD_ROTATION_MODE before the API call.
- Switching to ROTATE_FOREVER mid-flight resets some optimization signals -> note possible short-term volatility.
- Expired token -> refresh once, retry.
- Preview expired before approval -> re-run validate_only before commit.