สถานที่ตั้งที่ยกเว้น

เพิ่มสถานที่ตั้งที่ยกเว้นสำหรับแคมเปญ

function excludeTennessee(campaignName) {
  const campaignIterator = AdsApp.campaigns()
      .withCondition(`campaign.name = "${campaignName}"`)
      .get();
  if (!campaignIterator.hasNext()) {
    throw new Error(`No campaign with name "${campaignName}" found`);
  }

  const campaign = campaignIterator.next();
  // Exclude Tennessee, United States (location id = 21175) See
  // https://developers.google.com/google-ads/api/reference/data/geotargets
  // for list of all supported geo codes.
  // You could pass either the location code, or a TargetedLocation or
  // ExcludedLocation object from an existing campaign.
  const tennesseeId = 21175;
  campaign.excludeLocation(tennesseeId);
}

ดึงสถานที่ตั้งที่ยกเว้นสำหรับแคมเปญ

function getExcludedLocations(campaignName) {
  const campaignIterator = AdsApp.campaigns()
      .withCondition(`campaign.name = "${campaignName}"`)
      .get();
  if (!campaignIterator.hasNext()) {
    throw new Error(`No campaign with name "${campaignName}" found`);
  }

  const campaign = campaignIterator.next();
  return campaign.targeting().excludedLocations().get();
}