PLA Script: 自动添加转化词到PLA_Best否定列表

function main() {
  //How do you want to call your negative keyword list?
  var targetList = 'PLA_Best'
var now = new Date();
var timezone = AdWordsApp.currentAccount().getTimeZone();
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
//var last90Days = new Date(now.getTime() - 90 * MILLIS_PER_DAY);  
//var sqrStartDate = Utilities.formatDate(last90Days, timezone, 'yyyyMMdd')
var firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
var sqrStartDate = Utilities.formatDate(firstDay, timezone, 'yyyyMMdd');
var sqrEndDate = Utilities.formatDate(new Date(), timezone, "yyyyMMdd")
var CPA_Threshold_Micro = 50; 
var CPA_Threshold = CPA_Threshold_Micro*1000000;
  var brand = 'your brand name'
  Logger.log('Report start date: '+sqrStartDate)
  Logger.log('Report end date: '+sqrEndDate.replace(/-/g,''))
  //let's build the negKw list if not existing yet  
  if(AdsApp.negativeKeywordLists().withCondition('Name = "'+targetList+'"').get().totalNumEntities()==1)
  {Logger.log('Negative list called '+targetList+' already exists!')}
  //else create the lsit
  else {
    Logger.log('Negative list called '+targetList+' does not exist yet - building now!')
  //let's run search query report
  //keep in mind that cost numbers from API are multiplied by 1,000,000 for some reason - that's why I am multiplying by 1,000,000
  var reportText =
     'SELECT Query,Clicks,Cost,Ctr,ConversionRate,CostPerConversion,Conversions,ConversionValue,AllConversions,CampaignId,AdGroupId ' +
     'WHERE Impressions > 0 AND Clicks > 0 AND Conversions > 0 AND CostPerAllConversion < '+CPA_Threshold+' AND CampaignName CONTAINS_IGNORE_CASE "PLA_" + AND Query DOES_NOT_CONTAIN_IGNORE_CASE "'+brand+'" ' +
     'DURING '+sqrStartDate+','+sqrEndDate
  Logger.log('Running this SQT Report now: ' + reportText)
  var queries =;
  Logger.log('I am done with running the SQT Report.')
  var rows = queries.rows()
  //let's create negative kws as exact match
  var negKwsToAdd = []
  //start checking only there are bad terms to process
    Logger.log('These terms are eligible to be added as exact negs: '+negKwsToAdd+'\n'+
              'However, checking if they are not in the list already.'
    //let's start comparing existing neg KWs in the list vs neg KWs which you want to add base on the latest run of search query report 
    var existingNegKws = []
    var lists = AdsApp.negativeKeywordLists().withCondition('Name = "'+targetList+'"').get()
      list =
      var allCurrentNegKws = list.negativeKeywords().get()
      while (allCurrentNegKws.hasNext()){
        negKwInTheList =
      Logger.log(targetList+' is empty at the moment.')}
      else {Logger.log('These negative keywords are already present in the list: '+existingNegKws)}
    var checkedNegKwsToAdd = []
    var i=0
      //here is the main trick for array comparison
        Logger.log(negKwsToAdd[i]+' is already in '+targetList)}
        else {checkedNegKwsToAdd.push(negKwsToAdd[i])}
  else{Logger.log('No bad terms to process - lucky you!')}
    Logger.log('These neg kws will be added into '+targetList+' list:'+checkedNegKwsToAdd)}
    else {Logger.log('No new neg kws will be added into '+targetList+'. All the eligibile KWs are already there!')}
    //Let's add the negative kewords into the target list
      var lists = AdsApp.negativeKeywordLists().withCondition('Name = "'+targetList+'"').get()
        var list =
        Logger.log(checkedNegKwsToAdd+' added as neg KWs into '+targetList)


电子邮件地址不会被公开。 必填项已用*标注