Prices

Create prices

function createPrice() {
  var priceItemBuilder = AdsApp.extensions().newPriceItemBuilder();
  var priceItem = priceItemBuilder.withHeader('header1')
      .withDescription('description1')
      .withAmount(1000000)
      .withCurrencyCode('USD')
      .withUnitType('PER_DAY')
      .withFinalUrl('https://www.google.com')
      .withMobileFinalUrl('https://www.google.com')
      .build()
      .getResult();

  priceItemBuilder = AdsApp.extensions().newPriceItemBuilder();
  var priceItem2 = priceItemBuilder.withHeader('header2')
      .withDescription('description2')
      .withAmount(2000000)
      .withCurrencyCode('USD')
      .withUnitType('NONE')
      .withFinalUrl('https://www.google.com')
      .withMobileFinalUrl('https://www.google.com')
      .build()
      .getResult();

  priceItemBuilder = AdsApp.extensions().newPriceItemBuilder();
  var priceItem3 = priceItemBuilder.withHeader('header3')
      .withDescription('description3')
      .withAmount(3000000)
      .withCurrencyCode('USD')
      .withUnitType('NONE')
      .withFinalUrl('https://www.google.com')
      .withMobileFinalUrl('https://www.google.com')
      .build()
      .getResult();

  var priceBuilder = AdsApp.extensions().newPriceBuilder();
  var price = priceBuilder.withPriceType('PRODUCT_CATEGORIES')
      .withPriceQualifier('UP_TO')
      .withTrackingTemplate('http://www.example.com/track')
      .withLanguage('EN')
      .addPriceItem(priceItem)
      .addPriceItem(priceItem2)
      .addPriceItem(priceItem3)
      .build()
      .getResult();

  // Add price extension to the account.
  AdsApp.currentAccount().addPrice(price);

  // Add price extension to an ad group.
  var adGroupIterator = AdsApp.adGroups()
      .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();
    adGroup.addPrice(price);
  }

  // Add price extension to a campaign.
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    campaign.addPrice(price);
  }
}

Get prices for a campaign

function getPricesForCampaign() {
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var pricesIterator = campaign.extensions().prices().get();
    while (pricesIterator.hasNext()) {
      var price = pricesIterator.next();
      Logger.log('Price extension price qualifier: ' + price.getPriceQualifier() +
          ', Price extension price type: ' + price.getPriceType() +
          ', mobile preferred: ' + price.isMobilePreferred());
    }
    Logger.log('Total count of price extensions: ' + pricesIterator.totalNumEntities());
  }
}

Get price stats for a campaign

function getPricesStats() {
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // Retrieve the campaign's price extensions. Retrieving an ad group's
    // price extensions is similar.
    var pricesIterator = campaign.extensions().prices().get();

    while (pricesIterator.hasNext()) {
      var price = pricesIterator.next();

      // You can also request reports for pre-defined date ranges. Refer to
      // https://developers.google.com/adwords/api/docs/guides/awql,
      // DateRangeLiteral section for possible values.
      var stats = price.getStatsFor('LAST_MONTH');
      Logger.log(price.getId() + ', ' + stats.getClicks() + ', ' +
          stats.getImpressions());
    }
  }
}

Set schedule for prices in a campaign

function setPriceSchedule() {
  var campaignIterator = AdsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var pricesIterator = campaign.extensions().prices().get();
    var price = null;

    // Scan through the price extensions to locate the one with type set as Brands.
    while (pricesIterator.hasNext()) {
      price = pricesIterator.next();
      if (price.getPriceType() == 'BRANDS') {
        // Set price extension schedule to run only on Mondays and Tuesdays,
        // 9 AM to 6 PM. You can follow a similar approach to set schedules for
        // other ad extension types.
        var monday = {
            dayOfWeek: 'MONDAY',
            startHour: 9,
            startMinute: 0,
            endHour: 18,
            endMinute: 0
        };

        var tuesday = {
            dayOfWeek: 'TUESDAY',
            startHour: 9,
            startMinute: 0,
            endHour: 18,
            endMinute: 0
        };

        price.setSchedules([monday, tuesday]);

        return;
      }
    }
  }
}

Send feedback about...

Google Ads scripts
Google Ads scripts
Need help? Visit our support page.