Register for one of our Google Ads API Migration Workshops (October 5, 2021 - October 14, 2021)

Create Data Exclusions

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.

Create data exclusions programmatically using BiddingDataExclusions.

Scope

BiddingDataExclusions have a required scope that can be set to the following values. Additional scope-specific configuration options are set according to which scope is used.

  • CAMPAIGN - The exclusion is applied to specific campaigns. Set the campaigns field to a list of campaign resource names to which this exclusion will apply.
    • The maximum number of campaigns per BiddingDataExclusion is 2,000.
  • CHANNEL - The exclusion is applied to campaigns that belong to specific channel types. Set the advertising_channel_types field to a list of AdvertisingChannelTypes 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 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. A data exclusion is backward looking and should be used for events that have a start_date_time in the past and an end_date_time either in the past or future. The times are in the account's timezone.

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

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#

This example is not yet available in C#; you can take a look at the other languages.
    

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(
    $customerId,
    [$biddingDataExclusionOperation]
);

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

Python

This example is not yet available in Python; you can take a look at the other languages.
    

Ruby

This example is not yet available in Ruby; you can take a look at the other languages.
    

Perl

This example is not yet available in Perl; you can take a look at the other languages.