Need Help with ConversionValueRule

128 views
Skip to first unread message

gator...@gmail.com

unread,
Aug 11, 2023, 4:47:25 PM8/11/23
to Google Ads API and AdWords API Forum
I am trying to add a conversion value rule to a campaign but can't figure out how to set the geo location.  There is a GeoTargetConstants property of ValueRuleGeoLocationCondition, but it is ReadOnly.  When I run the code below, I get a TOO_FEW error referencing geo_location_condition.  I know I need to add the location, but I can't figure out where.  What am I missing?

            Dim convRule As New ConversionValueRule With {
                .Action = New ConversionValueRule.Types.ValueRuleAction With {
                    .Operation = ValueRuleOperationEnum.Types.ValueRuleOperation.Multiply,
                    .Value = 2.0
                },
                .GeoLocationCondition = New ConversionValueRule.Types.ValueRuleGeoLocationCondition With {
                    .GeoMatchType = ValueRuleGeoLocationMatchTypeEnum.Types.ValueRuleGeoLocationMatchType.LocationOfPresence
                }
            }
            Dim operation As New ConversionValueRuleOperation With {
                .Create = convRule
            }
            Dim convRuleService As ConversionValueRuleServiceClient = client.GetService(Services.V13.ConversionValueRuleService)

            Dim request As New MutateConversionValueRulesRequest
            request.CustomerId = ClientCustomerId
            request.ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.MutableResource
            request.Operations.Add(operation)
            Dim response As MutateConversionValueRulesResponse = convRuleService.MutateConversionValueRules(request)

Google Ads API Forum Advisor

unread,
Aug 11, 2023, 6:35:34 PM8/11/23
to gator...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API Forum. I hope that you are doing well today.

Moving forward to your concern, as mentioned in the geo_location_condition in the Rule conditions, "Applies the rule to impressions where the location information matches any of the specified geo_target_constants for the geo_match_type, and does not match any of the excluded_geo_target_constants for the excluded_geo_match_type. Consult the location targeting guide for how to retrieve location resource names."

If you are still encountering the issue, you may provide us the complete request and response logs with request ID and request header generated on your end. You can provide it via Reply privately to the author option. If this option is not available, then send it instead on this email address googleadsa...@google.com. If you haven't enabled the logging yet, logging can be enabled by navigating to the Client libraries > Your client library (ex. Java) > Logging documentation, which you can access from this link.
 
This message is in relation to case "ref:_00D1U1174p._5004Q2nrBho:ref"

Thanks,
 
Google Logo Google Ads API Team


gator...@gmail.com

unread,
Aug 11, 2023, 7:08:29 PM8/11/23
to Google Ads API and AdWords API Forum
"Applies the rule to impressions where the location information matches any of the specified geo_target_constants"

How do I specify the geo_target_constants?

Google Ads API Forum Advisor

unread,
Aug 14, 2023, 4:16:23 AM8/14/23
to gator...@gmail.com, adwor...@googlegroups.com

Hi,

Thanks for getting back to us.

As per the ValueRuleGeoLocationCondition.geo_target_constants[] guide, it is a string representation of Geo locations that advertisers want to include. That said, can you try setting this value to a string of geo_target_constants?

Let us know how it goes.
 

gator...@gmail.com

unread,
Aug 14, 2023, 11:42:37 AM8/14/23
to Google Ads API and AdWords API Forum
The  GeoTargetConstants property of ValueRuleGeoLocationCondition is ReadOnly.

                '
                ' Summary:
                '     Geo locations that advertisers want to include.
                <DebuggerNonUserCode> <GeneratedCode("protoc", Nothing)>
                Public ReadOnly Property GeoTargetConstants As RepeatedField(Of String)

GeoTargetConstants.jpg

Google Ads API Forum Advisor

unread,
Aug 14, 2023, 3:27:01 PM8/14/23
to gator...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for your response.

