SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
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()
Xminutes
1時間
Google Inc. - All Rights Reserved
参考資料
MccApp Documentation: http://goo.gl/r0pGJO
Feature guide: http://goo.gl/u65RAF
Code snippets: http://goo.gl/2BXrfo
Complete solutions: http://goo.gl/JSjYyf
Forum: http://goo.gl/sc95Q8
Google Inc. - All Rights Reserved
Questions?
Google Inc. - All Rights Reserved

Mais conteúdo relacionado

Semelhante a Mcc scripts deck (日本語)

Vertica 9.0.0 新機能
Vertica 9.0.0 新機能Vertica 9.0.0 新機能
Vertica 9.0.0 新機能Kaito Tono
 
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回caytosales
 
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナーHTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナーcaytosales
 
Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...
Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...
Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...Masaki Takeda
 
Try_to_writecode_practicaltest #atest_hack
Try_to_writecode_practicaltest #atest_hackTry_to_writecode_practicaltest #atest_hack
Try_to_writecode_practicaltest #atest_hackkimukou_26 Kimukou
 
【17-C-2】 クラウド上でのエンタープライズアプリケーション開発
【17-C-2】 クラウド上でのエンタープライズアプリケーション開発【17-C-2】 クラウド上でのエンタープライズアプリケーション開発
【17-C-2】 クラウド上でのエンタープライズアプリケーション開発lalha
 
20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料
20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料
20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料codeal
 
Team Foundation Server / Visual Studio Team Services 手順書
Team Foundation Server /Visual Studio Team Services 手順書Team Foundation Server /Visual Studio Team Services 手順書
Team Foundation Server / Visual Studio Team Services 手順書Masaki Takeda
 
Angular jsとsinatraでturbolinks
Angular jsとsinatraでturbolinksAngular jsとsinatraでturbolinks
Angular jsとsinatraでturbolinksMinori Tokuda
 
LabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training SlideLabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training SlideYusuke Tochigi
 

Semelhante a Mcc scripts deck (日本語) (10)

Vertica 9.0.0 新機能
Vertica 9.0.0 新機能Vertica 9.0.0 新機能
Vertica 9.0.0 新機能
 
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー第2回
 
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナーHTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー
HTML5で作るハイブリッドアプリに広告実装ハンズオンセミナー
 
Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...
Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...
Team Foundation Server / Visual Studio Team Services によるプロジェクト管理・リポジトリ管理・継続的イ...
 
Try_to_writecode_practicaltest #atest_hack
Try_to_writecode_practicaltest #atest_hackTry_to_writecode_practicaltest #atest_hack
Try_to_writecode_practicaltest #atest_hack
 
【17-C-2】 クラウド上でのエンタープライズアプリケーション開発
【17-C-2】 クラウド上でのエンタープライズアプリケーション開発【17-C-2】 クラウド上でのエンタープライズアプリケーション開発
【17-C-2】 クラウド上でのエンタープライズアプリケーション開発
 
20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料
20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料
20150207コデアルエンジニア学生向けハッカソン就活イベント発表資料
 
Team Foundation Server / Visual Studio Team Services 手順書
Team Foundation Server /Visual Studio Team Services 手順書Team Foundation Server /Visual Studio Team Services 手順書
Team Foundation Server / Visual Studio Team Services 手順書
 
Angular jsとsinatraでturbolinks
Angular jsとsinatraでturbolinksAngular jsとsinatraでturbolinks
Angular jsとsinatraでturbolinks
 
LabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training SlideLabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training Slide
 

Mais de marcwan

Opportunity Analysis with Kratu
Opportunity Analysis with KratuOpportunity Analysis with Kratu
Opportunity Analysis with Kratumarcwan
 
07. feeds update
07. feeds update07. feeds update
07. feeds updatemarcwan
 
AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced marcwan
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scriptingmarcwan
 
AwReporting Update
AwReporting UpdateAwReporting Update
AwReporting Updatemarcwan
 
Getting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google AnalyticsGetting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google Analyticsmarcwan
 
