애드센스 서비스를 사용하면 Apps Script에서 AdSense Management API를 사용할 수 있습니다. 이 API를 통해 애드센스 고객은 계정 구조에 관한 정보를 확인하고 계정 실적에 관한 보고서를 실행할 수 있습니다.
참조
이 서비스에 대한 자세한 내용은 AdSense Management API의 참조 문서를 참고하세요. Apps Script의 모든 고급 서비스와 마찬가지로 애드센스 서비스는 공개 API와 동일한 객체, 메서드, 매개변수를 사용합니다. 자세한 내용은 메서드 서명이 결정되는 방식을 참고하세요.
문제를 신고하고 다른 지원을 받으려면 adsense-api 태그를 사용하여 Stack Overflow에 질문하세요.
/** * Lists available AdSense accounts. */functionlistAccounts(){letpageToken;do{constresponse=AdSense.Accounts.list({pageToken:pageToken});if(!response.accounts){console.log('No accounts found.');return;}for(constaccountofresponse.accounts){console.log('Found account with resource name "%s" and display name "%s".',account.name,account.displayName);}pageToken=response.nextPageToken;}while(pageToken);}
광고 클라이언트 나열
이 샘플은 지정된 계정의 모든 광고 클라이언트를 나열합니다. 계정을 리소스 이름으로 지정합니다(예: accounts/pub-12345). 계정 나열 샘플 코드를 사용하여 계정 리소스 이름을 가져올 수 있습니다.
/** * Logs available Ad clients for an account. * * @param {string} accountName The resource name of the account that owns the * collection of ad clients. */functionlistAdClients(accountName){letpageToken;do{constresponse=AdSense.Accounts.Adclients.list(accountName,{pageToken:pageToken});if(!response.adClients){console.log('No ad clients found for this account.');return;}for(constadClientofresponse.adClients){console.log('Found ad client for product "%s" with resource name "%s".',adClient.productCode,adClient.name);console.log('Reporting dimension ID: %s',adClient.reportingDimensionId??'None');}pageToken=response.nextPageToken;}while(pageToken);}
광고 단위 나열
이 샘플은 지정된 광고 클라이언트의 모든 광고 단위를 나열합니다. 광고 클라이언트를 리소스 이름으로 지정합니다(예: accounts/pub-12345/adclients/ca-pub-12345).
광고 클라이언트 나열 샘플 코드를 사용하여 광고 클라이언트 리소스 이름을 가져올 수 있습니다.
/** * Lists ad units. * @param {string} adClientName The resource name of the ad client that owns the collection * of ad units. */functionlistAdUnits(adClientName){letpageToken;do{constresponse=AdSense.Accounts.Adclients.Adunits.list(adClientName,{pageSize:50,pageToken:pageToken});if(!response.adUnits){console.log('No ad units found for this ad client.');return;}for(constadUnitofresponse.adUnits){console.log('Found ad unit with resource name "%s" and display name "%s".',adUnit.name,adUnit.displayName);}pageToken=response.nextPageToken;}while(pageToken);}
/** * Generates a spreadsheet report for a specific ad client in an account. * @param {string} accountName The resource name of the account. * @param {string} adClientReportingDimensionId The reporting dimension ID * of the ad client. */functiongenerateReport(accountName,adClientReportingDimensionId){// Prepare report.consttoday=newDate();constoneWeekAgo=newDate(today.getTime()-7*24*60*60*1000);constreport=AdSense.Accounts.Reports.generate(accountName,{// Specify the desired ad client using a filter.filters:['AD_CLIENT_ID=='+escapeFilterParameter(adClientReportingDimensionId)],metrics:['PAGE_VIEWS','AD_REQUESTS','AD_REQUESTS_COVERAGE','CLICKS','AD_REQUESTS_CTR','COST_PER_CLICK','AD_REQUESTS_RPM','ESTIMATED_EARNINGS'],dimensions:['DATE'],...dateToJson('startDate',oneWeekAgo),...dateToJson('endDate',today),// Sort by ascending date.orderBy:['+DATE']});if(!report.rows){console.log('No rows returned.');return;}constspreadsheet=SpreadsheetApp.create('AdSense Report');constsheet=spreadsheet.getActiveSheet();// Append the headers.sheet.appendRow(report.headers.map((header)=>header.name));// Append the results.sheet.getRange(2,1,report.rows.length,report.headers.length).setValues(report.rows.map((row)=>row.cells.map((cell)=>cell.value)));console.log('Report spreadsheet created: %s',spreadsheet.getUrl());}/** * Escape special characters for a parameter being used in a filter. * @param {string} parameter The parameter to be escaped. * @return {string} The escaped parameter. */functionescapeFilterParameter(parameter){returnparameter.replace('\\','\\\\').replace(',','\\,');}/** * Returns the JSON representation of a Date object (as a google.type.Date). * * @param {string} paramName the name of the date parameter * @param {Date} value the date * @return {object} formatted date */functiondateToJson(paramName,value){return{[paramName+'.year']:value.getFullYear(),[paramName+'.month']:value.getMonth()+1,[paramName+'.day']:value.getDate()};}
[[["이해하기 쉬움","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-09-15(UTC)"],[[["\u003cp\u003eThe AdSense Management API allows you to programmatically access your AdSense account data within Google Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve information about your account structure, including accounts, ad clients, and ad units.\u003c/p\u003e\n"],["\u003cp\u003eThis API enables you to generate reports on your AdSense performance and export them to a Google Sheet.\u003c/p\u003e\n"],["\u003cp\u003eThis is an advanced service that needs to be enabled before use, offering functionality similar to the public AdSense Management API.\u003c/p\u003e\n"]]],[],null,[]]