Script for the Google Ads Display Network

Jan 10, 2020

At a Glance...

Mistakenly activating the display network in a campaign can be particularly damaging, leading to significant overspend if missed. Here’s a script that helps avoid making such a mistake – among other things, it reports hourly on one’s campaigns and pauses campaigns that have unintentionally activated the display network.

 

A Google Ads script to avoid the accidental activation of the Display Network

 

Among all the things that can go wrong when launching a PPC campaign, enabling the Display Network is probably one of the worst.

Picture the scenario: there is a campaign that must be launched by Friday EOP, for a sale starting on Saturday in France. Your keywords, ads, extensions are all ready, but there’s a rush to push everything live on Google Ads as the campaign is scheduled to start at midnight.

In your rush, some settings are set incorrectly: language targeting is set to English only, targeting is set to ‘Users in your target location or interested in your targeted location‘, Search partners are enabled despite having never worked in the past, and the Display Network is enabled.

The last mistake is particularly damaging, causing a – very likely – overspend vs original plans.

 

So here’s a script that can be used to avoid the above happening. In short, this is what the script does:

  1. It creates a report of the past hour’s live activity
  2. It filters the report to only show activity that has been running on the content network
  3. It sends an email detailing the campaigns that have enabled the Display Network
  4. It pauses such campaigns

 

Just five things require changing to make the Google Ads script work:

  1. A decision on whether it should run at account or manager account level (line 7 of the script)
  2. The naming convention of campaigns that require the Display Network to be enabled (line 8-10 – there are three exceptions as the AWQL language doesn’t allow to use multiple conditions on campaign names)
  3. The recipients of the automated email alerting that the Display Network is enabled (line 11)
  4. The URL of a Google sheet (line 12)
  5. The date range to filter inactive accounts when running at manager account level (line 13)
    Advice: run this script on an hourly basis.

 

Here’s the script:

//////////////////////////////////////////////////////
////////////In Digital - Google Ads Scripts///////////
//Always preview your scripts before clicking on Run//
//////////////////////////////////////////////////////

//Variables to customise
var level = 'MCC'; // Set the variable to ACCOUNT or MCC, based on whether you want the script to run at the account or manager account level
var exception = 'UAC'; // Any campaign naming convention indicating campaigns that are allowed to target the display network. leave blank if none.
var exceptionTwo = 'GDN'; // Any campaign naming convention indicating campaigns that are allowed to target the display network. leave blank if none.
var exceptionThree = 'YT'; // Any campaign naming convention indicating campaigns that are allowed to target the display network. leave blank if none.
var recipients = ['<span style="color: #ffcc00;"><code>emailaddress</code></span><span style="color: #003366;"><code>']; // The recipient who will be notified by the email. Multiple email addresses go as an array ['email1','email2'];

var url = 'https://docs.google.com/spreadsheets/d/1PFqBVzH_tu8Ckqg7RB-yEZDBdtMBHnlK2qgycuLI0tc/edit#gid=0'; // Create a Google Sheet and paste the URL here

var dateRange = 'TODAY'; // When running at Manager Account level, the script only runs in accounts that have had more than one impressions today. This is to filter out inactive accounts.</code></span>

// Variables not to amend
var list = [];
var campaignsToPause = [];
var sheet = SpreadsheetApp.openByUrl(url).getActiveSheet();
var lastHour = 0;
var accountName = '';
var count = 0;

function main() {

var today = new Date();
var timezone = AdsApp.currentAccount().getTimeZone();
lastHour = Utilities.formatDate(today, timezone, 'HH') -1;

if (level == 'ACCOUNT'){

runReport();
generateList();
sendEmail();
}

else {

accountName = AdsApp.currentAccount().getName();

var accounts = MccApp.accounts().withCondition('Impressions &gt; 0').forDateRange(dateRange).get();

while (accounts.hasNext()){

var account = accounts.next();

MccApp.select(account);

runReport();
generateList();

}
//sendEmail();
}
}

function runReport(){

if (exception == "" &amp;&amp; exceptionTwo =="" &amp;&amp; exceptionThree =="" )
{
var report = AdsApp.report('SELECT CampaignName, AdNetworkType1, Impressions, HourOfDay, AccountDescriptiveName, CampaignId FROM CAMPAIGN_PERFORMANCE_REPORT WHERE Impressions&gt;0 AND AdNetworkType1 = CONTENT AND HourOfDay='+lastHour+' DURING TODAY');

report.exportToSheet(sheet);
}

if (exception != "" || exceptionTwo != "" || exceptionThree != "")
{
var report = AdsApp.report('SELECT CampaignName, AdNetworkType1, Impressions, HourOfDay, AccountDescriptiveName, CampaignId FROM CAMPAIGN_PERFORMANCE_REPORT WHERE Impressions&gt;0 AND AdNetworkType1 = CONTENT AND CampaignName DOES_NOT_CONTAIN ' + exception + ' AND CampaignName DOES_NOT_CONTAIN '+exceptionTwo+' AND CampaignName DOES_NOT_CONTAIN ' + exceptionThree + ' AND HourOfDay='+lastHour+' DURING TODAY');
report.exportToSheet(sheet);
}

}

function generateList(){

campaignsToPause = [];

var rows = sheet.getLastRow();
var columns = sheet.getLastColumn();

if (rows &gt; 1) {

list.push('\n');

for (i=2; i&lt;=rows; i++)

{
var value = sheet.getRange('C'+i).getValue();
if (value &gt; 0) {
var campaign = sheet.getRange('A'+i).getValue();
var campaignIds = sheet.getRange('F'+i).getValue();
var account = sheet.getRange('E'+i).getValue();
list.push(account + ' - ' + campaign + ';\n');

Logger.log(account + ' - '+ campaign + ' has Display Network Enabled and will now be paused.');

campaignsToPause.push(campaignIds);

}

else{}
}

Logger.log(campaignsToPause.length);
Logger.log(campaignsToPause);

if (campaignsToPause.length &gt; 0) {

var campaigns = AdsApp.campaigns().withIds(campaignsToPause).get();

while (campaigns.hasNext())
{
var campaign = campaigns.next();
var campaignName = campaign.getName();

campaign.pause();
count +=1;
}

}

else{}
}

else {}

}

function sendEmail() {

if (list.length &gt; 1) {

MailApp.sendEmail(recipients, "WARNING: "+accountName+" had one or more campaigns with Display Network enabled and they were paused - Please review now", "List of campaigns with GDN enabled:" + "\t"+ list)

Logger.log('An email was sent');
}

else
{
Logger.log("No campaigns are targeting the Display Network.");
}
}

Contact 

In Digital Marketing Ltd.

71 Central St, London, EC1V 8AB

+44 207 693 5223

contact@indigital.marketing

Get in touch