PHP Get First Page Cpc Micros

193 views
Skip to first unread message

ma...@sumer.me

unread,
Apr 12, 2022, 11:53:22 AM4/12/22
to Google Ads API and AdWords API Forum
I am using Google Ads API V10 PHP Libray. I'm trying to get the "ad_group_criterion.position_estimates.first_page_cpc_micros," metric. But I am getting null error. Where am I doing wrong?

Sample Query:
SELECT campaign.id, campaign.name, ad_group_criterion.keyword.text, ad_group_criterion.position_estimates.first_page_cpc_micros FROM keyword_view

PHP Sample:
$campaign_id = $googleAdsRow->getCampaign()->getId();
$campaign_name = $googleAdsRow->getCampaign()->getName();
$keyword = $googleAdsRow->getAdGroupCriterion()->getKeyword()->getText();
$first_page_cpc = $googleAdsRow->getAdGroupCriterion()->getPositionEstimates()->getFirstPageCpcMicros();

Error:
Fatal error: Uncaught Error: Call to a member function getFirstPageCpcMicros() on null in...

Google Ads API Forum Advisor

unread,
Apr 12, 2022, 10:38:03 PM4/12/22
to ma...@sumer.me, adwor...@googlegroups.com
Hi Mahir,

Thank you for raising this concern to the Google Ads API team.

With regard to your concern, as you mentioned, you are using the PHP client library. That said, I would suggest reaching out to the PHP client library owner via this Issue Tab for them to provide guidance on how to address this issue.

Regards,
Google Logo
Carmela
Google Ads API Team
 


ref:_00D1U1174p._5004Q2a2Tfz:ref

Shobha Solanki

unread,
Jun 30, 2022, 6:24:30 AM6/30/22
to Google Ads API and AdWords API Forum
Hi,

When we fetch the 
ad_group_criterion.position_estimates.first_page_cpc_micros we are also getting the same error, can you please let us know how do we fetch the value as it is important. Is there some alternate way.

Thanks,
Shobha

Google Ads API Forum Advisor

unread,
Jun 30, 2022, 7:44:55 AM6/30/22
to shobha....@gmail.com, adwor...@googlegroups.com

Hi Shobha,

Thank you for that information.

To help you with your further, could you please provide the complete request and response logs, with the request-id? If you haven't 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.You can provide it via Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead. Let me know if you have any questions.


Best,

Google Logo
Anthony Cyril
Google Ads API Team
 


ref:_00D1U1174p._5004Q2a2Tfz:ref

Anil

unread,
Jul 7, 2022, 4:50:27 AM7/7/22
to Google Ads API and AdWords API Forum
Hello Anthony,

Attached is the log with the request Id

[2022-07-06T13:48:09.967873+01:00] google-ads.INFO: Request made: Host: "googleads.googleapis.com", Method: "/google.ads.googleads.v10.services.GoogleAdsService/Search", CustomerId: 3087510920, RequestId: "ALPK8bpVCLadrFjySei31A", IsFault: 0, FaultMessage: "None"
Fatal error:  Uncaught Error: Call to a member function getFirstPageCpcMicros() on null in /var/www/sites/psmedia/perfectstormmedia/tools/class/AdWordsAPI.class.php:5626
Stack trace:
#0 /var/www/sites/psmedia/perfectstormmedia/tools/bids/class/GoogleBidsTool.class.php(331): AdWordsAPI->getReport(Array)
#1 /var/www/sites/psmedia/perfectstormmedia/tools/bids/class/GoogleBidsTool.class.php(253): GoogleBidsTool->getSearchCampaignsReport()
#2 /var/www/sites/psmedia/perfectstormmedia/tools/bids/bidsCron.php(241): GoogleBidsTool->Keyword_Report(1)
#3 {main}
  thrown in /var/www/sites/psmedia/perfectstormmedia/tools/class/AdWordsAPI.class.php on line 5626

Thanks,
Shobha

Google Ads API Forum Advisor

unread,
Jul 7, 2022, 9:20:48 AM7/7/22
to anilv.pr...@gmail.com, adwor...@googlegroups.com

Hi Shobha,

Thanks for getting back to us.

I can see that your GAQL is valid, however, your PHP code throws the Fatal error:  Uncaught Error: Call to a member function getFirstPageCpcMicros(). This seems to be more related to PHP code implementation.

You may refer to this PHP client library hosted at GitHub, and this PHP reporting example on how you can get report data on your end. If you’re using a PHP client library and still encountering said Fatal error, then I recommend you to reach out to PHP client library owners by opening a new issue with their team via issue tracker, for further assistance. 

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2a2Tfz:ref

ma...@sumer.me

unread,
Apr 4, 2023, 8:48:16 AM4/4/23
to Google Ads API and AdWords API Forum
This problem still continues with V13

I do not receive errors when I use a code sample like below. But in this case, I can't get all the words.

SELECT metrics.clicks, metrics.impressions, ad_group_criterion.position_estimates.first_page_cpc_micros FROM keyword_view WHERE campaign.id="XXXXXX" AND ad_group.id="YYYYYY" AND ad_group_criterion.position_estimates.first_page_cpc_micros > 0

I want to take all the words and not to get errors. (Only with 1 query) how to do this?

Error: Fatal error: Uncaught Error: Call to a member function getFirstPageCpcMicros() on null in...

Google Ads API Forum Advisor

unread,
Apr 4, 2023, 12:54:33 PM4/4/23
to ma...@sumer.me, adwor...@googlegroups.com

Hello,

Thank you for getting back to us.

I understand that in this case, with your current query, you want to obtain keyword. I can see that the in the query “ad_group_criterion.keyword.text” is not present in the Select clause.

Please try using the sample query and substituting some of the values for the WHERE clause to see if you will get your expected data:

SELECT
metrics.clicks,
metrics.impressions,
ad_group_criterion.keyword.text,
ad_group_criterion.position_estimates.first_page_cpc_micros
FROM keyword_view
WHERE
campaign.id="XXXXXX" AND
ad_group.id="YYYYYY" AND
ad_group_criterion.position_estimates.first_page_cpc_micros > 0


Please let me know how it goes.

Regards,

Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2a2Tfz:ref

ma...@sumer.me

unread,
Apr 5, 2023, 3:33:44 AM4/5/23
to Google Ads API and AdWords API Forum
I think you misunderstood me. My problem is:

If I don't use this with WHERE ad_group_criterion.position_estimates.first_page_cpc_micros > 0, PHP returns "null" for some words and gives a Fatal Error and the process is interrupted.

ad_group_criterion.position_estimates.first_page_cpc_micros > 0 when I use this, I don't get all the words either. In other words, I need to do 2 actions to get all the words in the ad group in that campaign.

How can I get all the words without getting a Fatal Error?



Google Ads API Forum Advisor

unread,
Apr 5, 2023, 7:48:09 AM4/5/23
to ma...@sumer.me, adwor...@googlegroups.com
Hello,

Thank you for getting back to us.

The reason why you're not getting all keywords when using the condition ad_group_criterion.position_estimates.first_page_cpc_micros > 0 is because this condition will not return first_page_cpc_micros that is equal to 0. As per the FATAL error due to null value, what we can suggest is you may put conditions in place in your PHP code to handle null values in the event they are indeed returned.
Reply all
Reply to author
Forward
0 new messages