Search code examples
pythonfacebookfacebook-ads-apifacebook-marketing-api

Facebook ad budget estimate (reach estimate cpm)


I've been tasked with finding out how to use the Facebook ads api to get budget estimates for reaching a particular audience. I believe I'm looking for the estimated daily reach or possibly the delivery estimate. I'm looking for a response something like this one from here:

"data": {
      "users": 14600000,
      "bid_estimations": [
         {
            "unsupported": false,
            "location": 3,
            "cpa_min": 79,
            "cpa_median": 145,
            "cpa_max": 195,
            "cpc_min": 45,
            "cpc_median": 70,
            "cpc_max": 87,
            "cpm_min": 8,
            "cpm_median": 20,
            "cpm_max": 27
         }
      ],
      "estimate_ready": true
   }
}

My code so far:

with open('secrets.json') as f:
    secrets = json.load(f)

FacebookAdsApi.init(
    secrets['app_id'],
    secrets['app_secret'],
    secrets['access_token']
)

me = AdAccountUser(fbid='me')

my_account = me.get_ad_account()

targeting_spec = {
    'geo_locations':{
        'countries':['US'],
    },
    'age_min': 20,
    'age_max': 40,
}

promoted_object = {
    'application_id':   secrets['app_id'],
    'page_id':          secrets['page_id']
}

params = {
    'promoted_object': promoted_object,
    'optimize_for': AdSet.OptimizationGoal.offsite_conversions,
    'targeting_spec': targeting_spec,
}

account_reach_estimate = my_account.get_reach_estimate(params=params)
print(account_reach_estimate)

But I am getting the following response which is lacking the bid estimations:

[<ReachEstimate> {
    "estimate_ready": true,
    "users": 128000000
}]

In summary I am looking for CPM bid estimate from reachestimate but it is not being returned.


Solution

  • The examples of Ad Account Reachestimate seem to show the result you are getting. Using Ad Account Delivery Estimate instead gives a response with bid_estimate:

    account_delivery_estimate = my_account.get_delivery_estimate(params=params)
    

    Results in:

    [<AdAccountDeliveryEstimate> {
        "bid_estimate": {
            "max_bid": 1998,
            "median_bid": 1536,
            "min_bid": 1242
        },
        "daily_outcomes_curve": [
            {
                "actions": 0,
                "impressions": 0,
                "reach": 0,
                "spend": 0
            }
        ],
        "estimate_dau": 75052199,
        "estimate_mau": 129000000,
        "estimate_ready": true
    }]