As we previously provide under the rules conditions (https://developers.google.com/google-ads/api/docs/conversions/conversion-value-rules#rule_conditions), it was mentioned that you need to consult the location targeting guide (https://developers.google.com/google-ads/api/docs/targeting/location-targeting#retrieve_geo_targets) for how to retrieve location resource names. Then, to retrieve geo targets directly from the Google Ads API, query the geo_target_constant (https://developers.google.com/google-ads/api/fields/v14/geo_target_constant) field. You may also check this documentation (https://developers.google.com/google-ads/api/data/geotargets?hl=en) for geotargets.

Veyis Ahsak

unread,
Aug 14, 2023, 3:55:53 PM8/14/23
to Google Ads API Forum Advisor, gator...@gmail.com, Google Ads API and AdWords API Forum
Hi veyis ahsak turkey watcap 0539 631 27 35

14 Ağu 2023 Pzt 22:26 tarihinde 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum <adwor...@googlegroups.com> şunu yazdı:
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/NxFnc000000000000000000000000000000000000000000000RZEBCK00lqmMKQWURVGMd0M-nwjApw%40sfdc.net.

gator...@gmail.com

unread,
Aug 14, 2023, 4:02:11 PM8/14/23
to Google Ads API and AdWords API Forum
Your response only explains how to retrieve the location resource names.  I need to be able to SET the location for a new value rule.  HOW TO I SET A LOCATION FOR A NEW VALUE RILE?

Google Ads API Forum Advisor

unread,
Aug 14, 2023, 6:29:56 PM8/14/23
to gator...@gmail.com, adwor...@googlegroups.com

Hi there,

You may use campaignCriterionService to set the location targeting as the CampaignCriterionService, AdGroupCriterionService, and CustomerNegativeCriterionService support targeting or excluding various types of criteria. 

You may see following criteria: 

Named location targeting is implemented as LocationInfo and are created using a fixed set of criteria IDs. The available IDs are listed in the documentation and can be individually searched for using the GeoTargetConstantService. These criteria can be configured as either positive or negative, with negative targets overriding positive ones. By default a new campaign will contain no location criteria, which means that all locations are targeted. You may check more about Named location targeting.

Radius targets are implemented as ProximityInfo criteria. They can be created using either an address or latitude/longitude, and by specifying a radius. They can only be configured as positive, and by default a new campaign will not contain proximity criteria. You may check more about Radius targeting.

A LocationGroup lets campaigns target multiple geographic regions. These regions are defined by a set of locations and a distance radius around each location in either meters or miles. The set of locations is derived from the location extensions for the campaign. You can optionally use a Feed to define the set of locations. The targeting of these locations can be filtered using a list of geotargeting criteria IDs. You may check more about targeting multiple geographic regions.

Once you already have the targeting, then you may refer to the location targeting guide for how to retrieve location resource names. For more information, you may see below links:


Let us know if you have any questions. 

gator...@gmail.com

unread,
Aug 15, 2023, 11:04:24 AM8/15/23
to Google Ads API and AdWords API Forum
Your response does NOT address the problem.  After you set your geo locations on your campaign (which we have been doing for years), you need to be able to apply value rules to those locations.  That means there must be a way to specify a specific location that you want to apply a value rule to.  The geo_target_constants property of ValueRuleGeoLocationCondition seems like the logical place but it is a read only property.  Instead of posting a bunch of links to pages I have already read multiple times, how about you provide a code example of how to add a conversion value rule?

Google Ads API Forum Advisor

unread,
Aug 15, 2023, 3:14:11 PM8/15/23
to gator...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for coming back to us and providing your insights. I hope you are doing well today.

In relation to your concern, please code sample below for reference.

Request ------- MethodName: google.ads.googleads.v14.services.ConversionValueRuleService/MutateConversionValueRules Endpoint: googleads.googleapis.com:443 Headers: {developer-token=REDACTED, x-goog-api-client=gl-java/15.0.7 gccl/25.0.1-SNAPSHOT gapic/25.0.1-SNAPSHOT gax/2.29.0 grpc/1.55.1} Body: customer_id: "4985776047" operations { create {  action {   operation: ADD   value: 45.0  }  geo_location_condition {   geo_target_constants: "geoTargetConstants/1014044"   geo_match_type: ANY  } } } validate_only: true response_content_type: MUTABLE_RESOURCE partial_failure: true 

Response -------- Headers: Metadata(content-disposition=attachment,content-type=application/grpc,request-id=1AB7zOJHHOrDg_RTPIaOuw,date=Tue, 15 Aug 2023 17:50:56 GMT,alt-svc=h3=":443"; ma=2592000,h3-29=":443"; ma=2592000) Body: Failure message: null Status: Status{code=OK, description=null, cause=null}.

I have raised a feature request for this to be available in the Google Ads API documentation. This request is subject for review and for now, I would suggest keeping an eye on our blog post (https://ads-developers.googleblog.com/) or release notes (https://developers.google.com/google-ads/api/docs/release-notes) for the updates.

I hope this will help you. Have a great day.
 

gator...@gmail.com

unread,
Aug 15, 2023, 3:30:57 PM8/15/23
to Google Ads API and AdWords API Forum
Can you please provide an example of how to programmatically assign a value to geo_target_constants?

Google Ads API Forum Advisor

unread,
Aug 15, 2023, 6:14:12 PM8/15/23
to gator...@gmail.com, adwor...@googlegroups.com
Hello,

You may use this Java code snippet as reference:
public class ConversionValueRule {

    public static void main(String[] args) {
        AddConversionValueRuleParams params = new AddConversionValueRuleParams();
        if (!params.parseArguments(args)) {

            // Either pass the required parameters for this example on the command line, or insert them
            // into the code here. See the parameter class definition above for descriptions.
            params.customerId = Long.parseLong("4985776047");
        }

        GoogleAdsClient googleAdsClient = null;
        try {
            googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
        } catch (FileNotFoundException fnfe) {
            System.err.printf(
                    "Failed to load GoogleAdsClient configuration from file. Exception: %s%n", fnfe);
            System.exit(1);
        } catch (IOException ioe) {
            System.err.printf("Failed to create GoogleAdsClient. Exception: %s%n", ioe);
            System.exit(1);
        }

        try {
            new ConversionValueRule().runExample1(googleAdsClient, params.customerId);
        } catch (GoogleAdsException gae) {
            // GoogleAdsException is the base class for most exceptions thrown by an API request.
            // Instances of this exception have a message and a GoogleAdsFailure that contains a
            // collection of GoogleAdsErrors that indicate the underlying causes of the
            // GoogleAdsException.
            System.err.printf(
                    "Request ID %s failed due to GoogleAdsException. Underlying errors:%n",
                    gae.getRequestId());
            int i = 0;
            for (GoogleAdsError googleAdsError : gae.getGoogleAdsFailure().getErrorsList()) {
                System.err.printf("  Error %d: %s%n", i++, googleAdsError);
            }
            System.exit(1);
        }
    }

    private void runExample1(GoogleAdsClient googleAdsClient, long customerId) {


        List<String> geoTargetCountryCodes = ImmutableList.of("US");


        // Create a geo location condition.
        com.google.ads.googleads.v14.resources.ConversionValueRule.ValueRuleGeoLocationCondition geoLocationCondition = com.google.ads.googleads.v14.resources.ConversionValueRule.ValueRuleGeoLocationCondition.newBuilder()
                .addGeoTargetConstants("geoTargetConstants/1014044")
                .setGeoMatchType(ValueRuleGeoLocationMatchTypeEnum.ValueRuleGeoLocationMatchType.ANY)
                .build();


        com.google.ads.googleads.v14.resources.ConversionValueRule conversionValueRule =
                com.google.ads.googleads.v14.resources.ConversionValueRule.newBuilder()
                        .setAction(com.google.ads.googleads.v14.resources.ConversionValueRule.ValueRuleAction.newBuilder().setOperation(ValueRuleOperationEnum.ValueRuleOperation.ADD).setValue(45).build())
                        .setGeoLocationCondition(geoLocationCondition)
                        .build();


        // Creates the operation.

        ConversionValueRuleOperation operation = ConversionValueRuleOperation.newBuilder()
                .setCreate(conversionValueRule).build();

        try (ConversionValueRuleServiceClient conversionValueRuleServiceClient =
                     googleAdsClient.getLatestVersion().createConversionValueRuleServiceClient()) {
            MutateConversionValueRulesRequest request =
                    MutateConversionValueRulesRequest.newBuilder()
                            .setCustomerId("XXXX")
                            .addAllOperations(Collections.singletonList(operation))
                            .setPartialFailure(true)
                            .setValidateOnly(false)
                            .setResponseContentType(ResponseContentTypeEnum.ResponseContentType.MUTABLE_RESOURCE)
                            .build();

            MutateConversionValueRulesResponse response =
                    conversionValueRuleServiceClient.mutateConversionValueRules(request);
        }


    }

    private static class AddConversionActionParams extends CodeSampleParams {

        @Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
        private Long customerId;
    }
}
I hope this helps.

gator...@gmail.com

unread,
Aug 16, 2023, 11:55:49 AM8/16/23
to Google Ads API and AdWords API Forum
Thank you!  This is exactly what I was looking for.  For anyone who may be interested, you have to declare an instance of  ConversionValueRule.Types.ValueRuleGeoLocationCondition and use the GeoTargetConstants.Add method to add your locations.  

Google Ads API Forum Advisor

unread,
Aug 16, 2023, 6:19:23 PM8/16/23
to gator...@gmail.com, adwor...@googlegroups.com
Hello,

We're glad to have helped. Feel free to reach back to us if you have any further concerns or inquiries.
Reply all
Reply to author
Forward
0 new messages