Shopping Campaigns and AdWords API
Shopping Campaigns and AdWords APIShopping Campaigns and AdWords API
Shopping Campaigns and AdWords APImarcwan
 
API Updates for v201402
API Updates for v201402API Updates for v201402
API Updates for v201402marcwan
 
AdWords API Targeting Options
AdWords API Targeting OptionsAdWords API Targeting Options
AdWords API Targeting Optionsmarcwan
 
Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)marcwan
 
Rate limits and performance (Spanish)
Rate limits and performance (Spanish)Rate limits and performance (Spanish)
Rate limits and performance (Spanish)marcwan
 
OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)marcwan
 
End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)marcwan
 
AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)marcwan
 
Api update rundown (Spanish)
Api update rundown (Spanish)Api update rundown (Spanish)
Api update rundown (Spanish)marcwan
 
AdWords Scripts (Spanish)
AdWords Scripts (Spanish)AdWords Scripts (Spanish)
AdWords Scripts (Spanish)marcwan
 
Mobile landing pages (Spanish)
Mobile landing pages (Spanish)Mobile landing pages (Spanish)
Mobile landing pages (Spanish)marcwan
 
Rate limits and performance
Rate limits and performanceRate limits and performance
Rate limits and performancemarcwan
 
OAuth 2.0 refresher
OAuth 2.0 refresherOAuth 2.0 refresher
OAuth 2.0 refreshermarcwan
 
Mobile landing pages
Mobile landing pagesMobile landing pages
Mobile landing pagesmarcwan
 

Mais de marcwan (20)

Opportunity Analysis with Kratu
Opportunity Analysis with KratuOpportunity Analysis with Kratu
Opportunity Analysis with Kratu
 
07. feeds update
07. feeds update07. feeds update
07. feeds update
 
AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scripting
 
AwReporting Update
AwReporting UpdateAwReporting Update
AwReporting Update
 
Getting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google AnalyticsGetting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google Analytics
 
Shopping Campaigns and AdWords API
Shopping Campaigns and AdWords APIShopping Campaigns and AdWords API
Shopping Campaigns and AdWords API
 
API Updates for v201402
API Updates for v201402API Updates for v201402
API Updates for v201402
 
AdWords API Targeting Options
AdWords API Targeting OptionsAdWords API Targeting Options
AdWords API Targeting Options
 
Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)
 
Rate limits and performance (Spanish)
Rate limits and performance (Spanish)Rate limits and performance (Spanish)
Rate limits and performance (Spanish)
 
OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)
 
End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)
 
AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)
 
Api update rundown (Spanish)
Api update rundown (Spanish)Api update rundown (Spanish)
Api update rundown (Spanish)
 
AdWords Scripts (Spanish)
AdWords Scripts (Spanish)AdWords Scripts (Spanish)
AdWords Scripts (Spanish)
 
Mobile landing pages (Spanish)
Mobile landing pages (Spanish)Mobile landing pages (Spanish)
Mobile landing pages (Spanish)
 
Rate limits and performance
Rate limits and performanceRate limits and performance
Rate limits and performance
 
OAuth 2.0 refresher
OAuth 2.0 refresherOAuth 2.0 refresher
OAuth 2.0 refresher
 
Mobile landing pages
Mobile landing pagesMobile landing pages
Mobile landing pages
 

Último

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NTT DATA Technology & Innovation
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)Hiroshi Tomioka
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 

Último (7)

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 

