帳戶標籤
透過集合功能整理內容 你可以依據偏好儲存及分類內容。
建立帳戶標籤
function createAccountLabels(labelName) { AdsManagerApp.createAccountLabel(labelName); console.log("Label with text = '%s' created.", labelName); }
將帳戶標籤套用至多個帳戶
function applyAccountLabels(accountId1, accountId2, labelName) { // You can modify this function to accept an array of IDs directly as well. const accountIds = [accountId1, accountId2]; const accounts = AdsManagerApp.accounts().withIds(accountIds).get(); for (const account of accounts) { account.applyLabel(labelName); console.log('Label with text = "%s" applied to customer id %s.', labelName, account.getCustomerId()); } }
移除多個帳戶中的帳戶標籤
function removeLabelFromAccounts(accountId1, accountId2, labelName) { const accountIds = [accountId1, accountId2]; var accounts = AdsManagerApp.accounts().withIds(accountIds).get(); for (const account of accounts) { account.removeLabel(labelName); console.log('Label with text = "%s" removed from customer id %s.', labelName, account.getCustomerId()); } }
按標籤名稱選取帳戶
function selectAccountsByLabelName(labelName) { const accountIterator = AdsManagerApp.accounts() .withCondition(`LabelNames CONTAINS '${labelName}'`) .get(); for (const account of accountIterator) { const accountName = account.getName() ? account.getName() : '--'; console.log('%s,%s,%s,%s', account.getCustomerId(), accountName, account.getTimeZone(), account.getCurrencyCode()); } }
按標籤 ID 選取帳戶
function selectAccountsByLabelId(labelId) { const label = AdsManagerApp.accountLabels().withIds([labelId]).get().next(); const accountIterator = label.accounts().get(); for (const account of accountIterator) { const accountName = account.getName() ? account.getName() : '--'; console.log('%s,%s,%s,%s', account.getCustomerId(), accountName, account.getTimeZone(), account.getCurrencyCode()); } }
擷取所有帳戶標籤
function getAllAccountLabels() { const labelIterator = AdsManagerApp.accountLabels().get(); for (const label of labelIterator) { console.log('Label with id = %s and text = %s was found.', label.getId().toFixed(0), label.getName()); } }
按名稱擷取帳戶標籤
function getLabelByName(labelName) { const labelIterator = AdsManagerApp.accountLabels() .withCondition(`label.name CONTAINS '${labelName}'`) .get(); for (const label of labelIterator) { console.log(`Label with id = ${label.getId().toFixed(0)} ` + `and text = ${label.getName()} was found.`); } }
按 ID 擷取帳戶標籤
function getLabelById(labelId) { const labelIterator = AdsManagerApp.accountLabels() .withIds([labelId]) .get(); for (const label of labelIterator) { console.log("Label with id = %s and text = '%s' was found.", label.getId().toFixed(0), label.getName()); } }
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-28 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-28 (世界標準時間)。"],[[["This script provides functions for managing account labels in Google Ads Manager, including creating, applying, and removing labels from accounts."],["You can use it to select specific accounts based on label names or IDs for targeted management."],["The script enables retrieving information about all existing account labels or specific labels by name or ID."],["These functionalities streamline account organization and reporting within your Google Ads Manager hierarchy."],["Provided examples demonstrate how to perform these tasks with simple, clear, and well-documented code snippets."]]],[]]