expandedTextAd().getHeadlinePart1().replace(subString, newString) not working

91 views
Skip to first unread message

Faze Advertising

unread,
Jun 7, 2022, 1:22:56 AM6/7/22
to Google Ads Scripts Forum
Hi, 

I have a script which should modify the first headline for text ads. 

I am inserting the product's price in the first headline and now the prices for some of the products have changed and I'd like do this using the script. 

Using the manager account:

I have tried replacing only the price, in the version below I tried replacing the entire headline...still, it is not working. Based on the logs the strings, both for old header and new header, look fine so I just don't understand what it is that I am missing.

I'd like to further develop this and leave it to run on a trigger but the functionality I need is not working :(

object_ads gets the data from a separate function which I didn't share because of some ids I am using there but can share if needed (object is {ad_id1:[new_price, old_price],ad_id2:[new_price, old_price],...})

I am looking forward to a solution for this,
Thank you

function main() {
 
    var arrayKeywords = [];
    var object_ads = get_to_change()
    var accountIterator = AdsManagerApp.accounts()
                   .get()
    while (accountIterator.hasNext()) {
    var account = accountIterator.next();
          getAccountsAdGrWithLinks(account,object_ads)
       }

}




function getAccountsAdGrWithLinks(account,object){
 
   var links = [];
   AdsManagerApp.select(account);
   var adGrIterator = AdsApp.adGroups()
                   .get()
 
   while(adGrIterator.hasNext()){
    var adGr = adGrIterator.next()
    var adsgr = adGr.ads().get()
    while(adsgr.hasNext()){
     var ad = adsgr.next()
     var id = ad.getId()
     if (object[id]){
     var intermed = object[id]
     var old = intermed[1].toFixed(0) + ' Lei'
     var new_a =  intermed[0].toFixed(0)+ ' Lei'
     var text = ad.asType().expandedTextAd().getHeadlinePart1()
     var text_new = text.replace(old,new_a)
     Logger.log([old,new_a,text,text_new])
    ad.asType().expandedTextAd().getHeadlinePart1().replace(text,text_new)
   }
   
   }

   
   }

  }

Google Ads Scripts Forum Advisor

unread,
Jun 7, 2022, 5:55:16 AM6/7/22
to adwords...@googlegroups.com

Hello Faze,

James here, from the Google Ads scripts support team. Thank you for raising your concern to us.

Can you please provide us with the following details below so that we can proceed in our investigation?

  • Google Ads account ID / CID
  • Script name
  • Are you executing your script using the new script experience or legacy version when you encounter the issue?

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2bcwj6:ref

Faze Advertising

unread,
Sep 28, 2022, 3:44:53 AM9/28/22
to Google Ads Scripts Forum
Hi James,

Sorry for the late reply. Please see the answers below:
  • Google Ads account ID / CID - 325-046-4793
  • Script name - 00001
  • Are you executing your script using the new script experience or legacy version when you encounter the issue? - both new and old versions
I am looking forward to your reply.

Thank you

Google Ads Scripts Forum Advisor

unread,
Sep 29, 2022, 12:35:47 AM9/29/22
to adwords...@googlegroups.com

Hello Faze,

Upon checking your script, I noticed that you’re utilizing a spreadsheet. That said, can you please share with us the shareable link of the used spreadsheet so that we can proceed in our investigation and troubleshooting? You may follow this guide, specifically under `Share a file publicly` section on how you can get the said shareable link.

Kindly send the requested item above via `Reply privately to author` option or send it through this email <googleadsscr...@google.com>.

Regards,

Google Ads Scripts Forum Advisor

unread,
Sep 30, 2022, 4:13:29 AM9/30/22
to adwords...@googlegroups.com

Hello Faze,

We appreciate your patience on this.

I took a closer look at your script and I observed that your script implementation is fine. However, the replace() is not an official method of Google Ads scripts, instead it’s only a method on javascript level. That being said, it is expected that the changes made by the replace method will not be registered on the backend of Google Ads as it only allows you to manipulate the text on script surface level.

I believe that there’s currently no way to change the headlines on ad level through Google Ads new scripts experience. Instead, only the following methods stated in the following links below are supported.

Reply all
Reply to author
Forward
0 new messages