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

Requesting Exemption for Keywords

The steps for requesting exemption for keywords are as follows:

  1. Store all the exemptible policy violation keys included in PolicyViolationDetails, returned when your first attempt to create a keyword failed.
  2. Send a mutate request to create the keyword again by including the stored exemptible policy violation keys.

Store all exemptible policy violation keys

The error details for keywords will be included in PolicyViolationDetails, which in turn stores the key field whose value is an object of PolicyViolationKey.

Collect all exemptible policy violation keys to be used in the next step:

PHP

private static function fetchExemptPolicyViolationKeys(GoogleAdsException $googleAdsException)
{
    $exemptPolicyViolationKeys = [];

    printf("Google Ads failure details:%s", PHP_EOL);
    foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
        /** @var GoogleAdsError $error */
        printf(
            "\t%s: %s%s",
            $error->getErrorCode()->getErrorCode(),
            $error->getMessage(),
            PHP_EOL
        );
        if (!is_null($error->getDetails())
            && !is_null($error->getDetails()->getPolicyViolationDetails())) {
            $policyViolationDetails = $error->getDetails()->getPolicyViolationDetails();
            printf("\tPolicy violation details:%s", PHP_EOL);
            printf(
                "\t\tExternal policy name: '%s'%s",
                $policyViolationDetails->getExternalPolicyName(),
                PHP_EOL
            );
            printf(
                "\t\tExternal policy description: '%s'%s",
                $policyViolationDetails->getExternalPolicyDescription(),
                PHP_EOL
            );
            printf(
                "\t\tIs exemptible? '%s'%s",
                $policyViolationDetails->getIsExemptible() ? 'yes' : 'no',
                PHP_EOL
            );

            if ($policyViolationDetails->getIsExemptible() &&
                !is_null($policyViolationDetails->getKey())) {
                $policyViolationDetailsKey = $policyViolationDetails->getKey();
                $exemptPolicyViolationKeys[] = $policyViolationDetailsKey;
                printf("\t\tPolicy violation key:%s", PHP_EOL);
                printf(
                    "\t\t\tName: '%s'%s",
                    $policyViolationDetailsKey->getPolicyNameUnwrapped(),
                    PHP_EOL
                );
                printf(
                    "\t\t\tViolating text: '%s'%s",
                    $policyViolationDetailsKey->getViolatingTextUnwrapped(),
                    PHP_EOL
                );
            }
        }
    }
    return $exemptPolicyViolationKeys;
}

Send another mutate request by including exemptible policy violation keys

  1. Set all exemptible policy violation keys to the exempt_policy_violation_keys field of an ad group criterion operation.
  2. Send a mutate request for creating the keyword again.

PHP

private static function requestExemption(
    int $customerId,
    AdGroupCriterionServiceClient $adGroupCriterionServiceClient,
    AdGroupCriterionOperation $adGroupCriterionOperation,
    array $exemptPolicyViolationKeys
) {
    print "Try adding a keyword again by requesting exemption for its policy"
        . " violations." . PHP_EOL;
    $adGroupCriterionOperation->setExemptPolicyViolationKeys($exemptPolicyViolationKeys);
    $response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
        $customerId,
        [$adGroupCriterionOperation]
    );
    printf(
        "Successfully added a keyword 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
Нужна помощь? Обратитесь в службу поддержки.