쇼핑

모든 쇼핑 캠페인 가져오기

function getAllShoppingCampaigns() {
  // AdsApp.shoppingCampaigns() will return all campaigns that are not removed
  // by default.
  const campaignIterator = AdsApp.shoppingCampaigns().get();
  console.log(`Total shopping campaigns found : ${
      campaignIterator.totalNumEntities()}`);
  return campaignIterator;
}

쇼핑 캠페인을 이름으로 가져옵니다.

function getShoppingCampaignByName(shoppingCampaignName) {
  const campaignIterator = AdsApp.shoppingCampaigns()
      .withCondition(`campaign.name = "${shoppingCampaignName}"`)
      .get();

  if (campaignIterator.hasNext()) {
    const campaign = campaignIterator.next();
    console.log(`Campaign Name: ${campaign.getName()}`);
    console.log(`Enabled: ${campaign.isEnabled()}`);
    console.log(`Bidding strategy: ${campaign.getBiddingStrategyType()}`);
    console.log(`Ad rotation: ${campaign.getAdRotationType()}`);
    console.log(`Start date: ${formatDate(campaign.getStartDate())}`);
    console.log(`End date: ${formatDate(campaign.getEndDate())}`);
    return campaign;
  } else {
    throw new Error(
        `No shopping campaign named "${shoppingCampaignName}" found`);
  }
}

function formatDate(date) {
  function zeroPad(number) {
    return Utilities.formatString('%02d', number);
  }
  return (date == null) ?
      'None' :
      zeroPad(date.year) + zeroPad(date.month) + zeroPad(date.day);
}

이름으로 쇼핑 광고그룹 만들기

function getShoppingAdGroupByName(shoppingAdGroupName) {
  const adGroupIterator = AdsApp.shoppingAdGroups()
      .withCondition(`ad_group.name = "${shoppingAdGroupName}"`)
      .get();

  if (!adGroupIterator.hasNext()) {
    throw new Error(`No ad group with name "${shoppingAdGroupName}" found`);
  }

  const shoppingAdGroup = adGroupIterator.next();
  if (adGroupIterator.totalNumEntities() > 1) {
    console.warn(`Multiple ad groups named "${shoppingAdGroupName}" found.
Using the one from campaign "${shoppingAdGroup.getCampaign().getName()}"`);
  }

  return shoppingAdGroup;
}

쇼핑 광고그룹을 만듭니다.

function createElectronicsShoppingAdGroup() {
  // This example snippet assumes a user has a shopping campaign named
  // 'Shopping' and creates a new ad group named 'Electronics' in the campaign.
  // Please customize the snippet to suit your use case.
  const shoppingCampaignName = 'Shopping';
  const newAdGroupName = 'Electronics';

  const shoppingCampaign = AdsApp.shoppingCampaigns()
      .withCondition(`campaign.name = "${shoppingCampaignName}"`)
      .get()
      .next();

  const adGroupOperation = shoppingCampaign.newAdGroupBuilder()
      .withName(newAdGroupName)
      .withCpc(0.75)
      .build();

  if (adGroupOperation.isSuccessful()) {
    const adGroup = adGroupOperation.getResult();
    console.log(`Successfully created ad group "${
        adGroup.getName()}" in campaign "${adGroup.getCampaign().getName()}"`);
  } else {
    const errors = adGroupOperation.getErrors();
    console.error(`Creation failed with errors: ${errors}`);
    throw new Error(`Failed to create ad group "${
        newAdGroupName}" in campaign "${shoppingCampaignName}"`);
  }
}

쇼핑 제품 그룹 계층구조를 만듭니다.

function createElectronicsProductGroups() {
  // This example snippet assumes a user has a shopping campaign named
  // 'Shopping' that includes an ad group named 'Electronics'. Please customize
  // the product group hierarchy to suit your use case.
  const shoppingCampaignName = 'Shopping';
  const shoppingAdGroupName = 'Electronics';

  const shoppingAdGroup = AdsApp.shoppingAdGroups()
      .withCondition(`campaign.name = "${shoppingCampaignName}"`)
      .withCondition(`ad_group.name = "${shoppingAdGroupName}"`)
      .get()
      .next();

  const rootProductGroup = shoppingAdGroup.rootProductGroup();

  // The created product group hierarchy will be
  //  - root
  //    - 'Cardcow' brand
  //      - New condition
  //      - Refurbished condition
  //      - Other conditions
  //    - Other brands

  // Add a brand product group for 'Cardcow' under the root product group.
  const brandNode = rootProductGroup.newChild()
      .brandBuilder()
      .withName('Cardcow')
      .withBid(1.2)
      .build()
      .getResult();

  // Add groups for new and refurbished Cardcow brand items.
  const newItems = brandNode.newChild()
      .conditionBuilder()
      .withCondition('NEW')
      .build()
      .getResult();

  const refurbishedItems = brandNode.newChild()
      .conditionBuilder()
      .withCondition('REFURBISHED')
      .withBid(0.9)
      .build()
      .getResult();
}

계층 구조의 각 제품 그룹에 대한 작업

