constlabel=AdsApp.labels().withCondition("label.name = 'Christmas promotions'").get().next();constquery=`SELECT campaign.name, metrics.clicks, metrics.impressions, metrics.cost `+`FROM campaign WHERE campaign.labels CONTAINS ANY `+`["${label.getResourceName()}"] AND segments.date DURING THIS_MONTH`;constresult=AdsApp.search(query);
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\u003cp\u003eGoogle Ads scripts support labels at the account, campaign, ad group, ad, and keyword levels, allowing for flexible organization and filtering of elements.\u003c/p\u003e\n"],["\u003cp\u003eLabels enable various use cases, such as processing specific account or entity groups, managing changes over time, implementing flexible bidding strategies, and tracking quality scores.\u003c/p\u003e\n"],["\u003cp\u003eScripts can create and apply labels to accounts within a manager account, facilitating group processing and management based on shared labels.\u003c/p\u003e\n"],["\u003cp\u003eWithin individual accounts, scripts can apply and remove labels to campaigns, ad groups, ads, and keywords, enabling targeted operations on specific element sets.\u003c/p\u003e\n"],["\u003cp\u003eReporting functionality allows filtering entities based on label resource names, providing insightful performance data for labeled elements.\u003c/p\u003e\n"]]],[],null,["# Labels let you organize elements in your account into meaningful groups so\nyou can quickly filter and report on the data that is most interesting to you.\nGoogle Ads scripts support labels at the **account** , **campaign** ,\n**ad group** , **ad** , and **keyword** levels.\n\nUse cases\n---------\n\nWithin Google Ads accounts, labels can be used to associate arbitrary data with\nGoogle Ads entities. Within manager accounts, labels can be used to group similar\nchild accounts. Labels help with a number of use cases:\n\n- Process a list of accounts\n - If you are an agency, you could apply a `plumber_accounts` label to all the accounts for plumbers, and then a script can push plumber-related keywords (for example, \"emergency shower repair\") into all campaigns in those accounts.\n- Process a list of entities\n - If you have a set of keywords that you want to enable only during weekends, you could apply a `weekend_keywords` label to them. A script could then enable all keywords with `weekend_keywords` on Friday evening, and pause them on Monday morning.\n- Process entities across multiple runs\n - If you have a large number of entities that cannot be processed in under 30 minutes, then you can create a `processed` label in your script and apply it to entities that have already been processed. Schedule the script to run hourly, and then process only entities that don't have the `processed` label applied to them.\n- Two-step changes\n - Instead of having the script execute a bid change across a large number of keywords, you can label the keywords with `increase_bid_by_10%`, sign in to the Google Ads UI, filter out the keywords matching the label, review them, and if satisfied with the result, change their bids using [bulk edits](//support.google.com/google-ads/answer/144560).\n- Flexible bidding\n - A script could use labels to maintain a history of bid changes. For example when a script increases a keyword bid by 20%, it can mark the account with a label, `increased_20%`. The next day when the script runs across the label and realizes it had already increased the bid previously, it could increase the bid by only 10%.\n- Quality score tracking\n - A script could label important keywords with their quality scores, then periodically check and report on keywords whose quality score no longer matches the label.\n\nLabels at the account level\n---------------------------\n\nGoogle Ads scripts let you create labels within manager accounts, as well as apply\nlabels to Google Ads accounts under that manager account: \n\n const labelName = 'High spending accounts';\n AdsManagerApp.createAccountLabel(labelName);\n\nYou can apply the label to the accounts of your choice using the\n[`applyLabel`](/google-ads/scripts/docs/reference/adsmanagerapp/adsmanagerapp_managedaccount#applyLabel_name)\nmethod: \n\n const accountIds = ['123-456-7890', '345-6789-2100'];\n const labelName = 'High spending accounts';\n\n const accounts = AdsManagerApp.accounts().withIds(accountIds).get();\n for (const account of accounts) {\n account.applyLabel(labelName);\n }\n\nSimilarly, you can remove a label from an account using the\n[`removeLabel`](/google-ads/scripts/docs/reference/adsmanagerapp/adsmanagerapp_managedaccount#removeLabel_name)\nmethod: \n\n const accountIds = ['123-456-7890', '345-6789-2100'];\n const labelName = 'High spending accounts';\n\n const accounts = AdsManagerApp.accounts().withIds(accountIds).get();\n for (const account of accounts) {\n account.removeLabel(labelName);\n }\n\nThe most common use of account labels is to process a group of accounts sharing\nthe same account label: \n\n const labelName = 'High spending accounts';\n\n const accounts = AdsManagerApp.accounts()\n .withCondition(`LabelNames CONTAINS \"${labelName}\"`)\n .get();\n\n| **Note:** `LabelNames` is a convenience method, and requires an extra API call behind the scenes to look up the label's resource name. If you already have a label object, you should use a filter of `customer_client.applied_labels\n| CONTAINS ALL (${label.getResourceName()})` instead. See [the reporting\n| section](#reporting) below for more details on resource names.\n\nRefer to our\n[manager account scripts guide](/google-ads/scripts/docs/features/manager-scripts)\nto learn more about processing multiple accounts in a single script execution.\n\nLabels within an account\n------------------------\n\nYou can create and apply labels to an account's **campaigns** , **ad groups** ,\n**ads** , and **keywords**. Here's how to apply a label to a campaign: \n\n const campaign = AdsApp.campaigns()\n .withCondition('campaign.name = \"My first campaign\"').get().next();\n campaign.applyLabel('High performing campaign');\n\nSimilarly, you can remove a label using the `removeLabel` method: \n\n const campaign = AdsApp.campaigns()\n .withCondition('campaign.name = \"My first campaign\"').get().next();\n campaign.removeLabel('High performing campaign');\n\nLabels are most commonly used to process a set of similar entities grouped\ntogether by a label. The following code snippet shows how to pause a group of\ncampaigns sharing a common label: \n\n const label = AdsApp.labels()\n .withCondition('label.name = \"Christmas promotions\"')\n .get().next();\n var campaignIterator = label.campaigns().get();\n for (const campaign of campaignIterator) {\n campaign.pause();\n }\n\nReporting\n---------\n\nYou can use label resource names to filter for entities when running\nperformance reports for Google Ads accounts. Resource names are a concept from the\nGoogle Ads API and are sometimes used when running reports with GAQL. A label resource\nname is always in the format: \n\n customers/[customer id]/labels/[label id]\n\nYou can fetch a label's resource name using its\n[`getResourceName`](/google-ads/scripts/docs/reference/adsapp/adsapp_label#getResourceName)\nmethod.\n\nThe following code snippet shows how to run a [campaign report](/google-ads/api/reference/rpc/v21/Campaign)\nfor all campaigns that have a \"Christmas promotions\" label: \n\n const label = AdsApp.labels()\n .withCondition(\"label.name = 'Christmas promotions'\")\n .get().next();\n const query = `SELECT campaign.name, metrics.clicks, metrics.impressions, metrics.cost ` +\n `FROM campaign WHERE campaign.labels CONTAINS ANY ` +\n `[\"${label.getResourceName()}\"] AND segments.date DURING THIS_MONTH`;\n const result = AdsApp.search(query);\n\nKeep in mind that you can use only `CONTAINS_ALL`, `CONTAINS_ANY`, and\n`CONTAINS_NONE` operators for filtering by label resource names."]]