KeywordPlanKeywordForecast will be removed. What is the alternative?

177 views
Skip to first unread message

dimitris pfx

unread,
May 12, 2023, 9:48:58 AM5/12/23
to Google Ads API and AdWords API Forum
Hello,

We are using the KeywordPlanKeywordForecast in our applications, but according to the announcement the KeywordPlanKeywordForecast will be removed. What is the alternative for this?

Thanks in advance

Google Ads API Forum Advisor

unread,
May 12, 2023, 3:32:00 PM5/12/23
to teamp...@gmail.com, adwor...@googlegroups.com

Hello,

Thanks for reaching out to the Google Ads API Team.

Based on the blog post (https://ads-developers.googleblog.com/2023/04/ad-group-and-keyword-forecasts-being.html), Ad group and keyword forecasts are being removed in the Google Ads API. With this, I'm afraid that there's no alternative for these features. You will need to update your application to handle empty values for these fields.

We highly suggest that you start updating your applications as soon as possible. You can find more information about how to use KeywordPlanCampaignForecast in the Google Ads API documentation via this link (https://developers.google.com/google-ads/api/docs/keyword-planning/generate-forecast-metrics).


Regards,

Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2lHJWr:ref

dimitris pfx

unread,
May 15, 2023, 11:42:08 AM5/15/23
to Google Ads API and AdWords API Forum
Hello,

Thank you for your quick response. If I understand this correctly, this feature will remain on the Google Ads UI (as shown in the image below) but it will be removed from the Google Ads API. Is that correct?

keyword_planner.png

Regards

Google Ads API Forum Advisor

unread,
May 16, 2023, 3:02:13 AM5/16/23
to teamp...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for the reply. 

Unfortunately, our team does not comment on any Ads UI features or its deprecation as the appropriate team such questions is the Google Ads Product support team(https://support.google.com/google-ads/gethelp). However, as mentioned in the above post, Ad group and keyword forecasts are being removed in the Google Ads API. Let us know if you have further questions.

Best regards,

dimitris pfx

unread,
May 17, 2023, 9:33:49 AM5/17/23
to Google Ads API and AdWords API Forum
Hi again,

Thanks for your reply. According to the documentation you shared the keyword forecasts seem to be available, but the documentation does not mention if this functionality is going to end after the 1st of June 2023. In order to clarify this, I have created the below Python script, can you please verify if the script is going to continue to provide the forecasts after the deprecation of the 1st of June 2023?

Thanks in advance


from google.ads.googleads.client import GoogleAdsClient
import os
import uuid
from time import sleep


def print_forecasts(googleads_client, keyword_plans):
    keywords_forecasts = []
    keyword_plan_service = googleads_client.get_service("KeywordPlanService")
    for keyword_plan in keyword_plans:
        broad_keyword_plan = keyword_plan["broad_keyword_plan"]
        exact_keyword_plan = keyword_plan["exact_keyword_plan"]
        broad_response = keyword_plan_service.generate_forecast_metrics(
            keyword_plan=broad_keyword_plan
        )
        sleep(5)
        exact_response = keyword_plan_service.generate_forecast_metrics(
            keyword_plan=exact_keyword_plan
        )
        keywords_forecasts.append({
            "keywordText": keyword_plan["keyword"],
            "broad_response": broad_response,
            "exact_response": exact_response,
        })

    for keyword in keywords_forecasts:
        print(f"Keyword: {keyword['keywordText']}")
        # BROAD
        for broad_forecast in keyword["broad_response"].keyword_forecasts:
            metrics = broad_forecast.keyword_forecast

            click_val = metrics.clicks
            clicks = f"{click_val:.2f}" if click_val else "unspecified"
            print(f"Broad Estimated total clicks: {clicks}")

            imp_val = metrics.impressions
            impressions = f"{imp_val:.2f}" if imp_val else "unspecified"
            print(f"Broad Estimated total impressions: {impressions}")

            cpc_val = metrics.average_cpc
            cpc = f"{cpc_val:.2f}" if cpc_val else "unspecified"
            print(f"Broad Estimated average cpc: {cpc}\n")
        # EXACT
        for exact_forecast in keyword["exact_response"].keyword_forecasts:
            metrics = exact_forecast.keyword_forecast

            click_val = metrics.clicks
            clicks = f"{click_val:.2f}" if click_val else "unspecified"
            print(f"Exact Estimated total clicks: {clicks}")

            imp_val = metrics.impressions
            impressions = f"{imp_val:.2f}" if imp_val else "unspecified"
            print(f"Exact Estimated total impressions: {impressions}")

            cpc_val = metrics.average_cpc
            cpc = f"{cpc_val:.2f}" if cpc_val else "unspecified"
            print(f"Exact Estimated average cpc: {cpc}\n")


def main_keyword_plans(
    googleads_client,
    keywords,
    geoTarget: int,
    languageConst: int,
    customer_id: str,
):
    keyword_plans = []
    for keyword in keywords:
        broad_keyword_plan = _add_keyword_plan(
            googleads_client, keywords, "BROAD", geoTarget, languageConst, customer_id
        )
        exact_keyword_plan = _add_keyword_plan(
            googleads_client, keywords, "EXACT", geoTarget, languageConst, customer_id
        )
        keyword_plans.append({
            "keyword": keyword,
            "broad_keyword_plan": broad_keyword_plan,
            "exact_keyword_plan": exact_keyword_plan
        })
    return keyword_plans


def _add_keyword_plan(
    googleads_client,
    keywords,
    matchType: str,
    geoTarget: int,
    languageConst: int,
    customer_id: str,
):
    keyword_plan = _create_keyword_plan(googleads_client, customer_id)
    keyword_plan_campaign = _create_keyword_plan_campaign(
        googleads_client, customer_id, keyword_plan, geoTarget, languageConst
    )
    keyword_plan_ad_group = _create_keyword_plan_ad_group(
        googleads_client, customer_id, keyword_plan_campaign
    )
    _create_keyword_plan_ad_group_keywords(
        googleads_client, customer_id, keyword_plan_ad_group, keywords, matchType
    )

    return keyword_plan


def _create_keyword_plan(googleads_client, customer_id):
    keyword_plan_service = googleads_client.get_service("KeywordPlanService")

    operation = googleads_client.get_type("KeywordPlanOperation")
    keyword_plan = operation.create

    keyword_plan.name = f"Keyword plan for traffic estimate {uuid.uuid4()}"

    forecast_interval = googleads_client.get_type(
        "KeywordPlanForecastIntervalEnum"
    ).KeywordPlanForecastInterval.NEXT_QUARTER
    keyword_plan.forecast_period.date_interval = forecast_interval

    response = keyword_plan_service.mutate_keyword_plans(
        customer_id=customer_id, operations=[operation]
    )
    global resource_name
    resource_name = response.results[0].resource_name

    return resource_name


def _create_keyword_plan_campaign(
    googleads_client,
    customer_id,
    keyword_plan,
    geoTarget: int,
    languageConst: int,
    cpc_bid: int = 86_000_000
):
    keyword_plan_campaign_service = googleads_client.get_service(
        "KeywordPlanCampaignService"
    )
    operation = googleads_client.get_type("KeywordPlanCampaignOperation")
    keyword_plan_campaign = operation.create

    keyword_plan_campaign.name = f"Keyword plan campaign {uuid.uuid4()}"
    keyword_plan_campaign.cpc_bid_micros = cpc_bid
    keyword_plan_campaign.keyword_plan = keyword_plan

    network = googleads_client.get_type(
        "KeywordPlanNetworkEnum"
    ).KeywordPlanNetwork.GOOGLE_SEARCH
    keyword_plan_campaign.keyword_plan_network = network

    geo_target = googleads_client.get_type("KeywordPlanGeoTarget")
    geo_target.geo_target_constant = f"geoTargetConstants/{geoTarget}"

    keyword_plan_campaign.geo_targets.append(geo_target)

    # Constant for English
    language = f"languageConstants/{languageConst}"
    keyword_plan_campaign.language_constants.append(language)

    response = keyword_plan_campaign_service.mutate_keyword_plan_campaigns(
        customer_id=customer_id, operations=[operation]
    )

    resource_name = response.results[0].resource_name

    return resource_name


def _create_keyword_plan_ad_group(googleads_client, customer_id, keyword_plan_campaign, cpc_bid: int = 86_000_000):
    operation = googleads_client.get_type("KeywordPlanAdGroupOperation")
    keyword_plan_ad_group = operation.create

    keyword_plan_ad_group.name = f"Keyword plan ad group {uuid.uuid4()}"
    keyword_plan_ad_group.cpc_bid_micros = cpc_bid
    keyword_plan_ad_group.keyword_plan_campaign = keyword_plan_campaign

    keyword_plan_ad_group_service = googleads_client.get_service(
        "KeywordPlanAdGroupService"
    )
    response = keyword_plan_ad_group_service.mutate_keyword_plan_ad_groups(
        customer_id=customer_id, operations=[operation]
    )

    resource_name = response.results[0].resource_name

    return resource_name


def _create_keyword_plan_ad_group_keywords(
    googleads_client, customer_id, plan_ad_group, keywords, matchType: str, cpc_bid: int = 86_000_000
):
    keyword_plan_ad_group_keyword_service = googleads_client.get_service(
        "KeywordPlanAdGroupKeywordService"
    )
    operations = []

    for i, keyword in enumerate(keywords):

        operation = googleads_client.get_type("KeywordPlanAdGroupKeywordOperation")
        globals()[f"keyword_plan_ad_group_keyword{i}"] = operation.create
        globals()[f"keyword_plan_ad_group_keyword{i}"].text = keyword
        globals()[f"keyword_plan_ad_group_keyword{i}"].cpc_bid_micros = cpc_bid

        if matchType == "EXACT":
            globals()[
                f"keyword_plan_ad_group_keyword{i}"
            ].match_type = googleads_client.get_type(
                "KeywordMatchTypeEnum"
            ).KeywordMatchType.EXACT
        elif matchType == "BROAD":
            globals()[
                f"keyword_plan_ad_group_keyword{i}"
            ].match_type = googleads_client.get_type(
                "KeywordMatchTypeEnum"
            ).KeywordMatchType.BROAD
        else:
            globals()[
                f"keyword_plan_ad_group_keyword{i}"
            ].match_type = googleads_client.get_type(
                "KeywordMatchTypeEnum"
            ).KeywordMatchType.PHRASE
        globals()[
            f"keyword_plan_ad_group_keyword{i}"
        ].keyword_plan_ad_group = plan_ad_group
        operations.append(operation)
    # todo:verify the order of the response is aligned with order of the list
    response = (
        keyword_plan_ad_group_keyword_service.mutate_keyword_plan_ad_group_keywords(
            customer_id=customer_id, operations=operations
        )
    )


def main():
    # This is a static example with values
    gads_credentials = {
        "developer_token": os.getenv("GOOGLE_ADS_DEVELOPER_TOKEN"),
        "refresh_token": os.getenv("GOOGLE_ADS_REFRESH_TOKEN"),
        "client_id": os.getenv("GOOGLE_ADS_CLIENT_ID"),
        "client_secret": os.getenv("GOOGLE_ADS_CLIENT_SECRET"),
        "login_customer_id": os.getenv("GADS_CUSTOMERID"),
        "use_proto_plus": True,
    }
    googleads_client = GoogleAdsClient.load_from_dict(
        config_dict=gads_credentials, version="v13"
    )
    keywords = ["tofu", "vegan"]
    geo_target = 2826
    language_const = 1000
    customer_id = "XXXXXXXXXX"

    # start keyword plans
    keyword_plans = main_keyword_plans(
        googleads_client, keywords, geo_target, language_const, customer_id
    )

    # extract keyword forecasts
    print_forecasts(googleads_client, keyword_plans)


if __name__ == "__main__":
    main()

Google Ads API Forum Advisor

unread,
May 18, 2023, 6:40:58 AM5/18/23
to teamp...@gmail.com, adwor...@googlegroups.com
Hi Dimitris,

Thank you for getting back to us. I hope that you are doing well today.

I understand your concern, however, as mentioned on the blog post "If you are using KeywordPlanAdGroupForecast or KeywordPlanKeywordForecast in your applications, update your applications to ensure that they can handle blank responses.". Therefore, if you use KeywordPlanAdgroupForecast or KeyPlanKeywordForecast, you will get an empty response and this will be effective on June 1, 2023.

Therefore, as suggested in the blog, We recommend that you start updating your applications as soon as possible. You can find more information about how to use KeywordPlanCampaignForecast here https://developers.google.com/google-ads/api/docs/keyword-planning/generate-forecast-metrics.

Reference links:
I hope this clarifies but if you have other questions, please let us know and we will be happy to assist you.

Kind regards,
Reply all
Reply to author
Forward
0 new messages