Page Summary
-
Policy violations encountered during the initial attempt to mutate an ad can be handled by requesting an exemption.
-
This involves storing the ignorable policy topics returned in the error details.
-
A second mutate request is then sent for the ad, this time including the stored ignorable policy topics in the
PolicyValidationParameter.
The steps for requesting exemption for ads are as follows:
- Store all the ignorable policy topics included in
PolicyTopicEntry, which is stored insidePolicyFindingDetails, returned when your first attempt to mutate an ad failed. - Send a mutate request to create or update the ad again by including the stored ignorable policy topics.
In this guide, we create a responsive search ad as an example. The steps for requesting exemption are the same for all ad types and similar for all mutates (create and update).
Store all ignorable policy topics
The error details for ads are included in
PolicyFindingDetails, which in turn
stores a list of PolicyTopicEntry objects.
In this step, you store the topic field of each PolicyTopicEntry:
Java
private List<String> fetchIgnorablePolicyTopics(GoogleAdsException gae) { System.out.println("Google Ads failure details:"); // Creates a list to store the result. List<String> ignorableTopics = new ArrayList<>(); // Searches all errors for ignorable policy topics. for (GoogleAdsError error : gae.getGoogleAdsFailure().getErrorsList()) { // Supports sending exemption request for the policy finding error only. if (error.getErrorCode().getErrorCodeCase() != ErrorCodeCase.POLICY_FINDING_ERROR) { throw gae; } // Shows some information about the error encountered. System.out.printf("\t%s: %s%n", error.getErrorCode().getErrorCodeCase(), error.getMessage()); // Checks policy finding details for ignorable policy topics. if (error.getDetails() != null) { PolicyFindingDetails policyFindingDetails = error.getDetails().getPolicyFindingDetails(); if (policyFindingDetails != null) { System.out.println("\tPolicy finding details:"); // Shows all the policy topics for the current error. for (PolicyTopicEntry policyTopicEntry : policyFindingDetails.getPolicyTopicEntriesList()) { // Adds this topic to the result. ignorableTopics.add(policyTopicEntry.getTopic()); System.out.printf("\t\tPolicy topic name: '%s'%n", policyTopicEntry.getTopic()); System.out.printf("\t\tPolicy topic entry type: '%s'%n", policyTopicEntry.getType()); // 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 ignorableTopics; }
C#
private static string[] FetchIgnorablePolicyTopics(GoogleAdsException ex) { List<string> ignorablePolicyTopics = new List<string>(); ; Console.WriteLine("Google Ads failure details:"); foreach (GoogleAdsError error in ex.Failure.Errors) { if (error.ErrorCode.ErrorCodeCase != ErrorCode.ErrorCodeOneofCase.PolicyFindingError) { throw ex; } if (error.Details != null && error.Details.PolicyFindingDetails != null) { PolicyFindingDetails details = error.Details.PolicyFindingDetails; Console.WriteLine($"- Policy finding details:"); foreach (PolicyTopicEntry entry in details.PolicyTopicEntries) { ignorablePolicyTopics.Add(entry.Topic); Console.WriteLine($" - Policy topic name: '{entry.Topic}'"); Console.WriteLine($" - Policy topic entry type: '{entry.Type}'"); // For the sake of brevity, we exclude printing "policy topic evidences" // and "policy topic constraints" here. You can fetch those data by // calling: // - entry.Evidences // - entry.Constraints } } } return ignorablePolicyTopics.ToArray(); }
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->getTopic(), 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; }