ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
AdWords API Workshops ¨C All rights reserved
AdWords Scripts
Automate AdWords activities using JavaScript

Anash P. Oommen, Google, Inc.

AdWords API Workshops ¨C All rights reserved
Table of contents
¡ñ Introduction
¡ñ Your first script + demo
¡ñ Getting help
¡ñ Questions
¡ñ Resources

AdWords API Workshops ¨C All rights reserved
Introduction

AdWords API Workshops ¨C All rights reserved
Introduction
¡ñ Way to programmatically access AdWords data
¡ñ Write your code in JavaScript
¡ñ Embedded IDE in AdWords UI

AdWords API Workshops ¨C All rights reserved
Common use cases
¡ñ Quick one-time tools
¡ñ Highly customized reporting
¡ñ Account alerts
¡ñ External feed-based triggers

AdWords API Workshops ¨C All rights reserved
Requirements
¡ñ Entry-level familiarity with JavaScript
¡ñ An AdWords account to start writing your script!

AdWords API Workshops ¨C All rights reserved
Capabilities
¡ñ Can access important AdWords types
¡ð Campaigns, Ad groups, Keywords, Ads, ad
extensions, reports¡­
¡ñ API-specific types
¡ð Ad Params

¡ñ Types not yet available in AdWords API
¡ð Labels

¡ñ No beta restriction

AdWords API Workshops ¨C All rights reserved
Capabilities (cont¡¯d)
¡ñ IDE with autocomplete and syntax highlighting
¡ñ Run normally or in preview mode
¡ð Preview mode won¡¯t make any changes to your accounts
¡ð Will perform actions like sending email, updating
spreadsheets, etc.

¡ñ Uses OAuth 2.0 for authentication
¡ð Up to 250 scripts per login email.

AdWords API Workshops ¨C All rights reserved
Capabilities (cont¡¯d)
¡ñ Scripts can be automated
¡ð Can be scheduled to execute periodically on your behalf
¡ð As frequently as every hour.

¡ñ Can talk to external data sources
¡ð
¡ð
¡ð
¡ð

Fetch arbitrary URLs
Interact with Google Drive
Interact with Google Spreadsheets
Send emails

AdWords API Workshops ¨C All rights reserved
Capabilities (cont¡¯d)
¡ñ Simplified APIs
¡ñ Requires lesser amount of code than AdWords API.
¡ñ E.g. simplified feed services¡­

AdWords API Workshops ¨C All rights reserved
Demo

AdWords API Workshops ¨C All rights reserved
Creating your first script

AdWords API Workshops ¨C All rights reserved
Creating your first script (cont¡¯d)

AdWords API Workshops ¨C All rights reserved
First script - retrieve all campaigns
function main() {
// Get all campaigns.
var campaignIterator = AdWordsApp.campaigns().get();
// iterate the list and print names to logger window.
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
Logger.log(campaign.getName());
}
}

AdWords API Workshops ¨C All rights reserved

AW SCRIPT
Retrieving and updating objects
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);
}
AdWords API Workshops ¨C All rights reserved

AW SCRIPT
Reporting
function main() {

AW SCRIPT

// Run an account performance report
var report = AdWordsApp.report("SELECT Clicks, Impressions, " +
"Cost, AverageCpc, Date FROM ACCOUNT_PERFORMANCE_REPORT " +
"DURING LAST_WEEK");
// Retrieve the spreadsheet to export values to.
var SPREADSHEET_URL = "xxx";
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = spreadsheet.getSheetByName(
"Account performance report");

AdWords API Workshops ¨C All rights reserved
Reporting - cont¡¯d
// Export the report to spreadsheet
report.exportToSheet(sheet);
// Send out an email with the spreadsheet link
MailApp.sendEmail("john_hancock@google.com",
"Account performance report is ready!",
"Access it at " + SPREADSHEET_URL);
}

AdWords API Workshops ¨C All rights reserved

AW SCRIPT
Getting help

AdWords API Workshops ¨C All rights reserved
Documentation and code snippets
¡ñ Refer to the documentation
¡ð https://developers.google.com/adwords/scripts/

¡ñ Refer to our code snippets
¡ð Accessible from the IDE
¡ð Also available on documentation site

