googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
288 stars 260 forks source link

I can't uncheck the optional target roas box via the API #974

Closed anasbouzid closed 9 months ago

anasbouzid commented 9 months ago

Your client library and Google Ads API versions:

Your environment:

================= PHP GENERAL INFORMATION phpinfo() PHP Version => 8.1.3

System => Linux homestead 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 Build Date => Feb 21 2022 14:48:42 Build System => Linux Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/8.1/cli Loaded Configuration File => /etc/php/8.1/cli/php.ini Scan this dir for additional .ini files => /etc/php/8.1/cli/conf.d Additional .ini files parsed => /etc/php/8.1/cli/conf.d/10-mysqlnd.ini, /etc/php/8.1/cli/conf.d/10-opcache.ini, /etc/php/8.1/cli/conf.d/10-pdo.ini, /etc/php/8.1/cli/conf.d/15-xml.ini, /etc/php/8.1/cli/conf.d/20-bcmath.ini, /etc/php/8.1/cli/conf.d/20-bz2.ini, /etc/php/8.1/cli/conf.d/20-calendar.ini, /etc/php/8.1/cli/conf.d/20-ctype.ini, /etc/php/8.1/cli/conf.d/20-curl.ini, /etc/php/8.1/cli/conf.d/20-dba.ini, /etc/php/8.1/cli/conf.d/20-dom.ini, /etc/php/8.1/cli/conf.d/20-enchant.ini, /etc/php/8.1/cli/conf.d/20-exif.ini, /etc/php/8.1/cli/conf.d/20-ffi.ini, /etc/php/8.1/cli/conf.d/20-fileinfo.ini, /etc/php/8.1/cli/conf.d/20-ftp.ini, /etc/php/8.1/cli/conf.d/20-gd.ini, /etc/php/8.1/cli/conf.d/20-gettext.ini, /etc/php/8.1/cli/conf.d/20-gmp.ini, /etc/php/8.1/cli/conf.d/20-iconv.ini, /etc/php/8.1/cli/conf.d/20-igbinary.ini, /etc/php/8.1/cli/conf.d/20-imagick.ini, /etc/php/8.1/cli/conf.d/20-imap.ini, /etc/php/8.1/cli/conf.d/20-intl.ini, /etc/php/8.1/cli/conf.d/20-ldap.ini, /etc/php/8.1/cli/conf.d/20-mbstring.ini, /etc/php/8.1/cli/conf.d/20-msgpack.ini, /etc/php/8.1/cli/conf.d/20-mysqli.ini, /etc/php/8.1/cli/conf.d/20-odbc.ini, /etc/php/8.1/cli/conf.d/20-pdo_dblib.ini, /etc/php/8.1/cli/conf.d/20-pdo_mysql.ini, /etc/php/8.1/cli/conf.d/20-pdo_odbc.ini, /etc/php/8.1/cli/conf.d/20-pdo_pgsql.ini, /etc/php/8.1/cli/conf.d/20-pdo_sqlite.ini, /etc/php/8.1/cli/conf.d/20-pgsql.ini, /etc/php/8.1/cli/conf.d/20-phar.ini, /etc/php/8.1/cli/conf.d/20-posix.ini, /etc/php/8.1/cli/conf.d/20-pspell.ini, /etc/php/8.1/cli/conf.d/20-readline.ini, /etc/php/8.1/cli/conf.d/20-redis.ini, /etc/php/8.1/cli/conf.d/20-shmop.ini, /etc/php/8.1/cli/conf.d/20-simplexml.ini, /etc/php/8.1/cli/conf.d/20-snmp.ini, /etc/php/8.1/cli/conf.d/20-soap.ini, /etc/php/8.1/cli/conf.d/20-sockets.ini, /etc/php/8.1/cli/conf.d/20-sqlite3.ini, /etc/php/8.1/cli/conf.d/20-sysvmsg.ini, /etc/php/8.1/cli/conf.d/20-sysvsem.ini, /etc/php/8.1/cli/conf.d/20-sysvshm.ini, /etc/php/8.1/cli/conf.d/20-tidy.ini, /etc/php/8.1/cli/conf.d/20-tokenizer.ini, /etc/php/8.1/cli/conf.d/20-xmlreader.ini, /etc/php/8.1/cli/conf.d/20-xmlrpc.ini, /etc/php/8.1/cli/conf.d/20-xmlwriter.ini, /etc/php/8.1/cli/conf.d/20-xsl.ini, /etc/php/8.1/cli/conf.d/20-zip.ini, /etc/php/8.1/cli/conf.d/25-memcached.ini

PHP API => 20210902 PHP Extension => 20210902 Zend Extension => 420210902 Zend Extension Build => API420210902,NTS PHP Extension Build => API20210902,NTS Debug Build => no Thread Safety => disabled Zend Signal Handling => enabled Zend Memory Manager => enabled Zend Multibyte Support => provided by mbstring IPv6 Support => enabled DTrace Support => available, disabled

Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2, tlsv1.3 Registered Stream Filters => zlib., string.rot13, string.toupper, string.tolower, convert., consumed, dechunk, bzip2., convert.iconv.

This program makes use of the Zend Scripting Language Engine: Zend Engine v4.1.3, Copyright (c) Zend Technologies with Zend OPcache v8.1.3, Copyright (c), by Zend Technologies ================= PHP EXTENSION INFORMATION The PHP Extension grpc is not installed The PHP Extension protobuf is not installed

Description of the bug: I'm trying to set a "Maximize Conversion Value" strategy for a PMax campaign. According to this example, the target_roas is optional, however I can't change the strategy without setting the target_roas to a value greater than 0, same goes for "Maximize Conversion" I must set target_cpa_micros. I need to uncheck the optional target roas box via the API.

Steps to reproduce:

use Google\Ads\GoogleAds\V14\Resources\Campaign;
use Google\Ads\GoogleAds\V14\Common\MaximizeConversionValue;
use Google\Ads\GoogleAds\V14\Services\CampaignOperation;
use Google\Ads\GoogleAds\Util\FieldMasks;

$campaignOperations = [];
$campaignObj = new Campaign([
    'resource_name' => "customers/$accountId/campaigns/$campaignId",
]);
$campaignObj->setMaximizeConversionValue(new MaximizeConversionValue());
$campaignOperations[] = new CampaignOperation([
    'update' => $campaignObj,
    'update_mask' => FieldMasks::allSetFieldsOf($campaignObj)
]);
$campaignServiceClient->mutateCampaigns($accountId, $campaignOperations);

Expected behavior: The code above should uncheck the optional option "Set a target return on ad spend"

Screenshot_20231211_064011

Request/Response Logs: There is no error, the request passes but no changes are made.

Anything else we should know about your project / environment: Everything works if I set target_roas to value greater than 0, but that's not what I need:

$campaignObj->setMaximizeConversionValue(new MaximizeConversionValue([
    'target_roas' => 2
]));
fiboknacky commented 9 months ago

Could you please review this section? In short, there is a limitation that requires you to modify your field mask a bit to clear the field.

anasbouzid commented 9 months ago

This solve the issue, Thank you! I will close the issue but I'm still wondering why the below code doesn't raise the FieldMaskError.FIELD_HAS_SUBFIELDS error, if it did I wouldn't spend hours debugging the problem:

$campaign = new Campaign([
    'resource_name' => ResourceNames::forCampaign($customerId, $campaignId),
    'maximize_conversions' => new MaximizeConversions()
]);
/// ...
fiboknacky commented 9 months ago

Glad that you can resolve the issue now.

As for that error, I'm not entirely sure, but it's the error that is thrown from the server, so there might be some changes on the server side.