Request Exemption for Keywords

  • You can request exemption for keyword policy violations by storing exemptible policy violation keys from the initial failed creation attempt.

  • To resubmit the keyword creation request with exemption, include the stored exemptible policy violation keys in a mutate request for the ad group criterion operation.

  • Keyword texts with non-exemptible policy violations cannot use this exemption process and must be modified to remove the violations.

To request exemption for keywords:

  1. Store all the exemptible policy violation keys included in PolicyViolationDetails, which is returned when your first attempt to create a keyword fails.
  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 are 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:

Java

private List<PolicyViolationKey> extractExemptiblePolicyViolationKeys(
    GoogleAdsException googleAdsException) {
  List<PolicyViolationKey> exemptibleKeys = new ArrayList<>();
  System.out.println("Google Ads failure details:");
  for (GoogleAdsError googleAdsError : googleAdsException.getGoogleAdsFailure().getErrorsList()) {
    System.out.printf("\t%s: %s%n", googleAdsError.getErrorCode(), googleAdsError.getMessage());
    if (googleAdsError.hasDetails() && googleAdsError.getDetails().hasPolicyViolationDetails()) {
      PolicyViolationDetails policyViolationDetails =
          googleAdsError.getDetails().getPolicyViolationDetails();
      System.out.println("\tPolicy violation details:");
      System.out.printf(
          "\t\tExternal policy name: '%s'%n", policyViolationDetails.getExternalPolicyName());
      System.out.printf(
          "\t\tExternal policy description: '%s'%n",
          policyViolationDetails.getExternalPolicyDescription());
      System.out.printf("\t\tIs exemptible? '%s'%n", policyViolationDetails.getIsExemptible());
      if (policyViolationDetails.getIsExemptible() && policyViolationDetails.hasKey()) {
        PolicyViolationKey policyViolationKey = policyViolationDetails.getKey();
        exemptibleKeys.add(policyViolationKey);
        System.out.println("\t\tPolicy violation key:");
        System.out.printf("\t\t\tName: '%s'%n", policyViolationKey.getPolicyName());
        System.out.printf("\t\t\tViolating text: '%s'%n", policyViolationKey.getViolatingText());
      }
    }
  }
  return exemptibleKeys;
}
      

C#

private static PolicyViolationKey[] FetchExemptPolicyViolationKeys(GoogleAdsException ex)
{
    bool isFullyExemptable = true;
    List<PolicyViolationKey> exemptPolicyViolationKeys = new List<PolicyViolationKey>();

    Console.WriteLine("Google Ads failure details:");
    foreach (GoogleAdsError error in ex.Failure.Errors)
    {
        if (error.ErrorCode.ErrorCodeCase !=
            ErrorCode.ErrorCodeOneofCase.PolicyViolationError)
        {
            Console.WriteLine("No exemption request is sent because there are other " +
                "non-policy related errors thrown.");
            throw ex;
        }
        if (error.Details != null && error.Details.PolicyViolationDetails != null)
        {
            PolicyViolationDetails details = error.Details.PolicyViolationDetails;
            Console.WriteLine($"- Policy violation details:");

            Console.WriteLine(" - Policy violation details:");
            Console.WriteLine($"   - External policy name: '{details.ExternalPolicyName}'");
            Console.WriteLine($"   - External policy description: " +
                $"'{details.ExternalPolicyDescription}'");
            Console.WriteLine($"   - Is exemptable: '{details.IsExemptible}'");

            if (details.IsExemptible && details.Key != null)
            {
                PolicyViolationKey key = details.Key;
                Console.WriteLine($"   - Policy violation key:");
                Console.WriteLine($"     - Name: {key.PolicyName}");
                Console.WriteLine($"     - Violating Text: {key.ViolatingText}");
                exemptPolicyViolationKeys.Add(key);
            }
            else
            {
                isFullyExemptable = false;
            }
        }
    }

    if (!isFullyExemptable)
    {
        Console.WriteLine("No exemption request is sent because your keyword " +
            "contained some non-exemptible policy violations.");
        throw ex;
    }
    return exemptPolicyViolationKeys.ToArray();
}
      

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->getPolicyName(),
                    PHP_EOL
                );
                printf(
                    "\t\t\tViolating text: '%s'%s",
                    $policyViolationDetailsKey->getViolatingText(),
                    PHP_EOL
                );
            } else {
                print "No exemption request is sent because your keyword contained some "
                    . "non-exemptible policy violations." . PHP_EOL;
                throw $googleAdsException;
            }
        } else {
            print "No exemption request is sent because there are other non-policy related "
                . "errors thrown." . PHP_EOL;
            throw $googleAdsException;
        }
    }
    return $exemptPolicyViolationKeys;
}