AdWords API Workshops ¨C All rights reserved
Ask on our forum!
¡ñ Ask on our forum
¡ð https://groups.google.com/forum/#!forum/adwords-scripts
¡ð Ask for general questions, code snippets, complete solutions,
feature requests¡­
¡ð Lots of helpful developers and Scripts team members!

AdWords API Workshops ¨C All rights reserved
Complete solutions
¡ñ Ready-to-use complete solutions
¡ð
¡ð
¡ð
¡ð

https://developers.google.com/adwords/scripts/docs/solutions/
Ready-to-use as provided
Customize if required
Multiple categories - customized reporting, bidding tools¡­

¡ñ Scripts from third party developers
¡ð http://www.freeadwordsscripts.com/

AdWords API Workshops ¨C All rights reserved
Questions?

AdWords API Workshops ¨C All rights reserved
Resources
Documentation: http://goo.gl/77ACP
Forum: http://goo.gl/QsxCz5

AdWords API Workshops ¨C All rights reserved
AdWords API Workshops ¨C All rights reserved
Appendix 1 - Create sitelinks
var sitelink = AdWordsApp.extensions()
.newSitelinkBuilder()
.withLinkText("Hello world")
.withLinkUrl("http://www.example.com")
.create();
AdWordsApp.campaigns()
.withIds(['178532656'])
.get().next()
.addSitelink(sitelink);

AdWords API Workshops ¨C All rights reserved

AW SCRIPT
Appendix 2 - Read AdParams
//interator on keywords
var kwIter = AdWordsApp.keywords().get(); //this is long, select campaign first
while (kwIter.hasNext()) {
//iterator on parameter of the current keyword
var adParamIter = kwIter.next().adParams().get();
while (adParamIter.hasNext()) {
var adParam = adParamIter.next();
Logger.log("campaign="+ adParam.getAdGroup().getCampaign().getName()+
" AdGroup="+ adParam.getAdGroup().getName()+
" KW=" + adParam.getKeyword().getText() +
" idx=" + adParam.getIndex() +
" value=" + adParam.getInsertionText());
}
}

AdWords API Workshops ¨C All rights reserved

AW SCRIPT

More Related Content

