Microsoft広告スクリプトで、Yahoo広告スクリプトやGoogle広告スクリプトのようにスプレッドシートに日別の広告コスト、インプレッション、クリック、コンバージョン数を転記することはできますか?

tmtk 0 Reputation points
2023-08-06T01:42:37.1233333+00:00

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.');

}

Microsoft Advertising API
Microsoft Advertising API
A Microsoft API that provides programmatic access to Microsoft Advertising to manage large campaigns or to integrate your marketing with other in-house systems.
402 questions
Microsoft Advertising
Microsoft Advertising
A platform for Microsoft's advertising efforts designed to manage all advertising and reporting for partner advertisers. Previously known as Bing Ads and adCenter.
59 questions
0 comments No comments
{count} votes