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:

[code]<br /> //////////////////////////////////////////////////////<br /> ////////////In Digital – Google Ads Scripts///////////<br /> //Always preview your scripts before clicking on Run//<br /> //////////////////////////////////////////////////////</p>
<p>//Variables to customise<br /> 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<br /> var exception = ‘UAC’; // Any campaign naming convention indicating campaigns that are allowed to target the display network. leave blank if none.<br /> var exceptionTwo = ‘GDN’; // Any campaign naming convention indicating campaigns that are allowed to target the display network. leave blank if none.<br /> var exceptionThree = ‘YT’; // Any campaign naming convention indicating campaigns that are allowed to target the display network. leave blank if none.<br /> 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′];</p>
<p>var url = ‘https://docs.google.com/spreadsheets/d/1PFqBVzH_tu8Ckqg7RB-yEZDBdtMBHnlK2qgycuLI0tc/edit#gid=0’; // Create a Google Sheet and paste the URL here</p>
<p>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></p>
<p>// Variables not to amend<br /> var list = [];<br /> var campaignsToPause = [];<br /> var sheet = SpreadsheetApp.openByUrl(url).getActiveSheet();<br /> var lastHour = 0;<br /> var accountName = ”;<br /> var count = 0;</p>
<p>function main() {</p>
<p>var today = new Date();<br /> var timezone = AdsApp.currentAccount().getTimeZone();<br /> lastHour = Utilities.formatDate(today, timezone, ‘HH’) -1;</p>
<p>if (level == ‘ACCOUNT’){</p>
<p>runReport();<br /> generateList();<br /> sendEmail();<br /> }</p>
<p>else {</p>
<p>accountName = AdsApp.currentAccount().getName();</p>
<p>var accounts = MccApp.accounts().withCondition(‘Impressions > 0’).forDateRange(dateRange).get();</p>
<p>while (accounts.hasNext()){</p>
<p>var account = accounts.next();</p>
<p>MccApp.select(account);</p>
<p>runReport();<br /> generateList();</p>
<p>}<br /> //sendEmail();<br /> }<br /> }</p>
<p>function runReport(){</p>
<p>if (exception == "" && exceptionTwo =="" && exceptionThree =="" )<br /> {<br /> var report = AdsApp.report(‘SELECT CampaignName, AdNetworkType1, Impressions, HourOfDay, AccountDescriptiveName, CampaignId FROM CAMPAIGN_PERFORMANCE_REPORT WHERE Impressions>0 AND AdNetworkType1 = CONTENT AND HourOfDay=’+lastHour+’ DURING TODAY’);</p>
<p>report.exportToSheet(sheet);<br /> }</p>
<p>if (exception != "" || exceptionTwo != "" || exceptionThree != "")<br /> {<br /> var report = AdsApp.report(‘SELECT CampaignName, AdNetworkType1, Impressions, HourOfDay, AccountDescriptiveName, CampaignId FROM CAMPAIGN_PERFORMANCE_REPORT WHERE Impressions>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’);<br /> report.exportToSheet(sheet);<br /> }</p>
<p>}</p>
<p>function generateList(){</p>
<p>campaignsToPause = [];</p>
<p>var rows = sheet.getLastRow();<br /> var columns = sheet.getLastColumn();</p>
<p>if (rows > 1) {</p>
<p>list.push(‘\n’);</p>
<p>for (i=2; i<=rows; i++)</p>
<p>{<br /> var value = sheet.getRange(‘C’+i).getValue();<br /> if (value > 0) {<br /> var campaign = sheet.getRange(‘A’+i).getValue();<br /> var campaignIds = sheet.getRange(‘F’+i).getValue();<br /> var account = sheet.getRange(‘E’+i).getValue();<br /> list.push(account + ‘ – ‘ + campaign + ‘;\n’);</p>
<p>Logger.log(account + ‘ – ‘+ campaign + ‘ has Display Network Enabled and will now be paused.’);</p>
<p>campaignsToPause.push(campaignIds);</p>
<p>}</p>
<p>else{}<br /> }</p>
<p>Logger.log(campaignsToPause.length);<br /> Logger.log(campaignsToPause);</p>
<p>if (campaignsToPause.length > 0) {</p>
<p>var campaigns = AdsApp.campaigns().withIds(campaignsToPause).get();</p>
<p>while (campaigns.hasNext())<br /> {<br /> var campaign = campaigns.next();<br /> var campaignName = campaign.getName();</p>
<p>campaign.pause();<br /> count +=1;<br /> }</p>
<p>}</p>
<p>else{}<br /> }</p>
<p>else {}</p>
<p>}</p>
<p>function sendEmail() {</p>
<p>if (list.length > 1) {</p>
<p>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)</p>
<p>Logger.log(‘An email was sent’);<br /> }</p>
<p>else<br /> {<br /> Logger.log("No campaigns are targeting the Display Network.");<br /> }<br /> }<br /> [/code]

Reach out to one of our team to learn more about our services and how we can help your business thrive.