When you work with listing group filters in the context of an
[`AdGroupCriterion.listing_group`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterion#listing_group) or an
[`AssetGroupListingGroupFilter`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilter), take the
following considerations into account when designing your integration.

## Batch splitting

> [!IMPORTANT]
> **Key Point:** We recommend adding [`AssetGroupListingGroupFilterOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilterOperation) operations (`create`, `update`, and `remove`) targeting the same [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup), and [`AdGroupCriterionOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterionOperation) operations (`create`, `update`, and `remove`) for [`LISTING_GROUP`](https://developers.google.com/google-ads/api/reference/rpc/v26/CriterionTypeEnum.CriterionType#listing_group) criteria ([`AdGroupCriterion.listing_group`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterion#listing_group)) targeting the same [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup), to a batch job consecutively, so that the set of operations is treated atomically during batch splitting.

If there are any operations in a batch job that contain ad group criteria or
asset group listing group filters, the operations in the batch job are split
into multiple *sub-batches* when received by the Google Ads API server. Unlike standard
operations in a batch job, each sub-batch containing listing group filter
operations is treated atomically.

The way in which batch jobs containing listing group filters are split into
sub-batches is determined by the following factors:

1. Type of listing group filter
2. The [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup) or [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup) the listing group filter is targeting
3. Order of operations

Consider how operations are grouped:

- All consecutive [`AssetGroupListingGroupFilterOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilterOperation) operations (`create`, `update`, and `remove`) targeting the same [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup) are grouped together in an atomic sub-batch (no partial failure behavior).
- All consecutive [`AdGroupCriterionOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterionOperation) operations (`create`, `update`, and `remove`) for [`LISTING_GROUP`](https://developers.google.com/google-ads/api/reference/rpc/v26/CriterionTypeEnum.CriterionType#listing_group) criteria ([`AdGroupCriterion.listing_group`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterion#listing_group)) targeting the same [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup) are grouped together in an atomic sub-batch (no partial failure behavior).
- All other consecutive operations are grouped together in non-atomic sub-batches (partial failure behavior).

> [!NOTE]
> **Note:** If you are also creating the [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup) in the same batch job, place any prerequisite [`AssetOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetOperation) (`create`) operations for new [`Asset`](https://developers.google.com/google-ads/api/reference/rpc/v26/Asset) resources before the [`AssetGroupOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupOperation) (`create`), followed immediately by its [`AssetGroupAssetOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupAssetOperation) (`create`) operations (which execute together in a preceding atomic sub-batch), and then the consecutive [`AssetGroupListingGroupFilterOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilterOperation) operations (which execute in the next atomic sub-batch). Because these form two separate sub-batches, a failure in the [`AssetGroupListingGroupFilterOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilterOperation) sub-batch rolls back the listing group filters without rolling back the newly created [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup) and [`AssetGroupAsset`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupAsset) resources.

> [!IMPORTANT]
> **Key Term:** **Consecutive** refers to the order of the operations in the batch job. If operations targeting the same [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup) or [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup) are interleaved with operations targeting a different group, they are split into separate sub-batches and are no longer processed as a single atomic transaction.

The following diagram illustrates this concept. Each of the gray boxes
represents a batch job as submitted using the Google Ads API. Within the gray boxes,
the individual operations are grouped by color to represent the sub-batches that
the Google Ads API server creates. The order of the operations in each of the gray
boxes corresponds to the order in which the operations would have been added to
the batch job.

![Diagram showing batch operations grouped into sub-batches](https://developers.google.com/static/google-ads/api/images/listing_group_batching.svg)

## Limitations

When working with listing group filters in the context of batch jobs, the
following limitations apply:

- A single atomic sub-batch of consecutive [`AdGroupCriterionOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterionOperation) operations (`create`, `update`, and `remove`) for [`LISTING_GROUP`](https://developers.google.com/google-ads/api/reference/rpc/v26/CriterionTypeEnum.CriterionType#listing_group) criteria ([`AdGroupCriterion.listing_group`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterion#listing_group)) targeting the same [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup) cannot exceed 20,000 operations in length. However, it is recommended not to exceed 10,000 operations. Because each [`AddBatchJobOperationsRequest`](https://developers.google.com/google-ads/api/reference/rpc/v26/AddBatchJobOperationsRequest) is capped at 10,000 operations, an [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup) sub-batch of 10,001 to 20,000 operations must be uploaded across at least two consecutive [`AddBatchJobOperations`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobService/AddBatchJobOperations) requests.
- A single atomic sub-batch of consecutive [`AssetGroupListingGroupFilterOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilterOperation) operations (`create`, `update`, and `remove`) targeting the same [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup) cannot exceed 10,000 operations.
- Violating either of these operation count limits (or exceeding the server's internal serialized byte size limit for a single sub-batch) aborts the batch job at that sub-batch: any earlier sub-batches that already completed remain committed, while all operations in the offending sub-batch and any subsequent sub-batches fail with [`InternalError.INTERNAL_ERROR`](https://developers.google.com/google-ads/api/reference/rpc/v26/InternalErrorEnum.InternalError#internal_error).

## Troubleshooting

Listing group filter operations in a batch job are processed as one transaction,
which can lead to scenarios where many operations fail due to a small number of
erroneous operations. Further, because of the way [`BatchJob`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJob)
operations are processed, the root cause of the failures may appear at an index
before or after the downstream failures.

For example, when processing a response from
[`ListBatchJobResults`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobService/ListBatchJobResults):

- For [`AdGroupCriterionOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupCriterionOperation) listing groups, you may find that consecutive operations targeting the same [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup) failed with [`CriterionError.LISTING_GROUP_ERROR_IN_ANOTHER_OPERATION`](https://developers.google.com/google-ads/api/reference/rpc/v26/CriterionErrorEnum.CriterionError#listing_group_error_in_another_operation) (`Product group operations are atomic within the same ad group. This
  operation failed because another operation targeting the same ad group ID
  was invalid.`).
- For [`AssetGroupListingGroupFilterOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilterOperation) operations, you may find that consecutive operations targeting the same [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup) failed with [`BatchJobError.ASSET_GROUP_LISTING_GROUP_FILTER_TRANSACTION_FAILURE`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobErrorEnum.BatchJobError#asset_group_listing_group_filter_transaction_failure).

These errors indicate that the operation at that index was rolled back because
another operation in the same atomic sub-batch failed. To identify the root
cause of the issue, iterate through the [`status`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobResult#status)
messages in each [`BatchJobResult`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobResult)---before and after the
[`operation_index`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobResult#operation_index) of the transaction error---for
operations sharing the same [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup) or [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup)
ID.