Google Ads API is returning to beta status. Please read our blog post for more details.

Requesting Exemption for Expanded Text Ads and Responsive Search Ads

Expanded text ads and responsive search ads require steps for exemption request that are different from other ad types:

  1. Store all the ignorable policy topic included in PolicyTopicEntry, which is stored inside PolicyFindingDetails, returned when your first attempt to create an ad failed.
  2. Send a mutate request to create the ad again by including the stored ignorable policy topics.

Visit this guide if you wish to request exemption for other ad types instead. In this guide, we will use an expanded text ad as an example. The steps for requesting exemption for responsive search ads are mostly the same, except for the step of creating ExpandedTextAdInfo, which you need to replace with ResponsiveSearchAdInfo.

Store all ignorable policy topics

The error details for expanded text ads and responsive search ads will be included in PolicyFindingDetails, which in turn stores a list of PolicyTopicEntry objects.

In this step, you need to store the topic field of each PolicyTopicEntry:

PHP

private static function fetchIgnorablePolicyTopics(GoogleAdsException $googleAdsException)
{
    $ignorablePolicyTopics = [];

    printf("Google Ads failure details:%s", PHP_EOL);
    foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
        /** @var GoogleAdsError $error */
        if ($error->getErrorCode()->getErrorCode() !== 'policy_finding_error') {
            // This example supports sending exemption request for the policy finding error
            // only.
            throw $googleAdsException;
        }

        printf(
            "\t%s: %s%s",
            $error->getErrorCode()->getErrorCode(),
            $error->getMessage(),
            PHP_EOL
        );
        if (!is_null($error->getDetails())
            && !is_null($error->getDetails()->getPolicyFindingDetails())) {
            $policyFindingDetails = $error->getDetails()->getPolicyFindingDetails();
            printf("\tPolicy finding details:%s", PHP_EOL);

            foreach ($policyFindingDetails->getPolicyTopicEntries() as $policyTopicEntry) {
                /** @var PolicyTopicEntry $policyTopicEntry */
                $ignorablePolicyTopics[] = $policyTopicEntry->getTopic();
                printf(
                    "\t\tPolicy topic name: '%s'%s",
                    $policyTopicEntry->getTopicUnwrapped(),
                    PHP_EOL
                );
                printf(
                    "\t\tPolicy topic entry type: '%s'%s",
                    PolicyTopicEntryType::name($policyTopicEntry->getType()),
                    PHP_EOL
                );
                // For the sake of brevity, we exclude printing "policy topic evidences" and
                // "policy topic constraints" here. You can fetch those data by calling:
                // - $policyTopicEntry->getEvidences()
                // - $policyTopicEntry->getConstraints()
            }
        }
    }
    return $ignorablePolicyTopics;
}

Send another mutate request by including ignorable policy topics

  1. Create an object of PolicyValidationParameter.
  2. Set stored ignorable policy topics to the ignorable_policy_topics field of the created PolicyValidationParameter.
  3. Set PolicyValidationParameter to the policy_validation_parameter field of an ad group ad operation.
  4. Send a mutate request for creating the ad group ad as usual.

PHP

private static function requestExemption(
    int $customerId,
    AdGroupAdServiceClient $adGroupAdServiceClient,
    AdGroupAdOperation $adGroupAdOperation,
    array $ignorablePolicyTopics
) {
    print "Try adding an expanded text ad again by requesting exemption for its policy"
        . " violations." . PHP_EOL;
    $adGroupAdOperation->setPolicyValidationParameter(
        new PolicyValidationParameter(['ignorable_policy_topics' => $ignorablePolicyTopics])
    );
    $response = $adGroupAdServiceClient->mutateAdGroupAds(
        $customerId,
        [$adGroupAdOperation]
    );
    printf(
        "Successfully added an expanded text ad with resource name '%s' by requesting"
        . " for policy violation exemption.%s",
        $response->getResults()[0]->getResourceName(),
        PHP_EOL
    );
}

Code examples

The ErrorHandling folder of each client library contains the following code example that shows how to use this feature:

Оставить отзыв о...

Текущей странице
Google Ads API Beta
Google Ads API Beta
Нужна помощь? Обратитесь в службу поддержки.