검색 잠재고객

광고그룹에 검색 잠재고객 추가

function addSearchAudienceToAdGroup(adGroupName, audienceId, bidModifier = 1.5) {

  // Retrieve the ad group.
  const adGroups = AdsApp.adGroups()
      .withCondition(`ad_group.name = "${adGroupName}"`)
      .get();

  if (!adGroups.hasNext()) {
    throw new Error(`Cannot find ad group with name "${adGroupName}"`);
  }
  const adGroup = adGroups.next();
  if (adGroups.totalNumEntities() > 1) {
    console.warn(`More than one ad group with name "${adGroupName}" was ` +
    `found. Using the ad group in campaign ` +
    `"${adGroup.getCampaign().getName()}"`);
  }

  // Create the search audience.
  const operation = adGroup.targeting()
      .newUserListBuilder()
      .withAudienceId(audienceId)
      .withBidModifier(bidModifier)
      .build();

  if (!operation.isSuccessful()) {
    console.warn(`Failed to attach search audience. ` +
    `Errors: ${operation.getErrors().join(', ')}'`);
  }

  const searchAudience = operation.getResult();

  // Display the results.
  console.log(`Search audience with name ${searchAudience.getName()} and ` +
      `ID = ${searchAudience.getId().toFixed(0)} was added to ` +
      `ad group "${adGroupName}".`);
}

광고그룹과 연결된 검색 잠재고객을 이름별로 가져오기

function getAdGroupSearchAudienceByName(campaignName, adGroupName, audienceName) {

  // Retrieve the search audience.
  const searchAudiences = AdsApp.adGroupTargeting().audiences()
      .withCondition(`campaign.name = "${campaignName}"`)
      .withCondition(`ad_group.name = "${adGroupName}"`)
      .get();

  for (const audience of searchAudiences) {
    if (audience.getName() == audienceName) {
      return audience;
    }
  }

  // Display the results.
  console.warn(`Cannot find an audience "${audienceName}" in the ad group
    "${adGroupName}" belonging to the campaign "${campaignName}".`);
}

광고그룹과 연결된 검색 잠재고객을 통계별로 필터링

function filterAdGroupAudienceByStats() {
  // Retrieve top performing search audiences.
  const topPerformingAudiences = AdsApp.adGrouptargeting().audiences()
      .withCondition(`campaign.name = "Campaign #1"`)
      .withCondition(`ad_group.name = "Ad Group #1"`)
      .withCondition("metrics.clicks > 34")
      .forDateRange("LAST_MONTH")
      .get();

  for (const audience of topPerformingAudiences) {
    const stats = audience.getStatsFor("LAST_MONTH");
    console.log(`Search audience with ID = ${audience.getId().toFixed(0)}, ` +
        `name = "${audience.getName()}" and audience list ID = ` +
        `${audience.getAudienceId()} had ${stats.getClicks()} clicks last ` +
        `month.`);
  }
}

캠페인에서 검색 잠재고객 제외

function addExcludedAudienceToCampaign(campaignName, audienceId) {

  // Retrieve the campaign.
  const campaigns = AdsApp.campaigns()
      .withCondition(`campaign.name = "${campaignName}"`)
      .get();

  if (!campaigns.hasNext()) {
    throw new Error(`Cannot find campaign with name "${campaignName}"`);
  }

  const campaign = campaigns.next();

  // Create the excluded audience.
  const operation = campaign.targeting()
      .newUserListBuilder()
      .withAudienceId(`${audienceId}``)
      .exclude();

  if (!operation.isSuccessful()) {
    console.warn(`Failed to exclude audience ${audienceId}. Errors: ${operation.getErrors().join(', ')}`);
  }
  const audience = operation.getResult();
  console.log(`Excluded audience "${audience.getName()}" from campaign ` +
      ``"${campaignName}".`);
}

캠페인에서 제외 검색 잠재고객 가져오기

function getExcludedAudiencesForCampaign(campaignName) {
  // Retrieve the campaign.
  const campaign = AdsApp.campaigns()
      .withCondition(`campaign.name = "${campaignName}"`)
      .get();

  if (!campaigns.hasNext()) {
    throw new Error(`Cannot find campaign with name "${campaignName}"`);
  }

  const campaign = campaigns.next();
  return campaign.targeting().excludedAudiences().get();
}

광고그룹 타겟팅 설정 업데이트

function setAdGroupTargetSetting(campaignName, adGroupName, group = "USER_INTEREST_AND_ALL", setting = "TARGET_ALL_TRUE") {
  // Retrieve the ad group.
  const adGroups = AdsApp.adGroups()
      .withCondition(`campaign.name = "${campaignName}"`)
      .withCondition(`ad_group.name = "${adGroupName}"`)
      .get();

  if (!adGroups.hasNext()) {
    throw new Error(`Cannot find ad group with name "${adGroupName}" in ` +
        `campaign "${campaignName}"`);
  }

  // Change the target setting.
  adGroup.targeting().setTargetingSetting(group, setting);
}

잠재고객 입찰 조정 업데이트

function updateAudienceBidModifer(campaignName, adGroupName, audienceName, bidModifier = 1.5) {
  // Create the search audience.
  const audiences = AdsApp.adGrouptargeting().audiences()
      .withCondition(`campaign.name = "${campaignName}"`)
      .withCondition(`ad_group.name = "${adGroupName}"`)
      .get();

  for (const audience of audiences) {
    if (audience.getName() == audienceName) {
      audience.bidding().setBidModifier(bidModifier);
    }
  }
}