AdGroupBuilder

Contains the methods used to define and add an ad group. For information about builders, see Builders.

Example usage:

    // Get a campaign to add the ad group to.
    var iterator = AdsApp.campaigns()
        .withIds(['CAMPAIGN ID GOES HERE'])
        .get();

    while (iterator.hasNext()) {
        var campaign = iterator.next();

        // Get the campaign's ad group builder and add an ad group.
        var operation = campaign.newAdGroupBuilder()
            .withName("AD GROUP NAME GOES HERE")
            .withStatus("ENABLED")
            .build();
    
        // See the Builders topic for performance considerations
        // when using the operation object's methods.
        if (!operation.isSuccessful()) {
            for (var error of operation.getErrors()) {
                Logger.log(`${error}\n`);
            }
        }
    }

Methods

Method Name Return Type Description
build AdGroupOperation Creates the ad group and returns an operation object used to check whether the ad group was successfully added.
withBiddingStrategy(string biddingStrategy) AdGroupBuilder Sets the ad group's bidding strategy.
withCpc(double cpc) AdGroupBuilder Sets the ad group's maximum CPC bid.
withCpm(double cpm) AdGroupBuilder Sets the ad group's maximum CPM bid.
withCpv(double cpv) AdGroupBuilder Sets the ad group's maximum CPV bid.
withCustomParameters(Object customParameters) AdGroupBuilder Sets the ad group's custom parameters.
withEndDate(string endDate) AdGroupBuilder Sets the date when ads in the ad group stop serving.
withEndDate(Object endDate) AdGroupBuilder Sets the date when ads in the ad group stop serving.
withLanguage(string language) AdGroupBuilder Sets the language used by this ad group.
withName(string name) AdGroupBuilder Sets the ad group's name.
withStartDate(string startDate) AdGroupBuilder Sets the date when ads in the ad group start serving.
withStartDate(Object startDate) AdGroupBuilder Sets the date when ads in the ad group start serving.
withStatus(string status) AdGroupBuilder Sets the ad group's status.
withTrackingTemplate(string trackingTemplate) AdGroupBuilder Sets the ad group's tracking template.

build

Creates the ad group and returns an operation object used to check whether the ad group was successfully added.

Returns

Type Description
AdGroupOperation An operation object used to check whether the ad group was successfully added.

withBiddingStrategy(string biddingStrategy)

Sets the ad group's bidding strategy.

Arguments

Name Type Description
biddingStrategy string The bidding strategy to apply to the ad group. The following are the possible case-sensitive values.
  • MANUAL_CPC
  • MANUAL_CPM
  • MANUAL_CPV
For information about these strategies, see Bid Strategy Types.

Returns

Type Description
AdGroupBuilder Ad group builder with the bidding strategy applied.

withCpc(double cpc)

Sets the ad group's CPC bid.

Specifies the bid amount to use when the keyword matches the user's search term and the ad group's bid strategy is MANUAL_CPC. This bid is used if a lower-level entity such as keyword does not override it.

Arguments

Name Type Description
cpc double The ad group's maximum CPC bid. The account's currency determines the minimum and maximum bid values. For more information, see Bid and budget currencies.

Returns

Type Description
AdGroupBuilder Ad group builder with the CPC bid applied.

withCpm(double cpm)

Sets the ad group's CPM bid.

Specifies the bid amount to use per 1,000 viewed impressions, and when the ad group's bid strategy is MANUAL_CPM.

Arguments

Name Type Description
cpm double The ad group's maximum CPM bid. The account's currency determines the minimum and maximum bid values. For more information, see Bid and budget currencies.

Returns

Type Description
AdGroupBuilder Ad group builder with the CPM bid applied.

withCpv(double cpv)

Sets the ad group's CPV bid.

Specifies the bid amount to use per view or per click on a video ad, and when the ad group's bid strategy is MANUAL_CPV.

Arguments

Name Type Description
cpv double The ad group's maximum CPV bid. The account's currency determines the minimum and maximum bid values. For more information, see Bid and budget currencies.

