Targeting for extension settings

Targeting for extension settings is done by using various fields on the ExtensionFeedItem. You can specify a start time, end time, ad schedule, device, location target, or keyword. This will restrict this extension feed item to only serving when the indicated criteria are met.

Below is a demonstration of adding a geo target to an existing extension feed item.

PHP

public static function runExample(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    int $feedItemId,
    int $geoTargetConstantId
) {
    // Creates an extension feed item using the specified feed item ID and geo target constant
    // ID for targeting.
    $extensionFeedItem = new ExtensionFeedItem([
        'resource_name' => ResourceNames::forExtensionFeedItem($customerId, $feedItemId),
        'targeted_geo_target_constant' => new StringValue([
            'value' => ResourceNames::forGeoTargetConstant($geoTargetConstantId)
        ])
    ]);

    // Constructs an operation that will update the extension feed item, using the FieldMasks
    // utility to derive the update mask. This mask tells the Google Ads API which attributes of
    // the extension feed item you want to change.
    $extensionFeedItemOperation = new ExtensionFeedItemOperation();
    $extensionFeedItemOperation->setUpdate($extensionFeedItem);
    $extensionFeedItemOperation->setUpdateMask(FieldMasks::allSetFieldsOf($extensionFeedItem));

    // Issues a mutate request to update the extension feed item.
    $extensionFeedItemServiceClient = $googleAdsClient->getExtensionFeedItemServiceClient();
    $response = $extensionFeedItemServiceClient->mutateExtensionFeedItems(
        $customerId,
        [$extensionFeedItemOperation]
    );

    // Prints the resource name of the updated extension feed item.
    /** @var ExtensionFeedItem $updatedExtensionFeedItem */
    $updatedExtensionFeedItem = $response->getResults()[0];
    printf(
        "Updated extension feed item with resource name: '%s'.%s",
        $updatedExtensionFeedItem->getResourceName(),
        PHP_EOL
    );
}
    

Ruby

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

operation = client.operation.update_resource.extension_feed_item(efi_resource_name) do |efi|
  # 2840 corresponds to the USA
  efi.targeted_geo_target_constant = client.path.geo_target_constant(2840)
end

client.service.extension_feed_item.mutate_extension_feed_items(customer_id, [operation])