Yahoo!広告 スクリプト | Developer Center
English広告
・テキスト広告を新規追加する・テキスト広告を編集する
・画像広告を新規追加する
・画像広告を編集する
・レスポンシブディスプレイ広告を新規追加する
・レスポンシブディスプレイ広告を編集する
・広告グループ配下の広告を配信停止にする
・全ての広告情報を取得する
・指定の広告情報を取得する
・広告グループ配下の全ての広告情報を取得する
テキスト広告を新規追加する
function addTextAd() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupAdArray = [
{
accountId: accountId,
ad: {
adType: 'TEXT_AD',
mainMediaFormat:'NONE',
textAd: {
description: 'descriptionAAA',
headline: 'headlineAAA',
},
displayUrlLevel: 'DOMAIN',
finalUrl: 'http://xxxxx.co.jp',
},
adGroupId: 111111111,
adName: 'adNameAAA',
campaignId: 22222222,
userStatus: 'ACTIVE',
}
];//Multiple selections are possible
const adGroupAds = Display.AdGroupAdService.add({
accountId: accountId,
operand: adGroupAdArray,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++) {
if (adGroupAds.values[i].operationSucceeded) {
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adId-> ' + adGroupAd.adId + ', adName-> ' + adGroupAd.adName
+ ' be added as headline-> ' + adGroupAd.ad.textAd.headline + ', description-> ' + adGroupAd.ad.textAd.description
+ ' to adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName);
} else {
Logger.log('adName-> ' + adGroupAdArray[i].adName
+ ' could not to be added as headline-> ' + adGroupAdArray[i].ad.textAd.headline
+ ', description-> ' + adGroupAdArray[i].ad.textAd.description + ' to adGroupId-> ' + adGroupAdArray[i].adGroupId);
}
}
}
テキスト広告を編集する
function setTextAd() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupAdArray = [
{
accountId: accountId,
ad: {
adType: 'TEXT_AD',
mainMediaFormat:'NONE',
textAd: {
description: 'New descriptionAAA',
description2: 'New descriptionBBB',
headline: 'New headlineAAA',
},
displayUrlLevel: 'FIRST_LEVEL',
finalUrl: 'http://yyyyy.co.jp/aaaaa/bbbbb',
},
adId: 3333333333,
adGroupId: 111111111,
campaignId: 22222222,
userStatus: 'ACTIVE',
}
];//Multiple selections are possible
const adGroupAds = Display.AdGroupAdService.set({
accountId: accountId,
operand: adGroupAdArray,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++) {
if (adGroupAds.values[i].operationSucceeded) {
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adId-> ' + adGroupAd.adId + ', adName-> ' + adGroupAd.adName + ', adType-> ' + adGroupAd.ad.adType + ' has been updated.');
} else {
Logger.log('adId-> ' + adGroupAdArray[i].adId + ' could not be updated.');
}
}
}
画像広告を新規追加する
function addImageAd() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupAdArray = [
{
accountId: accountId,
ad: {
adType: 'BANNER_AD',
mainMediaFormat: "IMAGE",
bannerAd: null,//Required even if null
displayUrlLevel: 'DOMAIN',
finalUrl: 'http://xxxxx.co.jp'
},
adGroupId: 111111111,
adName: 'adNameAAA',
campaignId: 22222222,
mediaId: 3333333,
userStatus: 'ACTIVE',
}
];//Multiple selections are possible
const adGroupAds = Display.AdGroupAdService.add({
accountId: accountId,
operand: adGroupAdArray,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++){
if (adGroupAds.values[i].operationSucceeded) {
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adName-> ' + adGroupAd.adName + ', adId-> ' + adGroupAd.adId + ', mediaId-> ' + adGroupAd.mediaId
+ ' be added to adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName);
} else {
Logger.log('adName-> ' + adGroupAdArray[i].adName
+ ' could not to be added to adGroupId-> ' + adGroupAdArray[i].adGroupId);
}
}
}
画像広告を編集する
function setImageAd() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupAdArray = [
{
accountId: accountId,
ad: {
adType: 'BANNER_AD',
mainMediaFormat: 'IMAGE',
displayUrlLevel: 'FIRST_LEVEL',
finalUrl: 'http://xxxxx.co.jp/aaaaa/bbbbb',
},
adId: 3333333333,
adGroupId: 111111111,
campaignId: 22222222,
mediaId: 4444444,
userStatus: 'ACTIVE',
}
]; //Multiple selections are possible
const adGroupAds = Display.AdGroupAdService.set({
accountId: accountId,
operand: adGroupAdArray,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++){
if (adGroupAds.values[i].operationSucceeded) {
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adId-> ' + adGroupAd.adId + ', adName-> ' + adGroupAd.adName + ', adType-> ' + adGroupAd.ad.adType + ' has been updated.');
} else {
Logger.log('adId-> ' + adGroupAdArray[i].adId + ' could not be updated.');
}
}
}
レスポンシブディスプレイ広告を新規追加する
function addResponsiveDisplayAd() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupAdArray = [
{
accountId: accountId,
ad: {
adType: 'RESPONSIVE_AD',
mainMediaFormat: 'IMAGE',
responsiveAd: {
buttonText: 'MORE_DETAIL',//https://ads-developers.yahoo.co.jp/ja/ads-script/product-guide/reference/enums/display.AdGroupAdServiceButtonText.html
principal: 'principalAAA',
asset: {
mediaAssets: [
{ mediaId: 1111111 },
{ mediaId: 2222222 },
{ mediaId: 3333333 },
],
headlineAssets: [
{ text: "headlineAsset1" },
{ text: "headlineAsset2" },
{ text: "headlineAsset3" },
],
descriptionAssets: [
{ text: "descriptionAsset1" },
{ text: "descriptionAsset2" },
{ text: "descriptionAsset3" },
]
}
},
displayUrlLevel: 'DOMAIN',
finalUrl: 'http://xxxxx.co.jp'
},
campaignId: 11111111,
adGroupId: 222222222,
adName: 'adNameAAA',
userStatus: 'ACTIVE',
}
];//Multiple selections are possible
const adGroupAds = Display.AdGroupAdService.add({
accountId: accountId,
operand: adGroupAdArray,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++) {
if (adGroupAds.values[i].operationSucceeded) {
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adName-> ' + adGroupAd.adName + ', adId-> ' + adGroupAd.adId + ', mediaId-> ' + adGroupAd.mediaId
+ ' be added to adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName);
} else {
Logger.log('adName-> ' + adGroupAdArray[i].adName
+ ' could not to be added to adGroupId-> ' + adGroupAdArray[i].adGroupId);
}
}
}
レスポンシブディスプレイ広告を編集する
function setResponsiveDisplayAd() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupAdArray = [
{
accountId: accountId,
ad: {
adType: 'RESPONSIVE_AD',
mainMediaFormat: 'IMAGE',
responsiveAd: {
buttonText: 'FOR_MORE_INFO',//https://ads-developers.yahoo.co.jp/ja/ads-script/product-guide/reference/enums/display.AdGroupAdServiceButtonText.html
principal: 'principalBBB',
asset: {
mediaAssets: [
{ mediaId: 1111111 },
],
headlineAssets: [
{ text: "New headlineAsset" },
{ text: "New headlineAsset2" },
],
descriptionAssets: [
{ text: "New descriptionAsset" },
{ text: "New descriptionAsset2" },
]
}
},
displayUrlLevel: 'FIRST_LEVEL',
finalUrl: 'http://yyyyy.co.jp/aaaaaaa/bbbbbbb'
},
campaignId: 11111111,
adGroupId: 222222222,
adId: 3333333333,
userStatus: 'ACTIVE',
}
];//Multiple selections are possible
const adGroupAds = Display.AdGroupAdService.set({
accountId: accountId,
operand: adGroupAdArray,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++) {
if (adGroupAds.values[i].operationSucceeded) {
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adId-> ' + adGroupAd.adId + ', adName-> ' + adGroupAd.adName + ', adType-> ' + adGroupAd.ad.adType + ' has been updated.');
} else {
Logger.log('adId-> ' + adGroupAdArray[i].adId + ' could not be updated.');
}
}
}
広告グループ配下の広告を配信停止にする
function pauseAdsInAdGroup() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupIds = [111111111, 222222222];//Multiple selections are possible
const adGroupAdsGet = Display.AdGroupAdService.get({
accountId: accountId,
adGroupIds: adGroupIds,
}).rval;
if (adGroupAdsGet.totalNumEntries == 0) {
Logger.log('Target ID does not exist.');
return;
}
let adGroupAdArray = [];
for (let i = 0; i < adGroupAdsGet.values.length; i++){
let adGroupAd = adGroupAdsGet.values[i].adGroupAd;
let setAd = {
accountId: accountId,
campaignId: adGroupAd.campaignId,
adGroupId: adGroupAd.adGroupId,
adId: adGroupAd.adId,
userStatus: 'PAUSED'
};
adGroupAdArray.push(setAd);
}
const adGroupAdsSet = Display.AdGroupAdService.set({
accountId: accountId,
operand: adGroupAdArray,
}).rval;
for (let i = 0; i < adGroupAdsSet.values.length; i++){
if (adGroupAdsSet.values[i].operationSucceeded) {
let adGroupAd = adGroupAdsSet.values[i].adGroupAd;
Logger.log('adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName
+ ', adName-> ' + adGroupAd.adName + ', adId-> ' + adGroupAd.adId + ' have been stopped.');
} else {
let adGroupAd = adGroupAdsGet.values[i].adGroupAd;
Logger.log('adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName
+ ', adName-> ' + adGroupAd.adName + ', adId-> ' + adGroupAd.adId + ' could not to be stopped.');
}
}
}
全ての広告情報を取得する
function getAllAds() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupAds = Display.AdGroupAdService.get({
accountId: accountId,
numberResults: 10000,
}).rval;
if (adGroupAds.totalNumEntries == 0) {
Logger.log('Target ID does not exist.');
return;
}
for (let i = 0; i < adGroupAds.values.length; i++){
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adType-> ' + adGroupAd.ad.adType + ', adStyle-> ' + adGroupAd.adStyle
+ ', adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName
+ ', adId-> ' + adGroupAd.adId + ', adName-> ' + adGroupAd.adName
+ ', mediaId-> ' + adGroupAd.mediaId);
}
}
指定の広告情報を取得する
function getAllAdsById() {
const accountId = AdsUtilities.getCurrentAccountId();
const adIds = [1111111111, 2222222222];//Multiple selections are possible
const adGroupAds = Display.AdGroupAdService.get({
accountId: accountId,
adIds: adIds,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++){
let adGroupAd = adGroupAds.values[i].adGroupAd;
Logger.log('adType-> ' + adGroupAd.ad.adType + ', adStyle-> ' + adGroupAd.adStyle
+ ', adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName
+ ', adId-> ' + adGroupAd.adId + ', adName-> ' + adGroupAd.adName
+ ', mediaId-> ' + adGroupAd.mediaId);
}
}
広告グループ配下の全ての広告情報を取得する
function getAdInAdGroup() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupIds = [111111111, 222222222, 333333333];//Empty when not specified
const adGroupAds = Display.AdGroupAdService.get({
accountId: accountId,
adGroupIds: adGroupIds,
numberResults: 10000,
}).rval;
for (let i = 0; i < adGroupAds.values.length; i++) {
let adGroupAd = adGroupAds.values[i].adGroupAd;
let logText = 'adType-> ' + adGroupAd.ad.adType + 'mainMediaFormat-> ' + adGroupAd.ad.mainMediaFormat
+ ', adGroupId-> ' + adGroupAd.adGroupId + ', adGroupName-> ' + adGroupAd.adGroupName
+ ', adId-> ' + adGroupAd.adId + ', adName-> ' + adGroupAd.adName;
switch (adGroupAd.ad.adType) {
case 'TEXT_AD':
case 'DYNAMIC_DISPLAY_AD':
//mediaIdなし
break;
case 'RESPONSIVE_AD':
if (adGroupAd.ad.mainMediaFormat == 'VIDEO') {
logText += ', mediaId-> ' + adGroupAd.mediaId;//動画の場合は入る
}
break;
case 'BANNER_AD':
case 'CAROUSEL_AD':
logText += ', mediaId-> ' + adGroupAd.mediaId;
break;
}
Logger.log(logText);
}
}