Skip to content

Instantly share code, notes, and snippets.

@aarondicks
Last active January 31, 2017 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarondicks/ca21eba631a75682392919fb47b24fe9 to your computer and use it in GitHub Desktop.
Save aarondicks/ca21eba631a75682392919fb47b24fe9 to your computer and use it in GitHub Desktop.
Auto pause all ads automatically added by AdWords over the coming months. Just set this on a regular schedule and forget about it. For more information, please check out our blog post on this here: https://www.impression.co.uk/blog/6003/auto-pause-added-by-adwords-ads/
/**
* Script: Automatically pause any "Added by AdWords" ads in your AdWords account.
* This will not work with MCC level accounts - please find our other
* script versions at www.impression.co.uk
*
* Version: v1 - Jan 2017
* Author: www.impression.co.uk
*/
// Enter your email address here to be emailed a digest when ads are paused
var EMAIL_ALERT_ADDRESS = "";
function main() {
/**
* Get all ad Groups in the account
*/
var adGroupIterator = AdWordsApp.adGroups().get();
if (adGroupIterator.hasNext()) {
var adGroup = adGroupIterator.next();
/**
* Filter all ads in each adGroup where the label()
* object includes an "Added by AdWords" label.
*/
var label = AdWordsApp.labels().withCondition('Name="Added by AdWords"').get().next();
/**
* We're only interested in the ads not yet marked as "PAUSED"
*/
var adsIterator = label.ads().withCondition("Status = ENABLED").get();
var rows = [];
while (adsIterator.hasNext()) {
var ad = adsIterator.next();
/**
* Future proofing this... hopefully Google doesn't start pushing out other ad formats!
*/
if (ad.isType().expandedTextAd()) {
/**
* Push in each relevant ad into an array `rows` for the email notification
*/
rows.push([
ad.asType().expandedTextAd().getCampaign().getName(),
ad.asType().expandedTextAd().getAdGroup().getName(),
ad.asType().expandedTextAd().getHeadlinePart1(),
ad.asType().expandedTextAd().getHeadlinePart2(),
ad.asType().expandedTextAd().getDescription()
]);
/**
* Pause the ad if we've got this far
*/
ad.pause();
}
}
/**
* If the email address is set (not empty) then build the email and send.
*/
if (EMAIL_ALERT_ADDRESS) {
/**
* Set up the row headers for the email message
*/
var headers = ['Campaign name', 'AdGroup', 'Headline1', 'Headline2', 'Description'];
/**
* Build a quick email with the report format:
*
* Campaign name
* AdGroup name
* [Headline1]: [Value]
* [Headline2]: [Value]
* [Description]: [Value]
*/
var string = '\n\n';
for (var i = 0; i < rows.length; i++) {
for (var j = 0; j < rows[i].length; j++ ) {
string += headers[j] + ': ' + rows[i][j] + '\n';
}
string += '\n';
}
/**
* Use GmailApp to send a simple email to the notification email address
*/
MailApp.sendEmail({
to: EMAIL_ALERT_ADDRESS,
subject: '⚠️️ Automatic AdWords Ads have been paused in your AdWords account',
body: 'The following adverts have been automatically paused in your account: ' + string
});
}
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment