gads_campaign_audience_targeting
Retrieve audience targeting details for Google Ads campaigns, including targeting type (observation or targeting) and bid modifiers. View both included and excluded audience lists to optimize campaign performance.
Instructions
Audiences attached to campaigns with targeting setting (observation vs targeting) and bid modifier. Shows both inclusion and exclusion lists.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customer_id | No | Override GOOGLE_ADS_CUSTOMER_ID for this call | |
| campaign_id | No | Filter to a specific campaign ID |
Implementation Reference
- src/tools/audiences.ts:36-56 (handler)The main handler function that queries the Google Ads API for audience targeting (campaign_criterion with type USER_LIST) attached to campaigns. Accepts optional customer_id and campaign_id filter, returns rows with criterion_id, bid_modifier, negative flag, and user_list info, ordered by campaign name (limited to 500).
export async function campaignAudienceTargeting(args: z.infer<z.ZodObject<typeof campaignAudienceTargetingSchema>>) { const customer = getCustomer(args.customer_id); const campaignClause = args.campaign_id ? `AND campaign.id = ${args.campaign_id}` : ""; const rows = await customer.query(` SELECT campaign.id, campaign.name, campaign_criterion.criterion_id, campaign_criterion.type, campaign_criterion.bid_modifier, campaign_criterion.negative, campaign_criterion.user_list.user_list FROM campaign_criterion WHERE campaign_criterion.type = 'USER_LIST' AND campaign_criterion.status != 'REMOVED' ${campaignClause} ORDER BY campaign.name LIMIT 500 `); return { rowCount: rows.length, rows }; } - src/tools/audiences.ts:31-34 (schema)Zod schema for the gads_campaign_audience_targeting tool. Defines two optional string inputs: customer_id (to override the default Google Ads customer) and campaign_id (to filter to a specific campaign).
export const campaignAudienceTargetingSchema = { customer_id: z.string().optional().describe("Override GOOGLE_ADS_CUSTOMER_ID for this call"), campaign_id: z.string().optional().describe("Filter to a specific campaign ID"), }; - src/index.ts:174-179 (registration)Registration of the tool with the MCP server under the name 'gads_campaign_audience_targeting', with a description, schema, and async handler that catches errors via the ok/err pattern.
server.tool( "gads_campaign_audience_targeting", "Audiences attached to campaigns with targeting setting (observation vs targeting) and bid modifier. Shows both inclusion and exclusion lists.", campaignAudienceTargetingSchema, async (args) => { try { return ok(await campaignAudienceTargeting(args)); } catch (e) { return err(e); } } ); - src/client.ts:24-31 (helper)The getCustomer helper function used by the handler to create a Google Ads API Customer client, resolving the customer_id from the argument or environment variable.
export function getCustomer(override?: string): Customer { const refresh_token = process.env.GOOGLE_ADS_REFRESH_TOKEN; if (!refresh_token) throw new GoogleAdsError("GOOGLE_ADS_REFRESH_TOKEN is not set"); const customer_id = (override ?? process.env.GOOGLE_ADS_CUSTOMER_ID ?? "").replace(/-/g, ""); if (!customer_id) throw new GoogleAdsError("GOOGLE_ADS_CUSTOMER_ID is not set and no customer_id was passed"); const login_customer_id = process.env.GOOGLE_ADS_LOGIN_CUSTOMER_ID?.replace(/-/g, "") || undefined; return getApi().Customer({ customer_id, login_customer_id, refresh_token }); }