AdWords Scripts

  • 1. AdWords API Workshops ¨C All rights reserved
  • 2. AdWords Scripts Automate AdWords activities using JavaScript Anash P. Oommen, Google, Inc. AdWords API Workshops ¨C All rights reserved
  • 3. Table of contents ¡ñ Introduction ¡ñ Your first script + demo ¡ñ Getting help ¡ñ Questions ¡ñ Resources AdWords API Workshops ¨C All rights reserved
  • 4. Introduction AdWords API Workshops ¨C All rights reserved
  • 5. Introduction ¡ñ Way to programmatically access AdWords data ¡ñ Write your code in JavaScript ¡ñ Embedded IDE in AdWords UI AdWords API Workshops ¨C All rights reserved
  • 6. Common use cases ¡ñ Quick one-time tools ¡ñ Highly customized reporting ¡ñ Account alerts ¡ñ External feed-based triggers AdWords API Workshops ¨C All rights reserved
  • 7. Requirements ¡ñ Entry-level familiarity with JavaScript ¡ñ An AdWords account to start writing your script! AdWords API Workshops ¨C All rights reserved
  • 8. Capabilities ¡ñ Can access important AdWords types ¡ð Campaigns, Ad groups, Keywords, Ads, ad extensions, reports¡­ ¡ñ API-specific types ¡ð Ad Params ¡ñ Types not yet available in AdWords API ¡ð Labels ¡ñ No beta restriction AdWords API Workshops ¨C All rights reserved
  • 9. Capabilities (cont¡¯d) ¡ñ IDE with autocomplete and syntax highlighting ¡ñ Run normally or in preview mode ¡ð Preview mode won¡¯t make any changes to your accounts ¡ð Will perform actions like sending email, updating spreadsheets, etc. ¡ñ Uses OAuth 2.0 for authentication ¡ð Up to 250 scripts per login email. AdWords API Workshops ¨C All rights reserved
  • 10. Capabilities (cont¡¯d) ¡ñ Scripts can be automated ¡ð Can be scheduled to execute periodically on your behalf ¡ð As frequently as every hour. ¡ñ Can talk to external data sources ¡ð ¡ð ¡ð ¡ð Fetch arbitrary URLs Interact with Google Drive Interact with Google Spreadsheets Send emails AdWords API Workshops ¨C All rights reserved
  • 11. Capabilities (cont¡¯d) ¡ñ Simplified APIs ¡ñ Requires lesser amount of code than AdWords API. ¡ñ E.g. simplified feed services¡­ AdWords API Workshops ¨C All rights reserved
  • 12. Demo AdWords API Workshops ¨C All rights reserved
  • 13. Creating your first script AdWords API Workshops ¨C All rights reserved
  • 14. Creating your first script (cont¡¯d) AdWords API Workshops ¨C All rights reserved
  • 15. First script - retrieve all campaigns function main() { // Get all campaigns. var campaignIterator = AdWordsApp.campaigns().get(); // iterate the list and print names to logger window. while (campaignIterator.hasNext()) { var campaign = campaignIterator.next(); Logger.log(campaign.getName()); } } AdWords API Workshops ¨C All rights reserved AW SCRIPT
  • 16. Retrieving and updating objects 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); } AdWords API Workshops ¨C All rights reserved AW SCRIPT
  • 17. Reporting function main() { AW SCRIPT // Run an account performance report var report = AdWordsApp.report("SELECT Clicks, Impressions, " + "Cost, AverageCpc, Date FROM ACCOUNT_PERFORMANCE_REPORT " + "DURING LAST_WEEK"); // Retrieve the spreadsheet to export values to. var SPREADSHEET_URL = "xxx"; var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL); var sheet = spreadsheet.getSheetByName( "Account performance report"); AdWords API Workshops ¨C All rights reserved
  • 18. Reporting - cont¡¯d // Export the report to spreadsheet report.exportToSheet(sheet); // Send out an email with the spreadsheet link MailApp.sendEmail("john_hancock@google.com", "Account performance report is ready!", "Access it at " + SPREADSHEET_URL); } AdWords API Workshops ¨C All rights reserved AW SCRIPT
  • 19. Getting help AdWords API Workshops ¨C All rights reserved
  • 20. Documentation and code snippets ¡ñ Refer to the documentation ¡ð https://developers.google.com/adwords/scripts/ ¡ñ Refer to our code snippets ¡ð Accessible from the IDE ¡ð Also available on documentation site AdWords API Workshops ¨C All rights reserved
  • 21. Ask on our forum! ¡ñ Ask on our forum ¡ð https://groups.google.com/forum/#!forum/adwords-scripts ¡ð Ask for general questions, code snippets, complete solutions, feature requests¡­ ¡ð Lots of helpful developers and Scripts team members! AdWords API Workshops ¨C All rights reserved
  • 22. Complete solutions ¡ñ Ready-to-use complete solutions ¡ð ¡ð ¡ð ¡ð https://developers.google.com/adwords/scripts/docs/solutions/ Ready-to-use as provided Customize if required Multiple categories - customized reporting, bidding tools¡­ ¡ñ Scripts from third party developers ¡ð http://www.freeadwordsscripts.com/ AdWords API Workshops ¨C All rights reserved
  • 23. Questions? AdWords API Workshops ¨C All rights reserved
  • 25. AdWords API Workshops ¨C All rights reserved
  • 26. Appendix 1 - Create sitelinks var sitelink = AdWordsApp.extensions() .newSitelinkBuilder() .withLinkText("Hello world") .withLinkUrl("http://www.example.com") .create(); AdWordsApp.campaigns() .withIds(['178532656']) .get().next() .addSitelink(sitelink); AdWords API Workshops ¨C All rights reserved AW SCRIPT
  • 27. Appendix 2 - Read AdParams //interator on keywords var kwIter = AdWordsApp.keywords().get(); //this is long, select campaign first while (kwIter.hasNext()) { //iterator on parameter of the current keyword var adParamIter = kwIter.next().adParams().get(); while (adParamIter.hasNext()) { var adParam = adParamIter.next(); Logger.log("campaign="+ adParam.getAdGroup().getCampaign().getName()+ " AdGroup="+ adParam.getAdGroup().getName()+ " KW=" + adParam.getKeyword().getText() + " idx=" + adParam.getIndex() + " value=" + adParam.getInsertionText()); } } AdWords API Workshops ¨C All rights reserved AW SCRIPT