MCC Script to find and replace text in an Extended Text Ad

312 views
Skip to first unread message

James

unread,
Mar 21, 2018, 4:12:22 PM3/21/18
to AdWords Scripts Forum
Hello everyone, 

I hope someone can help with this but I currently have a situation where I need to find and replace text in my ETA so i'm hoping this is possible with a script. 

The goal here is to scan all my accounts ETA's, find "2017" and replace it with "2018". I am aware of the MCC stipulations and I can try to figure that out on my own but if someone can provide the function to make this possible that would be so amazing. Please note that I would appreciate a for dummies script as i'm not savvy in scripting at all. I just know how to read it, not write it. Therefore if it's not much to ask It would be great for a copy / paste solution with comments on what I need to replace in the script :) thanks all. 
Message has been deleted

Thea Vega (AdWords Scripts Team)

unread,
Mar 22, 2018, 2:37:18 AM3/22/18
to AdWords Scripts Forum
Hi James,
 
Based on my understanding, you would require for an MCC-level script that would change expanded ad text "2017" to "2018". If so, there is currently no way to edit expanded text ad entities as these are the only functions supported. However, you may delete the old ad and set the same conditions (e.g. HeadlinePart1, HeadlinePart2, etc.) on your new ETA based on your old ones. Please see below scripts based on these. 

Script 1: Creates new ETA

function main() {
 
 
var accountIterator = MccApp.accounts().get();
 
 
while (accountIterator.hasNext()) {
   
var account = accountIterator.next();
   
MccApp.select(account);

   
Logger.log(account.getName());
   
 
  //Create an expanded text ad for your specific string (i.e. on your use-case, "2018").
   
//Please see this documentation for more information on how to create an expanded text ad.

   
var adGroupIterator = AdWordsApp.adGroups()
   
.get();
   
if (adGroupIterator.hasNext()) {
     
var adGroup = adGroupIterator.next();
     
      //you may insert your string to any part of the ad conditions. Here, inserting 2018 on HeadlinePart2 is just an example
      adGroup
.newAd().expandedTextAdBuilder()
     
.withHeadlinePart1('INSERT_HEADLINE_P1_HERE')
     
.withHeadlinePart2('INSERT_HEADLINE_P2_HERE 2018')
     
.withDescription('INSERT_DESCRIPTION_HERE')
     
.withFinalUrl('INSERT_FINAL_URL_HERE')
     
.build();
   
}
 
}
}
Script 2: Deletes old ETAs
function main() {
 
 
// Selects all accounts using the ManagedAccountSelector object. You may see this example on how to get all accounts.
 
var accountIterator = MccApp.accounts().get();
 
 
while (accountIterator.hasNext()) {
   
var account = accountIterator.next();
   
MccApp.select(account);
   
Logger.log(account.getName());
   
   
var adSelector = AdWordsApp
   
.ads()
    //you may change this depending on your requirements
   
.withCondition("HeadlinePart1 CONTAINS '2017'");
     
   
var adIterator = adSelector.get();
   
while (adIterator.hasNext()) {
     
var ad = adIterator.next();
     
//Deletes your ETA with field containing "2017". You may see this documentation about .withCondition() for more details.
      ad
.remove();
   
}
 
}
}
Please take note of the following when creating the script above:
  • You may have to run the first script before running the second one to ensure that the new ads are created before deleting the old ones.
  • I suggest you Preview the scripts to see if it fits your requirements.
Accordingly, you may also be interested in our Ad Customizer solution script. The said solution script sets up parameterized ads to fetch live data and update an ad text.

Hope these help. Let me know if you have further clarificiations. 

Thanks,
Thea
AdWords Scripts Team

James

unread,
Mar 22, 2018, 12:00:44 PM3/22/18
to AdWords Scripts Forum
Hi Thea, 

Thanks for the help. this script is awesome and works as intended. I appreciate you taking the time to help me with this. I love this community!
Reply all
Reply to author
Forward
0 new messages