라벨
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
사용자 계정에서 모든 라벨 가져오기
function getAllLabels() {
const labelIterator = AdsApp.labels().get();
console.log(`Total labels found: ${labelIterator.totalNumEntities()}`);
return labelIterator;
}
이름별로 라벨 가져오기
function getLabelByName(name) {
const labelIterator = AdsApp.labels()
.withCondition(`label.name = "${name}"`)
.get();
if (labelIterator.hasNext()) {
const label = labelIterator.next();
console.log(`Name: ${label.getName()}`);
console.log(`Description: ${label.getDescription()}`);
console.log(`Color: ${label.getColor()}`);
console.log(`Number of campaigns: ${label.campaigns().get().totalNumEntities()}`);
console.log(`Number of ad groups: ${label.adGroups().get().totalNumEntities()}`);
console.log(`Number of ads: ${label.ads().get().totalNumEntities()}`);
console.log(`Number of keywords: ${label.keywords().get().totalNumEntities()}`);
return label;
}
return null;
}
캠페인에 라벨 적용
function applyLabel(labelName, campaignName) {
// Retrieve a campaign, and apply a label to it. Applying labels to other
// object types is similar.
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = "${campaignName}"`)
.get();
if (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
campaign.applyLabel(labelName);
}
}
캠페인에서 라벨 삭제
function removeLabel(labelName, campaignName) {
// Removing labels from other object types is similar.
const campaignIterator = AdsApp.campaigns()
.withCondition(`campaign.name = "${campaignName}"`)
.get();
if (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
campaign.removeLabel(labelName);
}
}
사용자 계정에서 라벨 삭제
function deleteLabel(labelName) {
const labelIterator = AdsApp.labels()
.withCondition(`label.name = "${labelName}"`)
.get();
if (labelIterator.hasNext()) {
const label = labelIterator.next();
label.remove();
}
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-08-21(UTC)
[[["이해하기 쉬움","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"]],["최종 업데이트: 2024-08-21(UTC)"],[[["This script provides functions to manage labels in Google Ads, allowing retrieval of all labels or a specific label by name."],["It demonstrates how to apply and remove labels from campaigns, with similar functionality for other Google Ads object types."],["The script also includes a function to delete a label entirely from the user's Google Ads account."],["Included are example functions that show how to get information like a label's description, color, and the number of entities it's applied to."]]],[]]