{{ searchResult.published_at | date:'d MMMM yyyy' }}

Loading ...
Loading ...

Enter a search term such as “mobile analytics” or browse our content using the filters above.

No_results

That’s not only a poor Scrabble score but we also couldn’t find any results matching “”.
Check your spelling or try broadening your search.

Logo_distressed

Sorry about this, there is a problem with our search at the moment.
Please try again later.

By adding a simple JavaScript program, you can link your own data to AdWords, to create rules for your campaigns, or customise reports. 

For example, if you’re a retailer, you can link your inventory data to AdWords, to change bidding on a campaign, or stop/start keywords as items go out of stock. Or you can automatically change keywords or bidding on AdWords, based on data trends. 

You can pretty much do anything you want, in fact. We've created a sample script to set up an alert on an AdWords campaign, which we're happy to share.

Google has just put AdWords Scripts on general release (after a limited release in June this year), which lets you link your own data to AdWords campaigns.

Some of the big search technology firms already offer things like inventory linking, of course, but the beauty of Google opening its system up for general use is there’s now no need to build an expensive tool from scratch (or pay someone else for theirs) or worry about getting API authorisation. Google’s done the work for you.

Google has made the process pretty accessible: so as long as you have a tech-minded person to write the scripts for you, you can schedule changes, create reports and set up alerts. Most things are possible through the AdWords Scripts interface. It’s not quite like having access to Google’s API, but if you’re familiar with JavaScript, there’s a lot you can do fairly simply to manage your AdWords campaigns.

Google used to let you create custom alerts, but removed this feature earlier this year. Now, though, you can create customer alerts by using scripts, so to test the system, we created a sample script for alerts – and as we’ve created it, we thought we’d share it, and hope it’s useful.

It is a simple piece of JavaScript that will alert you if your campaign suffers a drop of 80% or more in impressions (something you’d want to know, as it would be a reasonably sure indicator that something’s gone wrong).

If you’re interested, it’s below. You need to copy and paste the text into a new script in the Automation page in AdWords, from the left-hand navigation bar.

There are two sections you need to change before you use it, both at the top of the code:

  1. The ‘threshold’ variable sets the percentage fall at which to trigger an alert. (We’ve set it to 80%, but you might want to change that).
  2. The ‘strAddress’ variable sets the email address that should receive a notification. Obviously you need to set that, too.

Once you’ve done that, you need to hit ‘authorise’, save the script and set the schedule (I recommend setting it to ‘daily’ at 8am).

The script to copy and paste is below. Let me know how you get on!

// Code to create an email to note any and all ad groups with an
// X% or greater drop in impressions vs the same day the previous week

// *****************************************************
//
// Created by Periscopix Ltd
//
// August 2012
//
// *****************************************************

function main() {

   //Set the threshold of impression fall to send an alert
   var threshold = 80;    //Change this to adjust the percentage fall threshold

   //Set the email address to alert in case of changes
   var strAddress = "changethis@example.com";    //Change this to adjust the email recipient 

//Get an iterator over ad groups, ordered by cost
  var adGroupsIterator = AdWordsApp.adGroups()
      .orderBy("Cost")
      .withCondition("Impressions > 99")    //This is to prevent including low volume ad groups
      .forDateRange(getOneWeekBefore(), getOneWeekBefore())
      .get();

   //Initialise the message body variable
   var messagebody = "";

  //Loop through all the ad groups
  while (adGroupsIterator.hasNext()) {

    //Get the next ad group as an object
    var adGroup = adGroupsIterator.next();

    //Get the stats for yesterday
    var yesterdayImpressions = adGroup.getStatsFor("YESTERDAY").getImpressions();

    //Get the stats for the week before
    var strOneWeekBefore = getOneWeekBefore();
    var oneWeekBeforeImpressions = adGroup.getStatsFor(strOneWeekBefore, strOneWeekBefore).getImpressions();

    //Check for a large enough drop in impressions
    if (yesterdayImpressions <= (oneWeekBeforeImpressions * ((100-threshold)/100)))
      {

      //Create a new html table line and add the values to each cell
      messagebody =
        messagebody +
        "<tr><td>" + adGroup.getCampaign().getName() +    //Campaign Name
        "</td><td>" +  adGroup.getName() +                //Ad group name
        "</td><td>" + oneWeekBeforeImpressions +          //Impressions from the previous period
        "</td><td>" + yesterdayImpressions +              //Impressions from yesterday
        "</td></tr>";                                     //End the table row
      }          
  }

  //Send an email with a list of changed ad groups
  generateMail(messagebody, strAddress, threshold);

}

function generateMail(messagebody, recipient, threshold) {

  //messagebody will be an empty string if no lines have been added
  if (messagebody != "")
     {

     //Create the html-formatted email body
     //Create the table and headers, then add the message body then close the table and add the logo
     messagebody = "<table border='1'><tr><td>Campaign</td><td>Ad Group</td><td>Previous Impressions</td><td>Yesterday Impressions</td></tr>" + messagebody;
     messagebody = messagebody + "</table>";

     //Construct the email and send it with an html body and a list of the inline images
     var subject = "Ad Groups with >" + threshold + "% Impression Drop";
     MailApp.sendEmail(recipient, subject, "", {htmlBody: messagebody,});

     }

function getOneWeekBefore() {

  //Return the date in the string YYYYMMDD
  var thisDate = new Date();
  var oneWeekBeforeDate = new Date();
  oneWeekBeforeDate.setMonth(thisDate.getMonth()+1);
  oneWeekBeforeDate.setDate(thisDate.getDate()-8);

  var strOneWeekBeforeDate = oneWeekBeforeDate.getFullYear().toString() + twoDigit(oneWeekBeforeDate.getMonth().toString()) + twoDigit(oneWeekBeforeDate.getDate().toString());

  return strOneWeekBeforeDate;

}

function twoDigit(dayormonth) {

  //If a month or day value is just one digit, convert to two digits
  if (dayormonth.length == 1)
    {
    return "0" + dayormonth;
    }
  else
    {
     return dayormonth;
    }

}

Alistair Dent

Published 12 September, 2012 by Alistair Dent

Alistair Dent is Head of PPC at Periscopix at Periscopix and a contributor to Econsultancy. You can connect with Alistair via LinkedIn, or follow him on Twitter and Google+.

5 more posts from this author

Comments (3)

Avatar-blank-50x50

Roger

Thanks for the example script. I have implemented it and am working on creating some other ones. If you have one that gets everyone to start bidding 80% less that would be great as well.

about 4 years ago

Avatar-blank-50x50

fashions

Thanks for the example script
If you have one that gets everyone to start bidding 56% less that would be great as well.

almost 4 years ago

Avatar-blank-50x50

Erno Horvath

Well, I think it's not working properly, because the OneWeekBeforeDate was not valid...

oneWeekBeforeDate.setMonth(thisDate.getMonth()+1);
oneWeekBeforeDate.setDate(thisDate.getDate()-8);

It adds one month plus to the current month and subtract 8 days from the date and this currently it's 20130019 to me...

over 3 years ago

Comment
No-profile-pic
Save or Cancel
Daily_pulse_signup_wide

Enjoying this article?

Get more just like this, delivered to your inbox.

Keep up to date with the latest analysis, inspiration and learning from the Econsultancy blog with our free Daily Pulse newsletter. Each weekday, you ll receive a hand-picked digest of the latest and greatest articles, as well as snippets of new market data, best practice guides and trends research.