A Demand Gen ad group offers precise bidding and serving control for the ads
under it. This is configured in [`AdGroup`](https://developers.google.com/display-video/api/reference/rest/v4/advertisers.adGroups#AdGroup) resources through the bid
strategy, inventory settings, and targeting.

Ad groups have child resources called ads which are the configured creatives
served after an auction is won.

## Choose configurations

Before creating a Demand Gen ad group, consider these optional settings to
enable further control of ad serving:

- [`bidStrategy`](https://developers.google.com/display-video/api/reference/rest/v4/advertisers.adGroups#AdGroup.FIELDS.bid_strategy) can be configured with a [`DemandGenBiddingStrategy`](https://developers.google.com/display-video/api/reference/rest/v4/BiddingStrategy#DemandGenBiddingStrategy) to set a different target value for the ad group compared to the parent line item when using a target CPA, target CPC, or target ROAS bidding strategy.
- [`adGroupInventoryControl`](https://developers.google.com/display-video/api/reference/rest/v4/advertisers.adGroups#AdGroup.FIELDS.ad_group_inventory_control) can be set to select the inventories on which the ad group will bid on and the ads will serve.
- [`targetingExpansion`](https://developers.google.com/display-video/api/reference/rest/v4/advertisers.adGroups#AdGroup.FIELDS.targeting_expansion) lets you turn on [optimized
  targeting](https://support.google.com/displayvideo/answer/12060859) for the ad group that are using audience targeting. Optimized targeting expands serving beyond your set demographic targeting. You can restrict this by excluding demographic expansion.

When creating a Demand Gen ad group, you must also set the
[`adGroupFormat`](https://developers.google.com/display-video/api/reference/rest/v4/advertisers.adGroups#AdGroup.FIELDS.ad_group_format) field to `AD_GROUP_FORMAT_DEMAND_GEN`.

## Create an ad group

Here's how to create a Demand Gen ad group with the following settings:

- A bid strategy that optimizes towards an average cost of $12 per conversion, inheriting a target CPA bid strategy from its parent line item.
- Will only bid on YouTube in-stream and shorts inventory.

> [!NOTE]
> **Note:** In this example, you create the ad group in a "paused" state. This is done as a precaution to ensure that the ad group doesn't start serving ads before targeting configuration and review.

### Java

```java
// Provide the ID of the parent advertiser.
long advertiserId = advertiser-id;

// Provide the ID of the parent line item.
long lineItemId = line-item-id;

// Provide the display name of the ad group.
String displayName = display-name;

// Create the ad group structure.
AdGroup adGroup =
    new AdGroup()
        .setLineItemId(lineItemId)
        .setDisplayName(displayName)
        .setAdGroupFormat("AD_GROUP_FORMAT_DEMAND_GEN")
        .setEntityStatus("ENTITY_STATUS_PAUSED");

// Create and set the bidding strategy.
BiddingStrategy biddingStrategy =
    new BiddingStrategy()
        .setDemandGenBid(new DemandGenBiddingStrategy().setValue(12000000L));
adGroup.setBidStrategy(biddingStrategy);

// Create and set inventory controls.
AdGroupInventoryControl inventoryControl = new AdGroupInventoryControl();
SelectedInventories selectedInventories =
    new SelectedInventories()
        .setAllowYoutubeStream(true)
        .setAllowYoutubeShorts(true);
inventoryControl.setSelectedInventories(selectedInventories);
adGroup.setAdGroupInventoryControl(inventoryControl);

// Configure the create request.
AdGroups.Create request =
    service.advertisers().adGroups().create(advertiserId, adGroup);

// Create the ad group.
AdGroup response = request.execute();

// Display the new ad group.
System.out.printf("Demand Gen ad group %s was created.", response.getName());
```

### Python

```python
# Provide the ID of the parent advertiser.
advertiser_id = advertiser-id

# Provide the ID of the parent line item.
line_item_id = line-item-id

# Provide the display name of the ad group.
display_name = display-name

# Create an ad group object with example values.
ad_group_obj = {
    "lineItemId": line_item_id,
    "displayName": display_name,
    "entityStatus": "ENTITY_STATUS_PAUSED",
    "adGroupFormat": "AD_GROUP_FORMAT_DEMAND_GEN",
    "bidStrategy": {
        "demandGenBid": {
            "value": "12000000"
        }
    },
    "adGroupInventoryControl": {
        "selectedInventories": {
            "allowYoutubeStream": True,
            "allowYoutubeShorts": True,
        }
    }
}

# Build and execute request.
response = (
    service.advertisers()
    .adGroups()
    .create(advertiserId=advertiser_id, body=ad_group_obj)
    .execute()
)

# Display the new ad group.
print(f"Demand Gen ad group {response['name']} was created.")
```

### PHP

```php
// Provide the ID of the parent advertiser.
$advertiserId = advertiser-id;

// Provide the ID of the parent line item.
$lineItemId = line-item-id;

// Provide the display name of the ad group.
$displayName = display-name;

// Create the Demand Gen ad group structure.
$adGroup = new Google_Service_DisplayVideo_AdGroup();
$adGroup->setLineItemId($lineItemId);
$adGroup->setDisplayName($displayName);
$adGroup->setAdGroupFormat('AD_GROUP_FORMAT_DEMAND_GEN');
$adGroup->setEntityStatus('ENTITY_STATUS_PAUSED');

// Create and set the bidding strategy.
$demandGenBidStrategy =
    new Google_Service_DisplayVideo_DemandGenBiddingStrategy();
$demandGenBidStrategy->setValue(12000000);
$biddingStrategy = new Google_Service_DisplayVideo_BiddingStrategy();
$biddingStrategy->setDemandGenBid($demandGenBidStrategy);
$adGroup->setBidStrategy($biddingStrategy);

// Create and set the inventory control.
$selectedInventories =
    new Google_Service_DisplayVideo_SelectedInventories();
$selectedInventories->setAllowYoutubeStream(true);
$selectedInventories->setAllowYoutubeShorts(true);
$inventoryControl =
    new Google_Service_DisplayVideo_AdGroupInventoryControl();
$inventoryControl->setSelectedInventories($selectedInventories);
$adGroup->setAdGroupInventoryControl($inventoryControl);

// Call the API, creating the ad group under the advertiser and
// line item given.
try {
    $result = $this->service->advertisers_adGroups->create(
        $advertiserId,
        $adGroup
    );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Display the new ad group.
printf('<p>Demand Gen Ad Group %s was created.</p>', $result['name']);
```