New Script To Automate Negative Placements Based on Criteria - Doesn't Work

144 views
Skip to first unread message

Duncan McGillivray

unread,
Apr 11, 2023, 8:20:49 AM4/11/23
to Google Ads Scripts Forum
Hi all - I'm struggling with this new script and cannot seem to make it work. This version doesn't appear to do anything after testing, which is frustrating. Is this timing out?  I'm trying to run a script that will add any placement without specific criteria to a negative placement list.  Script is below - any help would be appreciated.

function main() {
  var campaignIterator = AdsApp.campaigns()
    .withCondition("CampaignType = 'DISPLAY'")
    .get();
 
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var campaignName = campaign.getName();
    var dateRange = "LAST_7_DAYS";
   
    var report = AdsApp.report(
      "SELECT Criteria, Clicks, Conversions, Cost, Ctr, ConversionRate, FinalUrls " +
      "FROM PLACEMENT_PERFORMANCE_REPORT " +
      "WHERE CampaignName = '" + campaignName + "' " +
      "AND Clicks > 0 " +
      "AND Conversions > 0 " +
      "AND Cost > 0 " +
      "AND Ctr > 0.1 " +
      "AND ConversionRate > 0.05 " +
      "AND Cost > 1 " +
      "AND Impressions > 50 " +
      "DURING " + dateRange);
   
    var rows = report.rows();
    while (rows.hasNext()) {
      var row = rows.next();
      var placementUrl = row["Criteria"];
      var finalUrl = row["FinalUrls"];
      var clickThroughRate = row["Ctr"];
      var conversionRate = row["ConversionRate"];
      var cpc = row["Cost"];
     
      if (clickThroughRate > 0.1 || conversionRate > 0.05 || costPerConversion > 1) {
        var placement = campaign.display().newPlacementBuilder()
          .withUrl(placementUrl)
          .build();
        var negativePlacementList = AdsApp.negativeKeywordLists().getByName("Block Placements");
        negativePlacementList.addNegativePlacement(placement);
        Logger.log("Added placement " + placementUrl + " to negative placement list.");
      }
    }
  }
}

Google Ads Scripts Forum Advisor

unread,
Apr 11, 2023, 2:03:31 PM4/11/23
to adwords...@googlegroups.com

Hello Duncan,

This is the Google Ads scripts forum channel. Thank you for reaching to us.

Upon checking, I observed that you haven't migrated the codes in your scripts in the new script experience setup which could be the main reason why it is not working properly on your end. The changes within the codes of your script is required because the new script experience version is now based on Google Ads API infrastructure. As we have mentioned in our blog post, you should manually move or convert the codes within your scripts over to the new experience setup before then to ensure continued functionality.

That said, I would suggest that you refer to the following links below on how you can migrate your script to the new script experience version.

Regards,

Google Logo Google Ads Scripts Team


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