Retrieving historical CPC values from Google Ads Api

580 views
Skip to first unread message

Martino Anzi

unread,
Apr 27, 2022, 7:53:24 AM4/27/22
to Google Ads API and AdWords API Forum
I am trying to get historical, monthly CPC values from a keyword plan.

As per https://developers.google.com/google-ads/api/reference/rpc/v10/KeywordPlanHistoricalMetrics, I am using the following code to attempt retrieving the information:

Code:
keyword_plan_service = client.get_service("KeywordPlanService")
metric_request = client.get_type("GenerateHistoricalMetricsRequest")
resource_name = keyword_plan_service.keyword_plan_path(customer_id, keyword_plan_id)
metric_request.keyword_plan=resource_name
metric_request.historical_metrics_options.year_month_range.start.year=2019
metric_request.historical_metrics_options.year_month_range.start.month=client.get_type("MonthOfYearEnum").MonthOfYear.JANUARY
metric_request.historical_metrics_options.year_month_range.end.year=2021
metric_request.historical_metrics_options.year_month_range.end.month=client.get_type("MonthOfYearEnum").MonthOfYear.MAY
response = keyword_plan_service.generate_historical_metrics(metric_request)
print(response)

Changing the period start and end related time variables, inherent monthly volumes are returned, but low_top_of_page_bid_micros and high_top_of_page_bid_micros aggregates remain the same (independently from the time period requested).

I assume the values are always referring to last 12 months, and I wonder if there is a way to request the cpc estimates for a specific time period instead.

Google Ads API Forum Advisor

unread,
Apr 28, 2022, 9:55:28 AM4/28/22
to arg3...@gmail.com, adwor...@googlegroups.com
Hi Martino,

Thanks for reaching out. I understand that you are finding that setting the year_month_range does have an impact on page bids. Can you please privately provide us with the complete request and response logs so that we can confirm?

Thanks,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5004Q2aO3QK:ref

Martino Anzi

unread,
Apr 29, 2022, 7:32:04 AM4/29/22
to Google Ads API and AdWords API Forum
Hi Matt,

I've tried retrieving the historical values from both "KeywordPlanService" and "KeywordPlanIdeaService" leading to the same result (cpc values seem to always be the same no matter the period requested).

I am sharing here the example for "KeywordPlanService" only, as the requests sent and responses returned seem to be the same (in case I am wrong, I can share another example using the "KeywordPlanIdeaService").

As seen in the responses, the returned monthly_search_volumes do refer to the requested period, but competition metrics such as low_top_of_page_bid_micros and high_top_of_page_bid_micros always stay the same.

Though I am still not certain this isn't due to the keywords mantaining the same cpc values throughout the entire year, I've tested a dozen keywords and observed they all return unchanging competition metrics.

Is this because competition metrics are always aggregated to the last 12 months? I couldn't find an explicit indication about this in the documentation.

Thanks,
Martino

Code:
```
from google.ads.googleads.client import GoogleAdsClient

def test(client, customer_id, keyword_plan_id):
    keyword_plan_service = client.get_service("KeywordPlanService")
    metric_request = client.get_type("GenerateHistoricalMetricsRequest")
    resource_name = keyword_plan_service.keyword_plan_path(customer_id, keyword_plan_id)
    metric_request.keyword_plan=resource_name
    metric_request.historical_metrics_options.year_month_range.start.year=2021
    metric_request.historical_metrics_options.year_month_range.start.month=client.get_type("MonthOfYearEnum").MonthOfYear.JANUARY
    metric_request.historical_metrics_options.year_month_range.end.year=2021
    metric_request.historical_metrics_options.year_month_range.end.month=client.get_type("MonthOfYearEnum").MonthOfYear.FEBRUARY
    response = keyword_plan_service.generate_historical_metrics(metric_request)
    print(response)

client = GoogleAdsClient.load_from_storage('./google-ads.yaml', version="v10")
test(client, CUSTOMER_ID, KEYWORD_PLAN_ID)
```

Responses:
2021 JAN to 2021 FEB returns:
```
metrics {
  keyword_metrics {
    competition: MEDIUM
    monthly_search_volumes {
      month: JANUARY
      year: 2021
      monthly_searches: 18100
    }
    monthly_search_volumes {
      month: FEBRUARY
      year: 2021
      monthly_searches: 18100
    }
    avg_monthly_searches: 33100
    competition_index: 55
    low_top_of_page_bid_micros: 713887
    high_top_of_page_bid_micros: 3617029
  }
  search_query: "cheap cruise"
}
```

2022 JAN to 2022 FEB returns:
```
metrics {
  keyword_metrics {
    competition: MEDIUM
    monthly_search_volumes {
      month: JANUARY
      year: 2022
      monthly_searches: 33100
    }
    monthly_search_volumes {
      month: FEBRUARY
      year: 2022
      monthly_searches: 40500
    }
    avg_monthly_searches: 33100
    competition_index: 55
    low_top_of_page_bid_micros: 713887
    high_top_of_page_bid_micros: 3617029
  }
  search_query: "cheap cruise"
}
```

Google Ads API Forum Advisor

unread,
May 2, 2022, 11:15:52 AM5/2/22
to arg3...@gmail.com, adwor...@googlegroups.com
Hi Martino,

Thanks for providing some additional information. However, could you please privately provide us with the complete request and response? The request and response will look similar to the JSON mappings found on this page.

You can reply to us privately by clicking the dropdown button on this post, and selecting 'reply privately to author'.
Reply all
Reply to author
Forward
0 new messages