HELP changing AW script to GA script

83 views
Skip to first unread message

Anat Landes

unread,
Sep 28, 2022, 8:36:37 AM9/28/22
to Google Ads Scripts Forum
  Hi there!
Can you please help me change these lines to the new API experience (GA script instead of AW script) :


NO_SUPPLIERS_TEXT = "THIS IS AN EXAMPLE"
CONDITION0 = 'campaign.name IN ("place 1")'
CONDITION1 = 'campaign.name IN ("place 2","place 3","place 4")'
CONDITION2 = 'campaign.status = ENABLED'
CONDITION3 = "ad_group.name NOT REGEXP_MATCH '.*dynamic'"
CONDITION4 = "ad_group.status = ENABLED"
CONDITION5 = "ad_group_ad.status IN ('PAUSED', 'ENABLED')"
CONDITION6 = "ad_group_ad.labels CONTAINS NONE ('customers/6635544498/labels/11065858449')"

function main()
{
  Logger.log("Beginning process...");
  var alreadyCheckedUrls = {};
 
  var ad_iter = AdsApp.ads().withCondition(CONDITION1).withCondition(CONDITION2).withCondition(CONDITION3).withCondition(CONDITION3).withCondition(CONDITION4).withCondition(CONDITION5).withCondition(CONDITION6).get();
  //var adsIterator = adSelector.get();
  var counter = 0;
    while (ad_iter.hasNext())
    {
      Logger.log(counter);
      var ad = ad_iter.next();
      try
      {
      var url = ad.urls().getFinalUrl();
      }
      catch(except)
      {
        Logger.log("Error reaching url in ad group: "+ad.getAdGroup().getName()+". Skipping...");
        continue;
      }
     
      if(alreadyCheckedUrls[url])
      {


Thank you!!

        if(alreadyCheckedUrls[url] === 'no suppliers')
        {
          ad.pause();
        }
        if(alreadyCheckedUrls[url] === '1 supplier or more')
        {
          ad.enable();
        }
      }
      else
      {
        if(url == null)
        {
          ad.pause();
          continue;
        }

        var htmlCode;
        try
        {
          htmlCode = UrlFetchApp.fetch(url).getContentText();
        } catch(e) {
          Logger.log('There was an issue checking: '+url+', Skipping.');
          continue;
        }
        if(htmlCode.indexOf(NO_SUPPLIERS_TEXT) >= 0) {
          alreadyCheckedUrls[url] = 'no suppliers';
          ad.pause();
        } else {
          alreadyCheckedUrls[url] = '1 supplier or more';
          ad.enable();
        }
      }

      Logger.log('Url: '+url+' has '+alreadyCheckedUrls[url]);
      ++counter;
    }
    Logger.log("Finished process.");
   
  }
  

Google Ads Scripts Forum

unread,
Oct 6, 2022, 10:20:13 PM10/6/22
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/j3HMeEcDyuI) from the forum as it wasn't routed to our support queue.

Regards,
Yasmin
Google Ads Scripts Team

Google Ads Scripts Forum Advisor

unread,
Oct 7, 2022, 1:56:07 AM10/7/22
to adwords...@googlegroups.com

Hi,

 

Thank you for reaching out to us, this is Yasmin from the Google Ads scripts team.

 

Upon checking the script, it appears that it is conforming to the new script experience version. With that said, are you able to confirm if you are encountering an issue on your end? If you are, kindly provide the following information for us to further check this and assist you accordingly:

  • Google Ads account ID / CID
  • Script name
  • Screenshot of the error
  • Shareable link (guide on Share a file publicly) of your spreadsheet, if applicable.

 

Kindly send the requested items via `Reply privately to author` option. If the said option is not available on your end, you may send those through the email alias `googleadsscr...@google.com` instead.

 

Regards,

 

Google Logo
Yasmin Gabrielle
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2f2qOw:ref
Reply all
Reply to author
Forward
0 new messages