Ads Manager 스크립트
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
모든 계정 가져오기
function getAllAccounts() {
const accountIterator = AdsManagerApp.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());
}
}
고객 ID에서 계정 가져오기
function getAccountsFromCustomerIds() {
// This is useful when you are reading customer IDs from an external data
// source, such as a Google Spreadsheet.
// You can also use the condition "CustomerId in ['123-456-7890',
// '345-678-9000', '890-123-6000']".
const accountIterator = AdsManagerApp.accounts()
.withIds(['123-456-7890', '345-678-9000', '890-123-6000'])
.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 getAccountsByLabel() {
// Only CONTAINS and DOES_NOT_CONTAIN operators are supported.
const accountIterator = AdsManagerApp.accounts()
.withCondition("LabelNames CONTAINS 'High spend 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 updateAccountsInSeries() {
// You can use this approach when you have only minimal processing to
// perform in each of your client accounts.
// Select the accounts to be processed.
const accountIterator = AdsManagerApp.accounts()
.withCondition("LabelNames CONTAINS 'Cars'")
.get();
for (const account of accountIterator) {
// Switch to the account you want to process.
AdsManagerApp.select(account);
// Retrieve all campaigns to be paused.
const campaignIterator = AdsApp.campaigns()
.withCondition("LabelNames = 'Christmas promotion'")
.get();
for (const campaign of campaignIterator) {
console.log(`Pausing campaign ${campaign.getName()} in ` +
`account ${account.getCustomerId()}`);
campaign.pause();
}
}
}
여러 계정을 동시에 업데이트
function updateAccountsInParallel() {
// You can use this approach when you have a large amount of processing
// to do in each of your client accounts.
// Select the accounts to be processed. You can process up to 50 accounts.
const accountSelector = AdsManagerApp.accounts()
.withCondition("LabelNames CONTAINS 'High spend accounts'")
.withLimit(50);
// Process the account in parallel. The 'processAccount' function will
// be called in the context of each account in the selector. The 'allFinished' function
// will be called in this script once processing is complete, and is optional.
accountSelector.executeInParallel('processAccount', 'allFinished');
}
/**
* Process one account at a time. This method is called by the executeInParallel
* method call in updateAccountsInParallel function for every account that
* it processes.
*
* @return {Number} the number of campaigns paused by this method.
*/
function processAccount() {
// executeInParallel will automatically switch context to the account being
// processed, so all calls to AdsApp will apply to the selected account.
const campaignIterator = AdsApp.campaigns()
.withCondition("LabelNames = 'Christmas promotion'")
.get();
for (const campaign of campaignIterator) {
console.log(`Pausing campaign ${campaign.getName()} in ` +
`account ${account.getCustomerId()}`);
campaign.pause();
}
// Optional: return a string value. If you have a more complex JavaScript
// object to return from this method, use JSON.stringify(value). This value
// will be passed on to the callback method, if specified, in the
// executeInParallel method call.
return campaignIterator.totalNumEntities().toFixed(0);
}
/**
* Post-process the results from processAccount. This method will be called
* once all the accounts have been processed by the executeInParallel method
* call.
*
* @param {Array.<ExecutionResult>} results An array of ExecutionResult objects,
* one for each account that was processed by the executeInParallel method.
*/
function allFinished(results) {
for (const result of results) {
console.log(`Customer ID: ${result.getCustomerId}; ` +
`status = ${result.getStatus}.`);
// Check the execution status. This can be one of ERROR, OK, or TIMEOUT.
if (result.getStatus() == 'ERROR') {
console.log(`-- Failed with error: '${result.getError()}'.`);
} else if (result.getStatus() == 'OK') {
// This is the value you returned from processAccount method. If you
// used JSON.stringify(value) in processAccount, you can use
// JSON.parse(text) to reconstruct the JavaScript object.
const retval = result.getReturnValue();
console.log(`--Processed ${retval} campaigns.`);
} else {
// Handle timeouts here.
}
}
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-10-11(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-10-11(UTC)"],[[["This script showcases how to retrieve Google Ads accounts using various methods, including fetching all accounts, filtering by customer IDs, and selecting accounts based on label criteria."],["It demonstrates methods for updating multiple accounts, either by processing them individually in series or handling them concurrently in parallel for improved efficiency."],["Parallel processing is highlighted as a suitable approach for scenarios involving substantial workloads within each account, enabling quicker execution by handling up to 50 accounts simultaneously."],["Account processing in parallel utilizes `executeInParallel`, allowing separate functions for individual account operations and a final callback for consolidating results and managing errors or timeouts."]]],[]]