gads_set_campaign_url_options
Google Ads write high risk
Part of the Tracking Audit Agent.
What it does
Set a campaign's URL options: tracking_url_template, final_url_suffix, and url_custom_parameters (ValueTrack custom parameters). Updates Campaign with an update_mask covering only the supplied fields. Returns old->new for each URL field. Preview->approve->commit: validate_only=true diff (campaign, current vs proposed tracking template / final-URL suffix / custom params, plus an example URL assembled on one of the campaign's own ad final URLs, with a warning when none can be read), explicit approval, then commit (with preview_id) sends validate_only=false server-side + audit log. Accuracy/safety: a broken tracking_url_template can break click measurement or redirect users off-policy — the preview shows the landing URL and the expanded tracking URL, and names the host a click goes through when it isn't the final URL's; final_url_suffix appends params under parallel tracking; custom parameter keys are alphanumeric only; the template/suffix must NOT change the landing domain (redirecting to a different domain = Misrepresentation/Cloaking risk). 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
Use when the user wants to set/clear campaign-level tracking (e.g. 'add UTM params via final URL suffix' or 'set our click tracker template'). Preview the assembled URL and verify it stays on the same domain before committing — a bad template breaks measurement or risks a cloaking suspension.
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. |
tracking_url_template | string | no | Tracking template used to assemble the destination URL (must contain {lpurl} or equivalent). Send empty string to CLEAR. The preview expands it on one of the campaign's ad final URLs ({lpurl}, {unescapedlpurl}, {escapedlpurl} and {_key} filled in, as Google does) and names the host a click goes through when it isn't the final URL's. |
final_url_suffix | string | no | Params appended to the final URL under parallel tracking (e.g. 'utm_source=google&utm_medium=cpc'). No leading '?'. Send empty string to clear. |
url_custom_parameters | array<object> | no | ValueTrack custom params: [{key (alphanumeric, no braces), value}]. REPLACES the existing set on the campaign (not a merge). Keys map to {_key} in templates. |
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
Tracking templates/suffixes must NOT redirect users to a domain different from the displayed final URL or cloak the destination — destination/landing mismatch is Misrepresentation and redirect chains that hide the real destination are Circumventing Systems, both egregious immediate-suspension risks. Keep tracking on the same final-URL domain.
Reminder
Show the assembled example URL and confirm the landing domain is unchanged; don't retain tracking config 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_TRACKING_URL_TEMPLATE | Template is malformed or missing {lpurl}/required ValueTrack tag. | Surface the platform message; fix the template. Do not guess a template. | no |
INVALID_FINAL_URL_SUFFIX | Suffix is malformed (e.g. contains '?', invalid encoding). | Surface platform message; send key=value&key=value without a leading '?'. | no |
INVALID_CUSTOM_PARAMETER | A custom parameter key has non-alphanumeric chars or there are too many params. | Surface platform message; fix the key/count. Don't strip silently. | 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
- No URL fields supplied -> success:false 'nothing to change'.
- Empty string for a field -> clears it; the preview warns, to confirm the user means to remove tracking, not leave it unchanged.
- A template whose click goes through another host than the final URL's -> the preview names that host and warns it must redirect to the final URL. Not refused: a third-party click tracker works exactly that way, and Google itself refuses a template with no {lpurl} tag.
- url_custom_parameters REPLACES (not merges) the existing set -> the preview names the current keys that are dropped.
- Custom param key with braces or spaces -> INVALID_CUSTOM_PARAMETER.
- Expired token -> refresh once, retry.
- Preview expired before approval -> re-run validate_only before commit.