Mobile Device criterion targeting on a campaign

81 views
Skip to first unread message

James Matthews

unread,
Aug 19, 2019, 1:04:32 AM8/19/19
to AdWords API and Google Ads API Forum
Hi,

I am currently trying to add specific mobile device targeting to many large campaigns. The web based interface on adwords means this has to be manually done for each campaign and will take a very long time.

I have looked into adding the mobile device targeting via PHP and using the the Adwords API library but have no yet had any success.

From my understanding i will want to use the Google\AdsApi\AdWords\v201809\cm\MobileDevice class to do this and the /AdWords/v201809/Targeting/AddCampaignTargetingCriteria.php class could serve as a base for this?

I have managed to send a request to google to fetch a device by name.

e.g.
$mobile = new MobileDevice();
$mobile
->setDeviceName('Samsung J5 Prime (SM-G570F)');
       
$campaignCriteria
[] = new CampaignCriterion($campaignId, null, $mobile);

...
etc


The response fails and states that i need to set the device id, however i have no been able to find any resource or api call that references these id's?

The webpage here lists lots of differnt criterion id's but none for mobile devices.
https://developers.google.com/adwords/api/docs/appendix/codes-formats#platforms

How should i do this?

Regards,
James

Google Ads API Forum Advisor Prod

unread,
Aug 19, 2019, 2:14:19 AM8/19/19
to adwor...@googlegroups.com
Hi James,

Apologies as we currently do not have an example specifically tailored to your requirement. However, you are correct with the example that you are referring to on how to add targeting criteria to a specific campaign. If you wish to add these in bulk, I would recommend that you also check out our batch processing guide (since this supports the CampaignCriterionOperation) as to how.

Moving forward to your issue, the ID field should only be required when you are passing a SET or REMOVE operation and the said field should not be required for ADD operations. That being said, could you provide the complete SOAP request and response logs so I can further investigate?

You may send your reply using the Reply privately to author option.

Thanks and regards,
Peter
Google Ads API Team

ref:_00D1U1174p._5001UEJSqY:ref

James Matthews

unread,
Aug 20, 2019, 9:42:56 AM8/20/19
to AdWords API and Google Ads API Forum
Hi Peter,

Thank you for the feedback and help. Unfortunately even when using an ADD operation the error returned is still stating a id must be set.

Request and response included below.


<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
   
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   
xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201809"
   
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   
<SOAP-ENV:Header>
       
<ns1:RequestHeader>
           
<ns1:clientCustomerId>XXX-XXX-XXXX</ns1:clientCustomerId>
           
<ns1:developerToken>REDACTED</ns1:developerToken>
           
<ns1:userAgent>unknown (AwApi-PHP, googleads-php-lib/42.0.0, PHP/7.3.7-1+ubuntu18.10.1+deb.sury.org+1)</ns1:userAgent>
           
<ns1:validateOnly>false</ns1:validateOnly>
           
<ns1:partialFailure>false</ns1:partialFailure>
       
</ns1:RequestHeader>
   
</SOAP-ENV:Header>
   
<SOAP-ENV:Body>
       
<ns1:mutate>
           
<ns1:operations>
               
<ns1:operator>ADD</ns1:operator>
               
<ns1:operand>
                   
<ns1:campaignId>2087725659</ns1:campaignId>
                   
<ns1:criterion xsi:type="ns1:MobileDevice">
                       
<ns1:deviceName>Samsung J5 Prime (SM-G570F)</ns1:deviceName>
                   
</ns1:criterion>
               
</ns1:operand>
           
</ns1:operations>
       
</ns1:mutate>
   
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<soap:Envelope
   
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   
<soap:Header>
       
<ResponseHeader
           
xmlns="https://adwords.google.com/api/adwords/cm/v201809">
           
<requestId>0005908c720423fb02ab42cca40bd386</requestId>
           
<serviceName>CampaignCriterionService</serviceName>
           
<methodName>mutate</methodName>
           
<operations>1</operations>
           
<responseTime>143</responseTime>
       
</ResponseHeader>
   
</soap:Header>
   
<soap:Body>
       
