Upload
marcwan
View
1.897
Download
0
Embed Size (px)
Citation preview
Google Inc. - All Rights Reserved
MCC スクリプトJavaScript を使った効率的なアカウント管理
Ryuich Hoshi, Google.
目次
● はじめに
● 使ってみよう
● 参考資料
● Questions?
Google Inc. - All Rights Reserved
はじめに
Google Inc. - All Rights Reserved
● AdWords のデータをプログラムから操作する方法
● JavaScript を使用
● 開発環境は AdWords UI の中に用意
AdWords スクリプトの復習
Script
Google Inc. - All Rights Reserved
function main() { // AWQL を使って指定した名前のキャンペーンを取得 var demoCampaign = AdWordsApp.campaigns(). withCondition("Name='Demo campaign'").get().next(); // AWQL を使って、直下の広告グループを取得 var demoAdGroup = demoCampaign.adGroups(). withCondition("Name='Demo adgroup'").get().next();
// 広告グループの設定を変更 demoAdGroup.setKeywordMaxCpc(1.2);}
AdWords スクリプトの復習
Google Inc. - All Rights Reserved
● MCC レベルで使える AdWords スクリプト
● 多くのアカウントを管理可能に
MCC スクリプトとは?
Google Inc. - All Rights Reserved
● 現在は、すべての方がご利用になれます
利用可能な方
Google Inc. - All Rights Reserved
● 1つのスクリプトで複数のアカウントを管理可能
● 1つのスクリプトを複数のアカウントにコピーする必要なし
● 複数のアカウントを並列に処理
利点
Google Inc. - All Rights Reserved
● 管理している全てのアカウントの入札単価を調整
● 複数アカウントのレポートを出力
よくある使い方
Google Inc. - All Rights Reserved
MCC スクリプトを使ってみる
1
2
Google Inc. - All Rights Reserved
使ってみよう
Script
Google Inc. - All Rights Reserved
初めての MCC スクリプト
function main() { // 全ての子アカウントを取得
var accountIterator = MccApp.accounts().get();
// 取得したアカウントを順に処理 while (accountIterator.hasNext()) { var account = accountIterator.next();
// 子アカウントのパフォーマンス データを取得 var stats = account.getStatsFor("THIS_MONTH");
// ログに出力 Logger.log("%s,%s,%s,%s", account.getCustomerId(), stats.getClicks(), stats.getImpressions(), stats.getCost()); }}
Google Inc. - All Rights Reserved
● アカウントを管理する機能を提供
● 子アカウントを取得
● 操作するアカウントを選択
● 複数のアカウントを並列に処理
MccApp クラス
Google Inc. - All Rights Reserved
var accountIterator = MccApp.accounts().get();
● MccApp.accounts メソッドを使用
● デフォルトでは、全ての子アカウントを返す(サブMCCは除く)
子アカウントを選択する
Script
Google Inc. - All Rights Reserved
● アカウント レベルでフィルターすることが可能
子アカウントを選択する
var accountIterator = MccApp.accounts()
.withCondition('LabelNames CONTAINS "xxx"')
.get();
Script
Google Inc. - All Rights Reserved
● Customer Id を直接指定することも可能
子アカウントを選択する
var accountIterator = MccApp.accounts()
.withIds(['123-456-7890', '345-678-9000'])
.get();
Script
Google Inc. - All Rights Reserved
● デフォルトでは、スクリプトが置かれているアカウント
● MccApp.select を使い、操作対象アカウントを変更
● AdWordsApp クラスを使いアカウントを操作
● 最後に操作対象をMCC アカウントへ戻すことを忘れずに!
いまどのアカウントを操作している?
Script
Google Inc. - All Rights Reserved
var childAccount = MccApp.accounts().withIds(["918-501-8835"]) .get().next();
// 現在のMCCアカウントを保存
var mccAccount = AdWordsApp.currentAccount();
// 子アカウントを選択
MccApp.select(childAccount);
// 子アカウントへの処理を実行...
// 操作対象を MCC アカウントに戻すMccApp.select(mccAccount);
特定の子アカウントを操作する
Google Inc. - All Rights Reserved
アカウントを並列に処理する
Google Inc. - All Rights Reserved
● AccountSelector.executeInParallel メソッドを使
用
● 50 アカウントまで並列に処理可能
● すべての処理終了後、オプションで callback 関数を実行可
能
アカウントを並列に処理する
Script
Google Inc. - All Rights Reserved
function main() { MccApp.accounts().executeInParallel("processAccount");}
function processAccount() { Logger.log("Operating on %s",
AdWordsApp.currentAccount().getCustomerId()); // アカウントへの処理を実行 // ... return;}
アカウントを並列に処理する
Script
Google Inc. - All Rights Reserved
function main() { MccApp.accounts().executeInParallel("processAccount",
"allFinished");}
function processAccount() { ...}
function allFinished(results) { ...}
Callback 関数を指定
Google Inc. - All Rights Reserved
● Callback 関数の results 引数を使用
● ExecutionResult オブジェクトの配列
● 1つのアカウント処理につき、1つの ExecutionResult
実行結果を分析する
Google Inc. - All Rights Reserved
● ExecutionResult オブジェクトが含む情報
● CustomerId
● Status (Success, Error, Timeout)
● Error (もしあれば)
● processAccount の返り値
実行結果を分析する
Script
Google Inc. - All Rights Reserved
function processAccount() { return AdWordsApp.campaigns().get().totalNumEntities().toString();}
function allFinished(results) { var totalCampaigns = 0; for (var i = 0; i < results.length; i++) { totalCampaigns += parseInt(results[i].getReturnValue()); } Logger.log("There are %s campaigns under MCC ID: %s.",
totalCampaigns,
AdWordsApp.currentAccount().getCustomerId());}
実行結果を返す
Google Inc. - All Rights Reserved
● 処理関数は string の返り値を返すことができる
● 複雑なオブジェクトを返したい場合には、JSON.stringify /
JSON.parse を使用してオブジェクトの serialize /
deserialize を行う
● 大きな値を返したい場合には、各種データストレージを使う
(E.g. SpreadSheetApp, DriveApp...)
実行結果を返す
Google Inc. - All Rights Reserved
実行時間制限
30-X 分
processAccount(A)
30 分30 分
30-X 分
processAccount(C)
30-X 分
processAccount(B)
main() 関数
executeInParallel() をアカウント A, B, C へ実行
allFinished()
X m
inutes
1 時間
Google Inc. - All Rights Reserved
参考資料
MccApp Documentation: http://goo.gl/r0pGJOFeature guide: http://goo.gl/u65RAFCode snippets: http://goo.gl/2BXrfoComplete solutions: http://goo.gl/JSjYyfForum: http://goo.gl/sc95Q8
Google Inc. - All Rights Reserved
Questions?
Google Inc. - All Rights Reserved