Mcc scripts deck (日本語)

  • 1. Google Inc. - All Rights Reserved
  • 4. Google Inc. - All Rights Reserved はじめに
  • 5. Google Inc. - All Rights Reserved ● AdWords のデータをプログラムから操作する方法 ● JavaScript を使用 ● 開発環境は AdWords UI の中に用意 AdWords スクリプトの復習
  • 6. 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 スクリプトの復習
  • 7. Google Inc. - All Rights Reserved ● MCC レベルで使える AdWords スクリプト ● 多くのアカウントを管理可能に MCC スクリプトとは?
  • 8. Google Inc. - All Rights Reserved ● 現在は、すべての方がご利用になれます 利用可能な方
  • 9. Google Inc. - All Rights Reserved ● 1つのスクリプトで複数のアカウントを管理可能 ● 1つのスクリプトを複数のアカウントにコピーする必要なし ● 複数のアカウントを並列に処理 利点
  • 10. Google Inc. - All Rights Reserved ● 管理している全てのアカウントの入札単価を調整 ● 複数アカウントのレポートを出力 よくある使い方
  • 11. Google Inc. - All Rights Reserved MCC スクリプトを使ってみる 1 2
  • 12. Google Inc. - All Rights Reserved 使ってみよう
  • 13. 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()); } }
  • 14. Google Inc. - All Rights Reserved ● アカウントを管理する機能を提供 ● 子アカウントを取得 ● 操作するアカウントを選択 ● 複数のアカウントを並列に処理 MccApp クラス
  • 15. Google Inc. - All Rights Reserved var accountIterator = MccApp.accounts().get(); ● MccApp.accounts メソッドを使用 ● デフォルトでは、全ての子アカウントを返す(サブMCCは除く) 子アカウントを選択する Script
  • 16. Google Inc. - All Rights Reserved ● アカウント レベルでフィルターすることが可能 子アカウントを選択する var accountIterator = MccApp.accounts() .withCondition('LabelNames CONTAINS "xxx"') .get(); Script
  • 17. Google Inc. - All Rights Reserved ● Customer Id を直接指定することも可能 子アカウントを選択する var accountIterator = MccApp.accounts() .withIds(['123-456-7890', '345-678-9000']) .get(); Script
  • 18. Google Inc. - All Rights Reserved ● デフォルトでは、スクリプトが置かれているアカウント ● MccApp.select を使い、操作対象アカウントを変更 ● AdWordsApp クラスを使いアカウントを操作 ● 最後に操作対象をMCC アカウントへ戻すことを忘れずに! いまどのアカウントを操作している?
  • 19. 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); 特定の子アカウントを操作する
  • 20. Google Inc. - All Rights Reserved アカウントを並列に処理する
  • 21. Google Inc. - All Rights Reserved ● AccountSelector.executeInParallel メソッドを使 用 ● 50 アカウントまで並列に処理可能 ● すべての処理終了後、オプションで callback 関数を実行可 能 アカウントを並列に処理する
  • 22. Script Google Inc. - All Rights Reserved function main() { MccApp.accounts().executeInParallel("processAccount"); } function processAccount() { Logger.log("Operating on %s", AdWordsApp.currentAccount().getCustomerId()); // アカウントへの処理を実行 // ... return; } アカウントを並列に処理する
  • 23. Script Google Inc. - All Rights Reserved function main() { MccApp.accounts().executeInParallel("processAccount", "allFinished"); } function processAccount() { ... } function allFinished(results) { ... } Callback 関数を指定
  • 24. Google Inc. - All Rights Reserved ● Callback 関数の results 引数を使用 ● ExecutionResult オブジェクトの配列 ● 1つのアカウント処理につき、1つの ExecutionResult 実行結果を分析する
  • 25. Google Inc. - All Rights Reserved ● ExecutionResult オブジェクトが含む情報 ● CustomerId ● Status (Success, Error, Timeout) ● Error (もしあれば) ● processAccount の返り値 実行結果を分析する
  • 26. 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()); } 実行結果を返す
  • 27. Google Inc. - All Rights Reserved ● 処理関数は string の返り値を返すことができる ● 複雑なオブジェクトを返したい場合には、JSON.stringify / JSON.parse を使用してオブジェクトの serialize / deserialize を行う ● 大きな値を返したい場合には、各種データストレージを使う (E.g. SpreadSheetApp, DriveApp...) 実行結果を返す
  • 28. 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() Xminutes 1時間
  • 29. Google Inc. - All Rights Reserved 参考資料 MccApp Documentation: http://goo.gl/r0pGJO Feature guide: http://goo.gl/u65RAF Code snippets: http://goo.gl/2BXrfo Complete solutions: http://goo.gl/JSjYyf Forum: http://goo.gl/sc95Q8
  • 30. Google Inc. - All Rights Reserved Questions?
  • 31. Google Inc. - All Rights Reserved