Returns

Type Description
AdGroupBuilder Ad group builder with the CPV bid applied.

withCustomParameters(Object customParameters)

Sets the ad group's custom parameters to use in final URLs or tracking templates.

Custom parameters are helpful with sharing dynamic information across multiple URLs. For more information about its usage, see Custom Parameters.

Arguments

Name Type Description
customParameters Object A map of up to three custom parameters to apply to the ad group. For example, {key1: 'value1', key2: 'value2', key3: 'value3'}, where key is the custom parameter's name and value is the parameter's value. The name may contain a maximum of 16 8-byte characters and the value may contain a maximum of 200 8-byte characters.

Returns

Type Description
AdGroupBuilder Ad group builder with the custom parameters applied.

withEndDate(string endDate)

Sets the date when ads in the ad group stop serving. Call this method only if you want ads in the group to stop serving on a specific date.

Arguments

Name Type Description
endDate string The date to stop serving ads. Specify the date in the form, YYYYMMDD.

Returns

Type Description
AdGroupBuilder Ad group builder with the end date applied.

withEndDate(Object endDate)

Sets the date when ads in the ad group stop serving. Call this method only if you want ads in the group to stop serving on a specific date.

Arguments

Name Type Description
endDate Object The date to stop serving ads. Specify the date using an object with the following fields:
  • year
  • month
  • day

For example: var date = {year: 2018, month: 5, day: 13};

The month is one-based where 1 is January and 12 is December.

Returns

Type Description
AdGroupBuilder Ad group builder with the end date applied.

withLanguage(string language)

Sets the language used by ads in this ad group.

By default, the ad group inherits the language from its parent campaign. Specify a language at the ad group level to override the language specified at the campaign level or if the campaign doesn't specify a language (language must be specified at the campaign and/or ad group level).

Arguments

Name Type Description
language string The language used by ads in the ad group. For example, English. The string is case insensitive. Do not use a two-character language code. For a list of supported languages, see Ad Languages.

Returns

Type Description
AdGroupBuilder Ad group builder with the language applied.

withName(string name)

Sets the ad group's name.

Arguments

Name Type Description
name string The ad group's name. The name is required. The name may contain a maximum of 256 characters and must be unique amongst all active ad groups in the campaign.

Returns

Type Description
AdGroupBuilder Ad group builder with the name applied.

withStartDate(string startDate)

Sets the date when ads in the ad group start serving. Call this method only if you want ads in the group to start serving on a specific date; otherwise, ads start serving immediately.

Arguments

Name Type Description
endDate string The date to start serving ads. Specify the date in the form, YYYYMMDD.

Returns

Type Description
AdGroupBuilder Ad group builder with the start date applied.

withStartDate(Object startDate)

Sets the date when ads in the ad group start serving. Call this method only if you want ads in the group to start serving on a specific date; otherwise, ads start serving immediately.

Arguments

Name Type Description
endDate Object The date to start serving ads. Specify the date using an object with the following fields:
  • year
  • month
  • day

For example: var date = {year: 2018, month: 5, day: 13};

The month is one-based where 1 is January and 12 is December.

Returns

Type Description
AdGroupBuilder Ad group builder with the start date applied.

withStatus(string status)

Sets the ad group's status.

Arguments

Name Type Description
status String The ad group's status. The following are the possible case-sensitive values.
  • ENABLED
  • PAUSED
  • REMOVED
The default is PAUSED.

Returns

Type Description
AdGroupBuilder Ad group builder with the status applied.

withTrackingTemplate(string trackingTemplate)

Sets the ad group's tracking template.

Tracking templates are used with the keyword's FinalUrl to create the destination URL used by the ad. For more information, see What tracking or URL parameters can I use?

Arguments

Name Type Description
trackingTemplate string The tracking template to use with the ad group.

Returns

Type Description
AdGroupBuilder Ad group builder with the tracking template applied.

See also

Campaign.newAdGroupBuilder()