Google Ads API is returning to beta status. Please read our blog post for more details.

Generate a Reach Curve

Once you have gathered the targeting settings and a product mix for your media plan, you can generate a curve of budgets versus potential reach using the generateReachForecast method in ReachPlanService. See the glossary and media plan guide for details on the request fields.

The curve includes impression and user reach in absolute numbers, as well as universe sizes corresponding to the census population and YouTube audience size for the requested demographic and country.

Python
def _request_reach_curve(
        client, customer_id, product_mix, location_id, currency_code):
    """Creates a sample request for a given product mix.

    Args:
      client: A google.ads.google_ads.client.GoogleAdsClient instance.
      customer_id: The customer ID for the reach forecast.
      product_mix: The product mix for the reach forecast.
      location_id: Location ID to plan for. You can get a valid loction ID from
        https://developers.google.com/adwords/api/docs/appendix/geotargeting or
        by calling ListPlannableLocations on the ReachPlanService.
      currency_code: Three-character ISO 4217 currency code.
    """
    reach_request = client.get_type('GenerateReachForecastRequest', version='v2')

    reach_request.customer_id = customer_id

    # Valid durations are between 1 and 90 days.
    duration = reach_request.campaign_duration
    duration.duration_in_days.value = 28

    targeting = reach_request.targeting
    targeting.plannable_location_id.value = location_id
    targeting.age_range = client.get_type(
            'ReachPlanAgeRangeEnum', version='v2').AGE_RANGE_18_65_UP

    genders = targeting.genders
    gender_types = [
            client.get_type('GenderTypeEnum', version='v2').FEMALE,
            client.get_type('GenderTypeEnum', version='v2').MALE,
    ]
    for gender_type in gender_types:
        gender = client.get_type('GenderInfo', version='v2')
        gender.type = gender_type
        genders.append(gender)

    devices = targeting.devices
    device_types = [
            client.get_type('DeviceEnum', version='v2').DESKTOP,
            client.get_type('DeviceEnum', version='v2').MOBILE,
            client.get_type('DeviceEnum', version='v2').TABLET,
    ]
    for device_type in device_types:
        device = client.get_type('DeviceInfo', version='v2')
        device.type = device_type
        devices.append(device)

    reach_plan_service = client.get_service('ReachPlanService', version='v2')

    # See the docs for defaults and valid ranges:
    # https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v2.services#google.ads.googleads.v2.services.GenerateReachForecastRequest
    response = reach_plan_service.generate_reach_forecast(
            customer_id=customer_id,
            currency_code=_string_value(client, currency_code),
            campaign_duration=duration,
            cookie_frequency_cap=_int_32_value(client, 0),
            min_effective_frequency=_int_32_value(client, 1),
            targeting=targeting,
            planned_products=product_mix
    )

    print('Currency, Cost, On-Target Reach, On-Target Imprs, Total Reach,'
          ' Total Imprs, Products')
    for point in response.reach_curve.reach_forecasts:
        product_splits = []
        for p in point.forecasted_product_allocations:
            product_splits.append({
                    p.plannable_product_code.value:
                        p.budget_micros.value / ONE_MILLION})
        print([
                currency_code,
                point.cost_micros.value / ONE_MILLION,
                point.forecast.on_target_reach.value,
                point.forecast.on_target_impressions.value,
                point.forecast.total_reach.value,
                point.forecast.total_impressions.value,
                product_splits])