Microsoft広告スクリプトで、Yahoo広告スクリプトやGoogle広告スクリプトのようにスプレッドシートに日別の広告コスト、インプレッション、クリック、コンバージョン数を転記することはできますか?
Microsoft広告スクリプトに以下のようなコードを記述したところ、
ReferenceError: 'AdsUtilities' is not defined at main (script code:2:3) |
というエラーが表示されるため、どのように記述するのが適切か教えていただけますと嬉しいです。
function main() {
const accountId = AdsUtilities.getCurrentAccountId();
const today = new Date();
today.setDate(today.getDate() - 1); // 前日の日付を取得
const endYear = today.getFullYear();
const endMonth = ("00" + (today.getMonth() + 1)).slice(-2);
const endDate = ("00" + today.getDate()).slice(-2);
const endDateValue = endYear + endMonth + endDate;
const startDate = endDateValue; // 前日の日付を設定
const spreadsheetId = '************************************';
const ss = SpreadsheetApp.openById(spreadsheetId);
const sheetName = 'microsoft';
let sh = ss.getSheetByName(sheetName);
const reports = AdsUtilities.getSearchReport({
accountId: accountId,
dateRange: {
endDate: endDateValue,
startDate: startDate,
},
fields: ['DAY','COST', 'IMPS', 'CLICKS', 'CONVERSIONS'],
reportDateRangeType: 'CUSTOM_DATE',
reportType: 'ACCOUNT',
});
const rows = reports.reports[0].rows;
const numColumns = rows[0].length;
const numRows = rows.length;
// 追加するデータを取得
const existingValues = sh.getRange(2, 1, sh.getLastRow() - 1, numColumns).getValues();
// データをスプレッドシートに追加
sh.getRange(existingValues.length + 2, 1, numRows, numColumns).setValues(rows);
Logger.log('Data appended to the spreadsheet.');
}