targeting custom key values in forecast service

157 views
Skip to first unread message

Hassan Khawaja

unread,
Jul 21, 2020, 4:23:05 AM7/21/20
to Google Ad Manager API Forum
Hi there,

Trying to target custom keys while forecasting.

See below the used code and it's error. Please help on this.



$permutive = new CustomCriteria();
        $permutive->setKeyId(intval(11975183));
        $permutive->setOperator(CustomCriteriaComparisonOperator::IS);
        $permutive->setValueIds([30846]);

        // Create ad unit targeting for the root ad unit.
        $networkService = $serviceFactory->createNetworkService($session);
        $rootAdUnitId = $networkService->getCurrentNetwork()
            ->getEffectiveRootAdUnitId();
        $adUnitTargeting = new AdUnitTargeting();
$adUnitTargeting->setAdUnitId("223617791");
        $adUnitTargeting->setIncludeDescendants(true);
$adUnitTargeting2 = new AdUnitTargeting();
$adUnitTargeting2->setAdUnitId("167379791");
        $adUnitTargeting2->setIncludeDescendants(true);
        $inventoryTargeting = new InventoryTargeting();
        $inventoryTargeting->setTargetedAdUnits([$adUnitTargeting,$adUnitTargeting2]);
        $targeting = new Targeting();
        $targeting->setInventoryTargeting($inventoryTargeting);
$targeting->setCustomTargeting($permutive);
        $lineItem->setTargeting($targeting);

Fatal error: Uncaught SoapFault exception: [soap:Client] Unmarshalling Error: cvc-elt.4.3: Type 'ns1:CustomCriteria' is not validly derived from the type definition, 'CustomCriteriaSet', of element 'ns1:customTargeting'. in /home/dmscg/public_html/dmsadops/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php:153 Stack trace: #0 /home/dmscg/public_html/dmsadops/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(153):

Ad Manager API Forum Advisor Prod

unread,
Jul 21, 2020, 5:05:20 AM7/21/20
to hkhawa...@choueirigroup.com, google-doubleclick...@googlegroups.com

Hi Hassan,

 

Thank you for reaching out to us.

 

After investigating, it seems that the error occurs on the following line:

$targeting->setCustomTargeting($permutive);

 

Specifically, the setCustomTargeting takes a CustomCriteriaSet, but the $permutive object is of type CustomCriteria instead. You may check our example code, specifically lines 148-181, for further details on how to correctly use setCustomTargeting.

 

Regards,

Ziv Yves Sanchez, Ad Manager API Team



ref:_00D1U1174p._5004Q22Xna3:ref

Hassan Khawaja

unread,
Jul 21, 2020, 7:57:30 AM7/21/20
to Ad Manager API Forum Advisor Prod, google-doubleclick...@googlegroups.com

Thanks for the reply.

 

Provided examples shows combination of multiple criteria sets (keys). I am still unable to find how to target only one and key and value?

Ad Manager API Forum Advisor Prod

unread,
Jul 21, 2020, 9:17:50 PM7/21/20
to hkhawa...@choueirigroup.com, google-doubleclick...@googlegroups.com

Hi Hassan,

 

Going back to the example code provided in my previous response: you only really need lines 155-158 for the primary CustomCriteriaSet, lines 143-146 to define the CustomCriteria that you wish to target, and finally lines 176-178 to insert this CustomCriteria as a child for the CustomCriteriaSet. The expectation here is that line 177 should only contain one child (which will be the CustomCriteria above).

Ad Manager API Forum Advisor Prod

unread,
Jul 22, 2020, 9:24:26 PM7/22/20
to hkhawa...@choueirigroup.com, google-doubleclick...@googlegroups.com

Hi Hassan,

 

I was able to test the same sample code successfully on my end. Could you kindly provide the details below (via Reply privately to author) so that I can further investigate the issue?

  • Error stack trace

Ad Manager API Forum Advisor Prod

unread,
Jul 23, 2020, 2:39:27 AM7/23/20
to hkhawa...@choueirigroup.com, google-doubleclick...@googlegroups.com

Hi Hassan,

 

Kindly check my answers to your questions below:

  • Can I export forecast report through api? As we do in UI.
    • I'm afraid that there is no forecast export option yet in the Ad Manager API. I can create a feature request for this if you would elaborate on what you wish to see for this feature.
  • How to target geo/OS/device/device capability in api?
Reply all
Reply to author
Forward
0 new messages