> [!IMPORTANT]
> **Key Point:** Data exclusions are meant to account for outages or major issues. Using them often or for long periods could negatively impact Smart Bidding performance.

Data exclusions are an advanced tool that can be used to inform Smart Bidding to
ignore all data from dates when there were issues with an account's conversion
tracking. For more details about how data exclusions work, refer to the
[data exclusions help page](https://support.google.com/google-ads/answer/10370710).

Create, update, or remove data exclusions programmatically using the
[`BiddingDataExclusion`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt) resource and
[`BiddingDataExclusionService.MutateBiddingDataExclusions`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusionService/MutateBiddingDataExclusions.md.txt)
with [`BiddingDataExclusionOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusionOperation.md.txt)
(`create`, `update`, or `remove`; note that
[`BiddingDataExclusion.status`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt#status) is
read-only/`OUTPUT_ONLY`). You cannot create a `BiddingDataExclusion` in a
manager account; you must create it in a client customer account with a scope of
`CAMPAIGN` or `CHANNEL`.

## Scope

A `BiddingDataExclusion` has a required
[`scope`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt#scope) that can be set to the
following values. Additional scope-specific configuration options are set
according to which scope is used.

> [!NOTE]
> **Note:** There is also a read-only `CUSTOMER` scope, but it cannot be used to create new data exclusions.

- `CAMPAIGN`: The exclusion is applied to specific campaigns. Set the [`campaigns`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt#campaigns%5B%5D) field to a list of campaign resource names to which this exclusion will apply.
- `CHANNEL`: The exclusion is applied to campaigns that belong to specific channel types. Set the [`advertising_channel_types`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt#advertising_channel_types%5B%5D) field to a list of `AdvertisingChannelType` values to which this exclusion will apply.

## Devices

In addition to their scope, data exclusions can be configured with an optional
list of device types to which the exclusion will apply. If
[`devices`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt#devices%5B%5D) is set, only conversion data from the specified
device types are excluded. If not specified, conversion data from all device
types will be excluded.

## Dates and times

Aside from the scope and optional devices, each data exclusion must have a start
and end date and time formatted as `yyyy-MM-dd HH:mm:ss`. A data exclusion is
backward looking and should be used for events that have a
[`start_date_time`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt#start_date_time) in the
past and an [`end_date_time`](https://developers.google.com/google-ads/api/reference/rpc/v26/BiddingDataExclusion.md.txt#end_date_time)
either in the past or future. The times are in the account's timezone.

## Limits

When working with `BiddingDataExclusion` resources, keep the following limits in
mind:

- A single `BiddingDataExclusion` can apply to a maximum of 2,000 campaigns when the scope is set to `CAMPAIGN`.
- Each customer account, including manager and test accounts, can have a maximum of 500 active bidding data exclusions at any given time. Exceeding this limit will result in a `RESOURCE_LIMIT` error.

## Example

The following example shows how to create a data exclusion with `CHANNEL` scope.
Commented out sections demonstrate how to specify campaigns if you were to
instead set a `CAMPAIGN` scope:


### Java

```java
BiddingDataExclusion DataExclusion =
    BiddingDataExclusion.newBuilder()
        // A unique name is required for every data exclusion.
        .setName("Data exclusion #" + getPrintableDateTime())
        // The CHANNEL scope applies the data exclusion to all campaigns of specific
        // advertising channel types. In this example, the exclusion will only apply to
        // Search campaigns. Use the CAMPAIGN scope to instead limit the scope to specific
        // campaigns.
        .setScope(SeasonalityEventScope.CHANNEL)
        .addAdvertisingChannelTypes(AdvertisingChannelType.SEARCH)
        // If setting scope CAMPAIGN, add individual campaign resource name(s) according to
        // the commented out line below.
        // .addCampaigns("INSERT_CAMPAIGN_RESOURCE_NAME_HERE")
        .setStartDateTime(startDateTime)
        .setEndDateTime(endDateTime)
        .build();

BiddingDataExclusionOperation operation =
    BiddingDataExclusionOperation.newBuilder().setCreate(DataExclusion).build();

MutateBiddingDataExclusionsResponse response =
    DataExclusionServiceClient.mutateBiddingDataExclusions(
        customerId.toString(), ImmutableList.of(operation));
System.out.printf(
    "Added data exclusion with resource name: %s%n",
    response.getResults(0).getResourceName());
      
```

### C#

```c#
BiddingDataExclusion dataExclusion = new BiddingDataExclusion()
{
    // A unique name is required for every data exclusion.
    Name = "Data exclusion #" + ExampleUtilities.GetRandomString(),
    // The CHANNEL scope applies the data exclusion to all campaigns of specific
    // advertising channel types. In this example, the the exclusion will only apply to
    // Search campaigns. Use the CAMPAIGN scope to instead limit the scope to specific
    // campaigns.
    Scope = SeasonalityEventScope.Channel,
    AdvertisingChannelTypes = { AdvertisingChannelType.Search },
    // The date range should be less than 14 days.
    StartDateTime = startDateTime,
    EndDateTime = endDateTime,
};
BiddingDataExclusionOperation operation = new BiddingDataExclusionOperation()
{
    Create = dataExclusion
};

try
{
    MutateBiddingDataExclusionsResponse response =
        biddingDataExclusionService.MutateBiddingDataExclusions(
            customerId.ToString(), new[] { operation });
    Console.WriteLine($"Added data exclusion with resource name: " +
        $"{response.Results[0].ResourceName}");
}
catch (GoogleAdsException e)
{
    Console.WriteLine("Failure:");
    Console.WriteLine($"Message: {e.Message}");
    Console.WriteLine($"Failure: {e.Failure}");
    Console.WriteLine($"Request ID: {e.RequestId}");
    throw;
}
      
```

### PHP

```php
// Creates a bidding data exclusion.
$dataExclusion = new BiddingDataExclusion(
    [
    // A unique name is required for every data exclusion.
    'name' => 'Data exclusion #' . Helper::getPrintableDatetime(),
    // The CHANNEL scope applies the data exclusion to all campaigns of specific
    // advertising channel types. In this example, the exclusion will only apply to
    // Search campaigns. Use the CAMPAIGN scope to instead limit the scope to specific
    // campaigns.
    'scope' => SeasonalityEventScope::CHANNEL,
    'advertising_channel_types' => [AdvertisingChannelType::SEARCH],
    // If setting scope CAMPAIGN, add individual campaign resource name(s) according to
    // the commented out line below.
    // 'campaigns' => ['INSERT_CAMPAIGN_RESOURCE_NAME_HERE'],
    'start_date_time' => $startDateTime,
    'end_date_time' => $endDateTime
    ]
);

// Creates a bidding data exclusion operation.
$biddingDataExclusionOperation = new BiddingDataExclusionOperation();
$biddingDataExclusionOperation->setCreate($dataExclusion);

// Submits the bidding data exclusion operation to add the bidding data exclusion.
$biddingDataExclusionServiceClient =
    $googleAdsClient->getBiddingDataExclusionServiceClient();
$response = $biddingDataExclusionServiceClient->mutateBiddingDataExclusions(
    MutateBiddingDataExclusionsRequest::build($customerId, [$biddingDataExclusionOperation])
);

printf(
    "Added bidding data exclusion with resource name: '%s'.%s",
    $response->getResults()[0]->getResourceName(),
    PHP_EOL
);
      
```

### Python

```python
bidding_data_exclusion_service: BiddingDataExclusionServiceClient = (
    client.get_service("BiddingDataExclusionService")
)
operation: BiddingDataExclusionOperation = client.get_type(
    "BiddingDataExclusionOperation"
)
bidding_data_exclusion: BiddingDataExclusion = operation.create
# A unique name is required for every data exclusion
bidding_data_exclusion.name = f"Data exclusion #{uuid4()}"
# The CHANNEL scope applies the data exclusion to all campaigns of specific
# advertising channel types. In this example, the exclusion will only
# apply to Search campaigns. Use the CAMPAIGN scope to instead limit the
# scope to specific campaigns.
bidding_data_exclusion.scope = (
    client.enums.SeasonalityEventScopeEnum.CHANNEL
)
bidding_data_exclusion.advertising_channel_types.append(
    client.enums.AdvertisingChannelTypeEnum.SEARCH
)
# If setting scope CAMPAIGN, add individual campaign resource name(s)
# according to the commented out line below.
#
# bidding_data_exclusion.campaigns.append(
#     "INSERT_CAMPAIGN_RESOURCE_NAME_HERE"
# )

bidding_data_exclusion.start_date_time = start_date_time
bidding_data_exclusion.end_date_time = end_date_time

response: MutateBiddingDataExclusionsResponse = (
    bidding_data_exclusion_service.mutate_bidding_data_exclusions(
        customer_id=customer_id, operations=[operation]
    )
)

resource_name: str = response.results[0].resource_name

print(f"Added data exclusion with resource name: '{resource_name}'")
      
```

### Ruby

```ruby
client = Google::Ads::GoogleAds::GoogleAdsClient.new

operation = client.operation.create_resource.bidding_data_exclusion do |bda|
  # A unique name is required for every data excluseion.
  bda.name = "Seasonality Adjustment #{(Time.new.to_f * 1000).to_i}"

  # The CHANNEL scope applies the data exclusion to all campaigns of specific
  # advertising channel types. In this example, the conversion_rate_modifier
  # will only apply to Search campaigns. Use the CAMPAIGN scope to instead
  # limit the scope to specific campaigns.
  bda.scope = :CHANNEL
  bda.advertising_channel_types << :SEARCH

  # If setting scope CAMPAIGN, add individual campaign resource name(s)
  # according to the commented out line below.
  #
  # bda.campaigns << "INSERT_CAMPAIGN_RESOURCE_NAME_HERE"

  bda.start_date_time = start_date_time
  bda.end_date_time = end_date_time
end

response = client.service.bidding_data_exclusion.mutate_bidding_data_exclusions(
  customer_id: customer_id,
  operations: [operation],
)

puts "Added data exclusion with resource name #{response.results.first.resource_name}."
      
```

### Perl

```perl
my $data_exclusion =
  Google::Ads::GoogleAds::V26::Resources::BiddingDataExclusion->new({
    # A unique name is required for every data exclusion.
    name => "Data exclusion #" . uniqid(),
    # The CHANNEL scope applies the data exclusion to all campaigns of specific
    # advertising channel types. In this example, the exclusion will only apply
    # to Search campaigns. Use the CAMPAIGN scope to instead limit the scope to
    # specific campaigns.
    scope                   => CHANNEL,
    advertisingChannelTypes => [SEARCH],
    # If setting scope CAMPAIGN, add individual campaign resource name(s)
    # according to the commented out line below.
    # campaigns     => ["INSERT_CAMPAIGN_RESOURCE_NAME_HERE"],
    startDateTime => $start_date_time,
    endDateTime   => $end_date_time
  });

my $operation =
  Google::Ads::GoogleAds::V26::Services::BiddingDataExclusionService::BiddingDataExclusionOperation
  ->new({
    create => $data_exclusion
  });

my $response = $api_client->BiddingDataExclusionService()->mutate({
    customerId => $customer_id,
    operations => [$operation]});

printf "Added data exclusion with resource name: '%s'.\n",
  $response->{results}[0]{resourceName};
      
```

### curl

> [!NOTE]
> **Note:** While a direct REST code sample for this step isn't provided here, you can achieve this using a manual REST request.   
>
> Refer to the Google Ads API REST interface documentation and the method-specific reference pages. You will need to construct the JSON payload based on the proto definitions.   
>
> Key Resources:
>
> - [Using REST](https://developers.google.com/google-ads/api/rest/overview.md.txt)
> - [REST Interface Structure](https://developers.google.com/google-ads/api/rest/design/overview.md.txt)
> - [JSON Field Mappings](https://developers.google.com/google-ads/api/rest/design/json-mappings.md.txt)
> - Consult the [REST API Reference](https://developers.google.com/google-ads/api/reference/rpc/latest/overview) for the specific service and method.

<br />