Targeting In Google Ads Api

509 views
Skip to first unread message

Martin Andrew

unread,
Mar 18, 2019, 5:50:39 PM3/18/19
to AdWords API and Google Ads API Forum
So I'm working on migrating from Adwords API to Ads api and I'm struck at one point, that is Targeting service. I cannot actually Target an Adgroup using the Ads API with either Topic or UserInterest as there are no examples available in the client libraries. I know that we have to create TopicInfo or UserInterestInfo for targeting. But how do we set the targeting Id or user interest id to the TopicInfo or UserInterestInfo, there are no setter methods for that.

val topicInfo = TopicInfo.newBuilder().setTopicConstant(StringValue.of("958"))
  .build()

val interestInfo: UserInterestInfo = UserInterestInfo
.newBuilder()
.setUserInterestCategory(StringValue.of("80412"))
.build()

Using the above topicInfo and InterestInfo, google Ads API is failing while mutating with AdgroupCriterionServiceClient. Help me out.

googleadsapi...@google.com

unread,
Mar 19, 2019, 2:12:43 AM3/19/19
to AdWords API and Google Ads API Forum
Hi Martin,

When implementing criteria targeting via Google Ads API, all you need to do is to specify the criteria resource_name like the example stated here in targeting the location. For UserInterestInfo and TopicInfo, you may refer below for sample request body. Also, you may refer to this link for complete sample code (also available in other languages that we support) on how to add campaign targeting criteria as the implementation of adding the other criteria is quite the same as this example.

Sample Request for TopicInfo
-------
MethodName: google.ads.googleads.v1.services.CampaignCriterionService/MutateCampaignCriteria
Endpoint: googleads.googleapis.com:443
Headers: {developer-token=REDACTED, login-customer-id=xxxxxxxxxx, x-goog-api-client=gl-java/1.8.0_171-google-v7 gapic/ gax/1.35.0 grpc/1.16.1}
Body: customer_id: "xxxxxxxxxx"
operations {
  create {
    campaign {
      value: "customers/[customer_id]/campaigns/[campaign_id]"
    }
    negative {
      value: true
    }
    topic {
      topic_constant {
        value: "topicConstants/958"
      }
    }
  }
}
Sample Request for UserInterestId
-------
MethodName: google.ads.googleads.v1.services.CampaignCriterionService/MutateCampaignCriteria
Endpoint: googleads.googleapis.com:443
Headers: {developer-token=REDACTED, login-customer-id=xxxxxxxxxx, x-goog-api-client=gl-java/1.8.0_171-google-v7 gapic/ gax/1.35.0 grpc/1.16.1}
Body: customer_id: "xxxxxxxxxx"
operations {
  create {
    campaign {
      value: "customers/[customer_id]/campaigns/[campaign_id]"
    }
    negative {
      value: true
    }
    user_interest {
      user_interest_category {
        value: "customers/[customer_id]/userInterests/80412"
      }
    }
  }
}
 
Thanks and regards,
Luis
Google Ads API Team


Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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+unsubscribe@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 "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/414e3fc3-8b92-4c64-b7f2-9e2c57f71f50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ramesh Kolamala

unread,
Feb 19, 2022, 8:35:29 AM2/19/22
to Google Ads API and AdWords API Forum

Hi Luis,

The above code results in exclusion of topic, so I removed 'negative' = true and tried but getting the error, below is my code and error:

My Code:
$topicId = 317;
    
    $campaignCriterion = new CampaignCriterion([
        'topic' => new TopicInfo([
            'topic_constant' => ResourceNames::forTopicConstant($topicId)
        ]),
        'campaign' => $campaignResourceName
    ]);

    $operations[] = new CampaignCriterionOperation(['create' => $campaignCriterion]);
Error:
"errorCode": { "criterionError": "FIELD_INCOMPATIBLE_WITH_NEGATIVE_TARGETING" }, "message": "The field is not allowed to be set when the negative field is set to true, e.g. we don't allow bids in negative ad group or campaign criteria.", "location": { "fieldPathElements": [ { "fieldName": "operations", "index": 0 }, { "fieldName": "create" }, { "fieldName": "topic" } ] }

Can you suggest me.


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 "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api...@googlegroups.com.

Ramesh Kolamala

unread,
Feb 19, 2022, 3:35:10 PM2/19/22
to Google Ads API and AdWords API Forum
'negative' => false is also giving the same error.

Google Ads API Forum Advisor

unread,
Feb 21, 2022, 4:19:03 AM2/21/22
to rame...@gmail.com, adwor...@googlegroups.com
HI Ramesh,

I've responded to you on this thread. Moving forward, kindly refrain from posting the same concern on multiple thread for better tracking of the issues.

Regards,
Google Logo
Teejay Wennie
Google Ads API Team
 
 

ref:_00D1U1174p._5004Q2WxJEs:ref

Ramesh Kolamala

unread,
Feb 21, 2022, 9:13:16 AM2/21/22
to Google Ads API Forum Advisor, adwor...@googlegroups.com
Sure, will do that. Thanks.
--
Thanks & Regards

K Ramesh
Zend Certified Engineer - PHP 5 & Zend Framework
Reply all
Reply to author
Forward
0 new messages