<soap:Fault>
           
<faultcode>soap:Client</faultcode>
           
<faultstring>[RequiredError.REQUIRED @ operations[0].operand.criterion.id]</faultstring>
           
<detail>
               
<ApiExceptionFault
                   
xmlns="https://adwords.google.com/api/adwords/cm/v201809">
                   
<message>[RequiredError.REQUIRED @ operations[0].operand.criterion.id]</message>
                   
<ApplicationException.Type>ApiException</ApplicationException.Type>
                   
<errors
                       
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RequiredError">
                       
<fieldPath>operations[0].operand.criterion.id</fieldPath>
                       
<fieldPathElements>
                           
<field>operations</field>
                           
<index>0</index>
                       
</fieldPathElements>
                       
<fieldPathElements>
                           
<field>operand</field>
                       
</fieldPathElements>
                       
<fieldPathElements>
                           
<field>criterion</field>
                       
</fieldPathElements>
                       
<fieldPathElements>
                           
<field>id</field>
                       
</fieldPathElements>
                       
<trigger></trigger>
                       
<errorString>RequiredError.REQUIRED</errorString>
                       
<ApiError.Type>RequiredError</ApiError.Type>
                       
<reason>REQUIRED</reason>
                   
</errors>
               
</ApiExceptionFault>
           
</detail>
       
</soap:Fault>
   
</soap:Body>
</soap:Envelope>

I have tried setting the id to 0 and null and give errors of out of range and the above XML response, respectively. Do you have any further ideas as to what may be going wrong?

Kind Regards,
James

Google Ads API Forum Advisor Prod

unread,
Aug 20, 2019, 1:33:02 PM8/20/19
to jpmatth...@gmail.com, adwor...@googlegroups.com
Hi James, 

I'm Peter's colleague addressing your concern as he is out of office. You will be able to use the ConstantDataService.getMobileDeviceCriterion() to pull the specific criteria IDs for Mobile devices. You will need to use the Criteria Id for the corresponding mobile device in your request. Could you please give this a try?

Thanks,
Bharani, Google Ads API Team

ref:_00D1U1174p._5001UEJSqY:ref

James Matthews

unread,
Aug 22, 2019, 6:55:46 AM8/22/19
to AdWords API and Google Ads API Forum
HI Bharani,

Thanks for the explanation and help. I have had success using  ConstantDataService.getMobileDeviceCriterion()  to get the ids and have been able to add mobile devices to a campaign.
I have a further question. How do i negatively set mobile devices on a campaign. (to exclude these devices from a campaign). The isNegative Field states it is readonly, is there a way to set this?
Currently i can only set a mobile device onto a campaign where isNegative is false. Am i correct in assuming the isNegative field will target these mobiles if false and exclude them if true?

Example of response below showing isNegative as false:

<value>
                   
<campaignId>2087725659</campaignId>
                   
<isNegative>false</isNegative>
                   
<criterion  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MobileDevice">
                       
<id>613251</id>
                       
<type>MOBILE_DEVICE</type>
                       
<Criterion.Type>MobileDevice</Criterion.Type>
                       
<deviceName>8079</deviceName>
                       
<manufacturerName>Alcatel</manufacturerName>
                       
<deviceType>DEVICE_TYPE_TABLET</deviceType>
                       
<operatingSystemName>Android</operatingSystemName>
                   
</criterion>
                   
<campaignCriterionStatus>ACTIVE</campaignCriterionStatus>
                   
<CampaignCriterion.Type>CampaignCriterion</CampaignCriterion.Type>
               
</value>


Kind Regards,
James

Google Ads API Forum Advisor Prod

unread,
Aug 22, 2019, 2:09:12 PM8/22/19
to jpmatth...@gmail.com, adwor...@googlegroups.com
Hello James, 

Your understanding about excluding the criteria is right. You may use the NegativeCampaignCriterion or set the isnegative field to true. However, please note that it is currently not possible to exclude the MobileDevice criteria at the campaign level. The Criteria Usage table will be helpful to identify as to which criteria can be targeted or excluded. 
Reply all
Reply to author
Forward
0 new messages