Wednesday, August 16, 2017

Automatically add AdWords Data to a Google Slide

Have you ever had to give a presentation about the performance of an AdWords account and spent a lot of time copy-and-pasting data from AdWords into your slides? If so, now you can automatically push data from AdWords into Google Slides.



This script leverages the recently announced integration of AdWords Scripts with the Google Slides API. Because this is one of the advanced APIs, the code is a bit more complicated and you will have to enable the Google Slides API from the script through an additional authorization step.

The code below appends a new slide to your Google Slide deck and adds some basic AdWords metrics. You can modify this code to add exactly the data from AdWords you want.


/* 
// AdWords Script: Add a Slide with AdWords Data
// --------------------------------------------------------------
// Copyright 2017 Optmyzr Inc., All Rights Reserved
// 
// This script takes a Google Presentation as input and appends a slide with basic AdWords metrics.
// Use this to automate creating an appendix of AdWords data to existing PPC report slides.
// The AW data we append is basic but can easily be tweaked to your own needs.
//
// For more PPC management tools and reports, visit www.optmyzr.com
//
*/

// Update this line with the presentation you want to edit. 
// E.g. this is for presentation https://docs.google.com/presentation/d/1RxIzTJC6Jwwd3H5aaRjA-zj3d5IhcG9uOTuOfwk8PUg/edit#slide=id.optmyzr_slide_a1f911e6-9538-427d-9e2f-12fdc951f752
var PRESENTATION_ID = "1RxIzTJC6Jwwd3H5aaRjA-zj3d5IhcG9uOTuOfwk8PUg"

function main() {
  
  var pageId = createSlide(PRESENTATION_ID);
  
  // Get the page element IDs for a basic TITLE_AND_BODY layout
  var baseElementId = readPageElementIds(PRESENTATION_ID, pageId);
  var titleId = baseElementId + "_0";
  var textId = baseElementId + "_1";
  
  // Edit the following with the text for the slide's title
  var titleText = "Automatically Fetched AdWords Data";
  updateElement(PRESENTATION_ID, titleId, titleText);
  
  // The next line gets text for the body section
  var dataForSlide = getLastMonthData();
  updateElement(PRESENTATION_ID, textId, dataForSlide);
  
  Logger.log("Done updating slides at https://docs.google.com/presentation/d/" + PRESENTATION_ID);
  
}

function getLastMonthData() {
  var currentAccount = AdWordsApp.currentAccount();
  //Logger.log('Customer ID: ' + currentAccount.getCustomerId() +
  //    ', Currency Code: ' + currentAccount.getCurrencyCode() +
  //    ', Timezone: ' + currentAccount.getTimeZone());
  var stats = currentAccount.getStatsFor('LAST_MONTH');
  var clicks = stats.getClicks();
  var impressions = stats.getImpressions();
  var text = clicks + " clicks from " + impressions + " impressions.";
  return(text);
}

function createSlide(presentationId) {
  // You can specify the ID to use for the slide, as long as it's unique.
  var pageId = Utilities.getUuid();

  var requests = [{
    "createSlide": {
      "objectId": pageId,
      //"insertionIndex": 1,
      "slideLayoutReference": {
        "predefinedLayout": "TITLE_AND_BODY"
      }
    }
  }];
  var slide =
      Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
  //Logger.log(slide);
  //Logger.log("Created Slide with ID: " + slide.replies[0].createSlide.objectId);
  
  return (pageId);
}

function updateElement(presentationId, elementId, textToAdd) {
  
  var requests = [{
      "insertText": {
        "objectId": elementId,
        "text": textToAdd,
      }
    }];
  var result =
      Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
  //Logger.log(result);
}

function readPageElementIds(presentationId, pageId) {
  // You can use a field mask to limit the data the API retrieves
  // in a get request, or what fields are updated in an batchUpdate.
  var response = Slides.Presentations.Pages.get(
      presentationId, pageId, {"fields": "pageElements.objectId"});
  //Logger.log(response);
 var objectIds = response.pageElements[0].objectId;
  var parts = objectIds.split("_");
  var objectIdBase = parts[0] + "_" + parts[1];
  //Logger.log("objectIdBase: " + objectIdBase);
  return(objectIdBase);
}

We maintain the most current version of this code on GitHub.

For a fully automated way to create PPC reports with interesting visualizations like Quality Score, a word cloud, a cause chart, or a heatmap, take a look at Optmyzr, my company.

Thanks,
Fred

17 comments:

  1. very interesting, good job and thanks for sharing such a good Post | blog.
    Best website designing company in Laxmi Nagar

    ReplyDelete
  2. Thank you for taking the time to publish this information very useful! High Quality Google Reviews

    ReplyDelete
  3. Yes. This code is absolutely correct and working. I'd like to thank you man for sharing this free. buy google reviews

    ReplyDelete
  4. Do you want your university to become number one? Vote for it here https://writemyessay4me.org/blog/university-rankings

    ReplyDelete
  5. Google reviews has proven to become a good element in anyone's business. Besides, it has become a essential aspect in effective business as well. Investigate Buy Google Reviews this page for fruitful information now.

    ReplyDelete
  6. SEO arama motorlarının bellirlediği kriterlere göre web sitenizin optimize edilmesi ile hedeflenen anahtar kelimelerde üst sıralarda yer almasını hedeflemektedir.

    ReplyDelete
  7. Boost your social media presence instantly get famous.Know how to get real instagram followers cheap.
    internetmarketingrocks

    ReplyDelete
  8. This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it buy real australian instagram likes

    ReplyDelete
  9. Links are one among the crucial ranking factors, probably the leading free seo tipps component, and we’ll dedicate several lessons to link building during this SEO course.

    ReplyDelete
  10. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. survey data entry

    ReplyDelete
  11. the information you provide on this website has helped me tremendously. Thanks for all
    of your time & work. Paraphrase Service Uk

    ReplyDelete
  12. hp fax error 344 happens when there is any correspondence blunder in the telephone line. ... Last Word from Experts for Error Code 344 HP Fax.

    ReplyDelete
  13. The ad word script is very helpful for many user who want to get the script all over the a huge people also want to earn online through the google ad word and it's the best idea many web development service company in Pakistan also build the blog sites for ad words and also earn a big amount online

    ReplyDelete
  14. wow, cool article, thanks
    also, if you need a social media accounts you can visit accsmarket store

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. If you need to buy everything with discount, for example, food and different drinks, you can visit the rabato.com which has fresh Weekly Ads on different stores.

    ReplyDelete