function actOnAllElectronicsProductGroups() {
  // This example snippet assumes a user has a hierarchy of product groups under
  // an ad group named 'Electronics' in a shopping campaign named 'Shopping'. It
  // applies the function 'actOnProductGroupAndChildren' to each product group
  // in the hierarchy. Please customize the 'actOnProductGroupAndChildren'
  // function to suit your specific use case.
  const shoppingCampaignName = 'Shopping';
  const shoppingAdGroupName = 'Electronics';

  const shoppingAdGroup = AdsApp.shoppingAdGroups()
      .withCondition(`campaign.name = "${shoppingCampaignName}"`)
      .withCondition(`ad_group.name = "${shoppingAdGroupName}"`)
      .get()
      .next();

  const rootProductGroup = shoppingAdGroup.rootProductGroup();
  actOnProductGroupAndChildren(rootProductGroup, 0);
}

function actOnProductGroupAndChildren(productGroup, level) {
  // This example function logs descriptive information about the given
  // productGroup and all children of the given productGroup. Please customize
  // the function to suit your particular use case.
  let description = '';
  if (productGroup.isOtherCase()) {
    description = 'Other';
  } else if (productGroup.getDimension() == 'CATEGORY') {
    description = productGroup.asCategory().getName();
  } else {
    description = productGroup.getValue();
  }

  // Note: Child product groups may not have a max cpc if it has been excluded.
  const padding = new Array(level + 1).join('-');
  console.log(
      '%s %s, %s, %s, %s, %s', padding, description,
      productGroup.getDimension(), productGroup.getMaxCpc(),
      productGroup.isOtherCase(), productGroup.getId().toFixed());

  for (const childProductGroup of productGroup.children()) {
    actOnProductGroupAndChildren(childProductGroup, level + 1);
  }
}

'기타' 가져오기 제품 그룹

function getEverythingElseProductGroupForAdGroup(shoppingAdGroupName) {
  const adGroupIterator = AdsApp.shoppingAdGroups()
      .withCondition(`ad_group.name = "${shoppingAdGroupName}"`)
      .get();

  if (!adGroupIterator.hasNext()) {
    throw new Error(`No ad group with name "${shoppingAdGroupName}" found`);
  }

  const shoppingAdGroup = adGroupIterator.next();
  if (adGroupIterator.totalNumEntities() > 1) {
    console.warn(`Multiple ad groups named "${shoppingAdGroupName}" found.
Using the one from campaign "${shoppingAdGroup.getCampaign().getName()}"`);
  }

  const rootProductGroup = shoppingAdGroup.rootProductGroup();
  for (const childProductGroup of rootProductGroup.children()) {
    if (childProductGroup.isOtherCase()) {
      // Note: Child product groups may not have a max cpc if it has been
      // excluded.
      console.log(
          `"Everything else" product group found. Type of the product group is ${
              childProductGroup.getDimension()} and bid is ${
              childProductGroup.getMaxCpc()}`);
      return childProductGroup;
    }
  }
  console.warn(
      '"Everything else" product group not found under root product group.');
  return null;
}

제품 그룹 입찰가 업데이트

function updateVariousProductGroupBids() {
  // This example snippet modifies the bids of some product groups based on
  // criteria. Please modify the snippet to suit your use case.
  const productGroups = AdsApp.productGroups()
      .withCondition('Clicks > 5')
      .withCondition('Ctr > 0.01')
      .forDateRange('LAST_MONTH')
      .get();

  for (const productGroup of productGroups) {
    productGroup.setMaxCpc(productGroup.getMaxCpc() + 0.01);
  }
}

제품 광고 가져오기

function getProductAdsInShoppingAdGroup(shoppingAdGroupName) {
  const adGroupIterator = AdsApp.shoppingAdGroups()
      .withCondition(`ad_group.name = "${shoppingAdGroupName}"`)
      .get();

  if (!adGroupIterator.hasNext()) {
    throw new Error(`No ad group with name "${shoppingAdGroupName}" found`);
  }

  const shoppingAdGroup = adGroupIterator.next();
  if (adGroupIterator.totalNumEntities() > 1) {
    console.warn(`Multiple ad groups named "${shoppingAdGroupName}" found.
Using the one from campaign "${shoppingAdGroup.getCampaign().getName()}"`);
  }

  const productAdIterator = shoppingAdGroup.ads().get();
  console.log(`Ad Group "${shoppingAdGroup.getName()}" has ${
      productAdIterator.totalNumEntities()} ads`);
  return productAdIterator;
}

제품 광고 만들기

function createElectronicsProductAd() {
  // This example snippet assumes a user has a shopping campaign named
  // 'Shopping' that includes an ad group named 'Electronics'. Please customize
  // the snippet to suit your use case.
  const shoppingCampaignName = 'Shopping';
  const shoppingAdGroupName = 'Electronics';

  const shoppingAdGroup = AdsApp.shoppingAdGroups()
      .withCondition(`campaign.name = "${shoppingCampaignName}"`)
      .withCondition(`ad_group.name = "${shoppingAdGroupName}"`)
      .get()
      .next();

  const adOperation =
      shoppingAdGroup.newAdBuilder().withMobilePreferred(true).build();

  if (adOperation.isSuccessful()) {
    const productAd = adOperation.getResult();
    console.log(`Successfully created product ad in ad group "${
        productAd.getAdGroup().getName()}"`);
  } else {
    const errors = adOperation.getErrors();
    console.error(`Creation failed with errors: ${errors}`);
    throw new Error(
        `Failed to create product ad in ad group "${shoppingAdGroupName}"`);
  }
}