5. Google Inc. - All Rights Reserved
● Way to programmatically access AdWords data
● Write your code in JavaScript
● Embedded IDE in AdWords UI
Recap - AdWords Scripts
6. Script
Google Inc. - All Rights Reserved
function main() {
// Retrieve campaign by name using AWQL.
var demoCampaign = AdWordsApp.campaigns().
withCondition("Name='Demo campaign'").get().next();
// Retrieve child adgroup using AWQL.
var demoAdGroup = demoCampaign.adGroups().
withCondition("Name='Demo adgroup'").get().next();
// Modify the adgroup properties.
demoAdGroup.setKeywordMaxCpc(1.2);
}
Recap - AdWords Scripts
7. Google Inc. - All Rights Reserved
● AdWords Scripts at MCC level
● Allows managing accounts at scale
What are MCC Scripts?
8. Google Inc. - All Rights Reserved
● Currently open for beta signup
● Whitelisting usually takes a few business days.
● Request whitelist at top-level MCC account
Availability
9. Google Inc. - All Rights Reserved
● Manage multiple client accounts from a single script
● No more copy-pasting a script into multiple accounts!
● Process multiple accounts in parallel
Benefits
10. Google Inc. - All Rights Reserved
● Bid management in all your child accounts
● Cross-account reporting
Common use cases
11. Google Inc. - All Rights Reserved
Accessing MCC Scripts
1
2
13. Script
Google Inc. - All Rights Reserved
Your first script
function main() {
// Retrieve all the child accounts.
var accountIterator = MccApp.accounts().get();
// Iterate through the account list.
while (accountIterator.hasNext()) {
var account = accountIterator.next();
// Get stats for the child account.
var stats = account.getStatsFor("THIS_MONTH");
// And log it.
Logger.log("%s,%s,%s", account.getCustomerId(), stats.getClicks(),
stats.getImpressions(), stats.getCost());
}
}
14. Google Inc. - All Rights Reserved
● Provides account management functionality
● Retrieve child accounts
● Select a child account for further operations
● Process multiple child accounts in parallel
MccApp class
15. Google Inc. - All Rights Reserved
var accountIterator = MccApp.accounts().get();
● Use MccApp.accounts method
● By default, returns all client accounts (excluding sub-
MCCs)
Selecting child accounts
Script
16. Google Inc. - All Rights Reserved
● Can optionally filter by an account label
Selecting child accounts (cont’d)
var accountIterator = MccApp.accounts()
.withCondition('LabelName = "xxx"')
.get();
Script
17. Google Inc. - All Rights Reserved
● Can optionally take a list of client ids
Selecting child accounts (cont’d)
var accountIterator = MccApp.accounts()
.withIds(['123-456-7890', '345-678-9000'])
.get();
Script
18. Google Inc. - All Rights Reserved
● By default, this is the account where script resides
● Switch context using MccApp.select method
● Then use AdWordsApp class to process account
● Remember to switch back to your MCC account!
What account am I operating on?
19. Script
Google Inc. - All Rights Reserved
var childAccount = MccApp.accounts().withIds(["918-501-8835"])
.get().next();
// Save the MCC account.
var mccAccount = AdWordsApp.currentAccount();
// Select the child account
MccApp.select(childAccount);
// Process the account.
...
// Switch back to MCC account.
MccApp.select(mccAccount);
Operating on a specific child account (cont’d)
20. Google Inc. - All Rights Reserved
Processing accounts in parallel
21. Google Inc. - All Rights Reserved
● Use AccountSelector.executeInParallel
method
● Operate on upto 50 accounts in parallel
● Optional callback method after processing accounts
Operating on accounts in parallel
22. Script
Google Inc. - All Rights Reserved
function main() {
MccApp.accounts().executeInParallel("processAccount");
}
function processAccount() {
Logger.log("Operating on %s",
AdWordsApp.currentAccount().getCustomerId());
// Process the account.
// ...
return;
}
Operating on accounts in parallel (cont’d)
23. Script
Google Inc. - All Rights Reserved
function main() {
MccApp.accounts().executeInParallel("processAccount",
"allFinished");
}
function processAccount() {
...
}
function allFinished(results) {
...
}
Specifying a callback
24. Google Inc. - All Rights Reserved
● Use results argument of callback method
● Array of ExecutionResult objects
● One ExecutionResult per account processed
Analyzing the outcome...
25. Google Inc. - All Rights Reserved
● Contains
● CustomerId
● Status (Success, Error, Timeout)
● Error (if any)
● Return values from processAccount
Analyzing the outcome (cont’d)
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());
}
Returning processing results (cont’d)
27. Google Inc. - All Rights Reserved
● Processing method can return a string value
● Use JSON.stringify / JSON.parse to serialize / deserialize
complex objects
● Use datastore to return large values
● E.g. SpreadSheetApp, DriveApp...
Returning processing results (cont’d)
28. Google Inc. - All Rights Reserved
Execution time limits
30-Xmin
processAccount(A)
30
minutes
30minutes
30-Xmin
processAccount(C)
30-Xmin
processAccount(B)
main() method
calls executeInParallel() for
accounts A, B, C
allFinished()
Xminutes
1hour
29. Google Inc. - All Rights Reserved
● Signup form: https://services.google.
com/fb/forms/mccscripts
Beta signup
30. Google Inc. - All Rights Reserved
Resources
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