简体   繁体   中英

how to exclude multiple zip code from adword campaign via script?

I am facing issue in google AdWords. I want to exclude zip code from all campaign via a script, script applied on account for all campaign

    function main() {
  excludeLocationTarget();
}
function excludeLocationTarget() {
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "US-WooCommerce"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // Exclude Tennessee, United States (location id = 21175) See
    // https://developers.google.com/adwords/api/docs/appendix/geotargeting
    // for list of all supported geo codes.
    // You could pass either the location code, or a TargetedLocation or
    // ExcludedLocation object from an existing campaign.
    var tennessee_id =['21175','21176'];
    for(val in tennessee_id){
      Logger.log(tennessee_id[val]);
      campaign.excludeLocation(tennessee_id[val]);
    }

  }
}

7/31/2019 11:45:44 PM 21175 7/31/2019 11:45:44 PM Invalid argument: id. Should be of type: number (file Code.gs, line 19)

excludeLocation method expects an integer argument and you're using string. that's why excludeLocation fails. try

var tennessee_id =[21175,21176]; // numerical values instead of strings
    for(val in tennessee_id){
      Logger.log(tennessee_id[val]);
      campaign.excludeLocation(tennessee_id[val]);
    }

or campaign.excludeLocation(parseInt(tennessee_id[val]));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM