Exclude placement script | Removes .com domains in Display campaigns

37 views
Skip to first unread message

Max Leuftink

unread,
Dec 3, 2020, 7:24:21 AM12/3/20
to Google Ads Scripts Forum
Hi,

I have written a script which should exclude irrelevant traffic in my Google Display campaigns. However, whilst running the script in 'Example' mode it also filtered .com domains. This is not listed in my script, is someone able to see the fault in my code?

/**

 * Removes placements ending in the top level domains containing xyz, tk, in, io, club, news, kr, co, ch, fun, dk, online, ru, ch and download.

 * @author Max Leuftink

*/

 

// Top Level Domains to exclude

 

var TLDs = '.xyz, .tk, .download, .in, .io, .club, .xyz, .news, .kr, .co, .ch, .fun, .dk, .online, .ru, .ch';

 

// -------------------------------------------------------

 

function removePlacementByDomain (domain) {

  var placementSelector = AdWordsApp.display().placements()

  .withCondition("PlacementUrl CONTAINS '" + domain + "'")

  .withCondition("CampaignStatus != REMOVED");

 

  var placementIterator = placementSelector.get();

  while (placementIterator.hasNext()) {

    var placement = placementIterator.next();

    var placementUrl = placement.getUrl();

    //Logger.log(placementUrl);

 

    var campaign = placement.getCampaign();

    var excludeOperation = campaign.display().newPlacementBuilder().withUrl(placementUrl).exclude();

    if (!excludeOperation.isSuccessful()) {

      Logger.log("Could not exclude : " + placementUrl);

    }

  }

}

 

function run () {

  TLDs.split(',').map(function (tld) {

    return tld.trim();

  }).forEach(function (domain) {

    removePlacementByDomain(domain);

  });

}

 

function executeInSequence (sequentialIds, executeSequentiallyFunc) {

  Logger.log('Executing in sequence : ' + sequentialIds);

  sequentialIds.forEach(function (accountId) {

    var account = MccApp.accounts().withIds([accountId]).get().next();

    MccApp.select(account);

    executeSequentiallyFunc();

  });

}

 

function main () {

  try {

    var accountIterator = MccApp.accounts().orderBy('Name').get();

    Logger.log('Total number of accounts under MCC : ' + accountIterator.totalNumEntities());

 

    var accountIds = [];

    while (accountIterator.hasNext()) {

      var account = accountIterator.next();

      accountIds.push(account.getCustomerId());

    }

    var parallelIds = accountIds.slice(0, 50);

    var sequentialIds = accountIds.slice(50);

    // execute accross accounts

    MccApp.accounts()

      .withIds(parallelIds)

      .executeInParallel('run');

    if (sequentialIds.length > 0) {

      executeInSequence(sequentialIds, run);

    }

  } catch (exception) {

    // not an Mcc

    Logger.log('Running on non-MCC account.');

    run();

  }

}

Thanks in advance!

Max

Google Ads Scripts Forum Advisor

unread,
Dec 3, 2020, 11:27:30 PM12/3/20
to adwords...@googlegroups.com

Hi Max,

 

Thanks for reaching out. Can you kindly share with us your CID and the script ID/Name via Reply privately to author or Reply to author option instead, so we could check on our end? If those options aren't working on your end, you can send those requested details on this email (googleadsscr...@google.com) and include the link of this thread so we could keep track of this existing conversation.

 

Thanks,

Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


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