Script for exclude placments account level

55 views
Skip to first unread message

F.A.N.

unread,
Oct 22, 2024, 7:16:04 AM10/22/24
to Google Ads Scripts Forum
Hello 
I created the followeing script to exclude placments for pmax , demand gen campaigns , but it showing failed in the results .. can you audit thi sscript and tell me what sis wrong ? 

 
function main() {
  // Define the list of languages you want to exclude
  var languagesToExclude = [
    'hi', 'bn', 'mr', 'ta', 'te', 'ur', 'sw', 'am'
  ];

  // Define the list of content labels (categories) you want to exclude
  var contentCategoriesToExclude = [
    'TRAGEDY', 'RELIGION', 'NON_ADULT', 'BABY_AND_TODDLER', 'PARENTING', 'FOOD_AND_DRINK', 'KITCHEN'
  ];

  // Define the list of channel names/keywords to exclude in placements
  var placementKeywordsToExclude = [
    'official', 'khan', 'islam', 'muslim', 'story', 'pinoy', 'iqbal',
    'cricket', 'aftab', 'amit', 'raj', 'vikram', 'muk', 'kenya', 'azad',
    'imran', 'kapoor', 'مطبخ', 'يوميات', 'قصص', 'اطفال', 'طفل', 'حماس',
    'اسرائيل', 'سوريا', 'لبنان', 'ايران', 'سلمان', 'سعود', 'وصف',
    'شيخ', 'تلاوة', 'سورة', 'ايات', 'تفسير', 'رسول', 'قران'
  ];

  try {
    // Get all active campaigns
    var campaignIterator = AdsApp.campaigns()
      .withCondition('Status = ENABLED')
      .get();

    if (!campaignIterator.hasNext()) {
      Logger.log("No active campaigns found.");
      return;
    }

    while (campaignIterator.hasNext()) {
      var campaign = campaignIterator.next();
      Logger.log("Processing campaign: " + campaign.getName());

      // Exclude languages
      for (var i = 0; i < languagesToExclude.length; i++) {
        try {
          campaign.targeting().languages().excludeLanguage(languagesToExclude[i]);
          Logger.log("Excluded language: " + languagesToExclude[i]);
        } catch (error) {
          Logger.log("Failed to exclude language: " + languagesToExclude[i] + " - " + error.message);
        }
      }

      // Exclude content labels
      var contentLabelIterator = campaign.targeting().contentLabelTargets().get();
      while (contentLabelIterator.hasNext()) {
        var contentLabel = contentLabelIterator.next();
        if (contentCategoriesToExclude.includes(contentLabel.getName())) {
          try {
            contentLabel.exclude();
            Logger.log("Excluded content label: " + contentLabel.getName());
          } catch (error) {
            Logger.log("Failed to exclude content label: " + contentLabel.getName() + " - " + error.message);
          }
        }
      }

      // Exclude placements based on channel name keywords
      var placementIterator = campaign.display().placements().get();
      while (placementIterator.hasNext()) {
        var placement = placementIterator.next();
        for (var j = 0; j < placementKeywordsToExclude.length; j++) {
          if (placement.getUrl().toLowerCase().indexOf(placementKeywordsToExclude[j]) !== -1) {
            try {
              placement.exclude();
              Logger.log("Excluded placement: " + placement.getUrl());
            } catch (error) {
              Logger.log("Failed to exclude placement: " + placement.getUrl() + " - " + error.message);
            }
          }
        }
      }
    }
  } catch (error) {
    Logger.log("An error occurred: " + error.message);
  }
}

Google Ads Scripts Forum Advisor

unread,
Oct 22, 2024, 3:02:32 PM10/22/24
to adwords...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads Scripts support team.

In order to analyze the issue further, please share the following details:
  • Google Ads account ID / CID
  • Name of the script
  • Error details or screenshot of the issue (if any)
You can send the details via Reply privately to the author option, or direct private reply to this email.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vGflo:ref" (ADR-00272532)

Thanks,
 
Google Logo Google Ads Scripts Team


Sigurd Fabrin

unread,
Oct 23, 2024, 6:08:15 AM10/23/24
to Google Ads Scripts Forum
"I created the followeing script to exclude placments for pmax , demand gen campaigns [...]"
That won't work. You can't control the minute details of these automated campaign types. Their raison d'être is to use Google's data rather than your inputs.

And AdsApp.campaigns() won't even return those campaign types.

Not sure, why @Google Ads Scripts Team don't just tell you that you that.

When you ask ChatGPT to write code that will do something which is not possible, it will comply. But of course, the result will be rubbish. So you need to read the documentation yourself to know what is possible.


Sigurd


Google Ads Scripts Forum Advisor

unread,
Oct 23, 2024, 10:31:48 AM10/23/24
to adwords...@googlegroups.com

Hi,

@Sigurd - thanks for input on this issue.

I would like to inform you that the language targeting for PMax and Demand Gen campaigns are not supported in the Google Ads Scripts. You can use targeting methods for Search & Display, Shopping, and Video campaigns.

I hope this helps! Kindly get back to us if you still have any concerns. 

Reply all
Reply to author
Forward
0 new messages