getMetrics() result does not yield for all keywords

104 views
Skip to first unread message

Alexander Orlov

unread,
May 8, 2022, 10:10:57 AM5/8/22
to Google Ads API and AdWords API Forum
Hi all! 
(As usual) I'm working on migrating AdWords API to Ads API. 
The use case is the following: 

Feed an amount of keywords (paginating them by keyword plans a 10k) to generateHistoricalMetrics($keywordPlanResource) and collect the results.

To achieve this I followed rather closely the instructions at 
and especially 
using KeywordPlanAdGroupKeywords (with a single ad group)
and avoiding to pass a specific date range for now, relying on the default value. 

I had to apply some filters on my keywords because of KEYWORD_HAS_INVALID_CHARS and KEYWORD_TEXT_TOO_LONG, but all the errors which I'm aware of are gone now. 

Now, I found out, that the KeywordPlanHistoricalMetrics object does not contain any keyword id (of the form customers/*/keywordPlanAdGroupKeywords/*) So, I have to rely on the correct ordering. This is ok as it seems, that the original ordering of keywords is preserved within the results. 

But still I have the problem, that 

count($keywordPlanServiceClient->generateHistoricalMetrics($keywordPlanResource)->getMetrics()) < count($passedKeywords)

where each of $passedKeywords where passed to 

new KeywordPlanAdGroupKeyword([
'text' => $passedKeyword,
'match_type' => KeywordMatchType::EXACT
'keyword_plan_ad_group' => $planAdGroupResource
]);

So I have two questions here: 

1. Why getMetrics() does not yield the same amount of results as the amount of passed keywords?

2. I'm struggling with debugging at this moment: Say, I want to know which keywords are let out. Either for providing more information at this place or just to skip them, and let my customer know, that these particular keywords were not queried. How to do this, when although I have a keyword-id for every passed keyword I cannot match the returned metrics to them, because the KeywordPlanHistoricalMetrics object does not contain any keyword id. 


Cheers and thanks in advance 

Alex

Alexander Orlov

unread,
May 9, 2022, 3:11:24 AM5/9/22
to Google Ads API and AdWords API Forum
found something new. 
If I reduce the pagination number, the number of lost results reduces as well. Roughly the distribution follows 

plot points[(10000, 4.72),(5000, 2.12),(2500, .78),(1250, .43),(625, .30),(500, .24),(250, .03),(200,0.03)]

(via WolframAlpha), where the y-axis is in percent and the x-axis is the pagination number. 

The idea comes into my mind because of the RECOMMENDED_PAGE_SIZE parameter, used in AdWords API. However, both of the questions above remains:
1. Why getMetrics() loose results? 
2. How to find out, which keywords exactly were omitted during processing? and now
3. Is reducing the number of keywords/plan a valid workaround or do I miss something here? At least the documentation states, the amount of keywords per plan allowed is 10000. 

Google Ads API Forum Advisor

unread,
May 10, 2022, 2:45:06 PM5/10/22
to sascha...@gmail.com, adwor...@googlegroups.com
Hi Alexander,

Thanks for reaching out. Can you please try generating metrics for a list of keywords in version 10.1? In this version, you are not required to pass a keyword plan, keyword plan campaign, or ad group. 

If you continue to see the issue where you are not receiving metrics for each listed keyword, can you please privately provide us with the complete request and response logs?

Regards,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aqoWc:ref

Alexander Orlov

unread,
May 11, 2022, 7:39:33 AM5/11/22
to Google Ads API and AdWords API Forum
Thanks a lot for the answer and especially for hinting to the new version. Historical metrics include now more fields I need. 

I was able however to already solve my problem: 
Some of the missing keywords were hiding in close_variants and some others were added (unexpectedly) to the original list, which I passed. Though, with some array_diffs I was able to find all (!) missed (and new) keywords. 
Thanks again for your efforts. 

Google Ads API Forum Advisor

unread,
May 11, 2022, 8:57:46 AM5/11/22
to sascha...@gmail.com, adwor...@googlegroups.com

Hi Alexander,

Thanks for confirming that you are able to already solve the problem using v10.1. Should you have additional clarifications with the APIs, you may open a new thread, and we'll be happy to assist you.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aqoWc:ref

Alexander Orlov

unread,
May 11, 2022, 1:02:12 PM5/11/22
to Google Ads API and AdWords API Forum
In version 10.1 for the request of KeywordPlanIdeaService.GenerateKeywordHistoricalMetrics how to set e.g. a language and geoConstants?

Best regards
Alex

Google Ads API Forum Advisor

unread,
May 11, 2022, 10:30:36 PM5/11/22
to sascha...@gmail.com, adwor...@googlegroups.com
Hi Alexander,

Thank you for your reply.

You can refer to the example from this guide as it provides details on how to include geo targets as well as language constants, in your keyword plan. I hope this helps.

Best regards,

Google Logo
Peter Laurence
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aqoWc:ref

Alexander Orlov

unread,
May 12, 2022, 2:55:24 AM5/12/22
to Google Ads API and AdWords API Forum
Not really: In version 10.1 KeywordPlanIdeaService.GenerateKeywordHistoricalMetrics is meant to be used without creating a Keyplan, Campaign, Adgroups or the like. 
However, your link leads exactly to the description I found also before.
Does this mean, specifying the context of a language and geolocations still needs the creation of the overhead objects? 
Best regards
Alex

Google Ads API Forum Advisor

unread,
May 17, 2022, 12:19:57 AM5/17/22
to sascha...@gmail.com, adwor...@googlegroups.com
Hi Alex,

Thank you for the reply. I am also a member of the Google Ads API team and let me provide support to your concern.

Could you confirm if my understanding is correct that you want to set geo targets and language directly at the KeywordPlanIdeaService.GenerateKeywordHistoricalMetrics? If yes, then to answer your question, this is not possible as you will need to create entities using the KeywordPlanCampaign where you can set location and the language to target. I would suggest to continue following this guide as it provides there the instruction on how to generate historical metrics using Google Ads API.

Let me know if you have further questions.

Regards,
Google Logo
Ernie John
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aqoWc:ref
Reply all
Reply to author
Forward
Message has been deleted
0 new messages