Use Facebook ads with your existing customers and to reach new ones. Each guide describes Facebook ads products to help meet your advertising goals. There are several types of ad units with a variety of appearances, placement and creative options. For guidelines on ads units as creative content, see Facebook Ads Guide.
An ad creative is an object that contains all the data for visually rendering the ad itself. In the API, there are different types of ads that you can create on Facebook, all listed here.
If you have a campaign with the Page Post Engagement Objective, you can now create an ad that promotes a post made by the page. This is considered a Page post ad. Page post ads require a field called object_story_id
, which is the id
property of a Page post. Learn more about Ad Creative, Reference.
An ad creative has three parts:
To create the ad creative object, make the following call:
The response to the API call is the id
of the creative object. Store this; you need it for the ad object:
There are limits on the creative's text, image size, image aspect ratio and other aspects of the creative. See the Ads Guide.
In the Ads API, each field you want to retrieve needs to be asked for explicitly, except for id
. Each object's Reference has a section for reading back the object and lists what fields are readable. For the creative, it's the same fields as specified when creating the object, and id
.
A placement is where your ad is shown on Facebook, such as on News Feed on desktop, News Feed on a mobile device or on the right column. See Ads Product Guide.
We encourage you to run ads across the full range of available placements. Facebook’s ad auction is designed to deliver ad impressions to the placement most likely to drive campaign results at the lowest possible cost.
The easiest way to take advantage of this optimization is to leave this field blank. You can also select specific placements in an ad set’s target_spec.
This example has a page post ad. The available placements are Mobile News Feed, Desktop News Feed and Right column of Facebook. In the API, see Placement Options. If you choose desktopfeed
and rightcolumn
as the page_type
, the ad runs on Desktop News Feed and Right column placements. Any ad created below this ad set has only the desktop placement.
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
AdSetFields::NAME => 'Desktop Ad Set',
AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
AdSetFields::DAILY_BUDGET => 10000,
AdSetFields::TARGETING => (new Targeting())->setData(array(
TargetingFields::PUBLISHER_PLATFORMS => array(
'facebook',
'audience_network',
),
TargetingFields::GEO_LOCATIONS => array(
'countries' => array('BR'),
),
)),
AdSetFields::OPTIMIZATION_GOAL =>
AdSetOptimizationGoalValues::POST_ENGAGEMENT,
AdSetFields::BILLING_EVENT => AdSetBillingEventValues::POST_ENGAGEMENT,
AdSetFields::BID_AMOUNT => 1500,
));
$adset->create(array(
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));
from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.targeting import Targeting
adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset[AdSet.Field.name] = 'Desktop Ad Set'
adset[AdSet.Field.campaign_id] = <CAMPAIGN_ID>
adset[AdSet.Field.daily_budget] = 10000
adset[AdSet.Field.targeting] = {
Targeting.Field.publisher_platforms: ['facebook', 'audience_network'],
Targeting.Field.facebook_positions: ['feed'],
Targeting.Field.geo_locations: {
'countries': ['BR'],
},
}
adset[AdSet.Field.optimization_goal] = AdSet.OptimizationGoal.post_engagement
adset[AdSet.Field.billing_event] = AdSet.BillingEvent.post_engagement
adset[AdSet.Field.bid_amount] = 1500
adset.remote_create(params={
'status': AdSet.Status.paused,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
.setName("Desktop Ad Set")
.setCampaignId(<CAMPAIGN_ID>)
.setDailyBudget(10000L)
.setTargeting(
new Targeting()
.setFieldGeoLocations(
new TargetingGeoLocation()
.setFieldCountries(Arrays.asList("BR"))
)
.setFieldPublisherPlatforms(Arrays.asList("facebook", "audience_network"))
)
.setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_POST_ENGAGEMENT)
.setBillingEvent(AdSet.EnumBillingEvent.VALUE_POST_ENGAGEMENT)
.setBidAmount(1500L)
.setStatus(AdSet.EnumStatus.VALUE_PAUSED)
.execute();
String ad_set_id = adSet.getId();
curl \
-F 'name=Desktop Ad Set' \
-F 'campaign_id=<CAMPAIGN_ID>' \
-F 'daily_budget=10000' \
-F 'targeting={
"geo_locations": {"countries":["BR"]},
"publisher_platforms": ["facebook","audience_network"]
}' \
-F 'optimization_goal=POST_ENGAGEMENT' \
-F 'billing_event=POST_ENGAGEMENT' \
-F 'bid_amount=1500' \
-F 'status=PAUSED' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets
We encourage you to run ads across the full range of available placements. Facebook’s ad auction is designed to deliver ad impressions to the placement most likely to drive campaign results at the lowest possible cost.
The easiest way to take advantage of this optimization is to leave this field blank. You can also select specific placements in an ad set’s target_spec.
With the effective placements, you can now determine which placements your ad will deliver based on your ad set's billing_event
, optimization_goal
and promoted_object
as well as your ad campaign's buying_type
and objective
. All parameters for /ad_campaign_placement
include:
account_id
and access tokenbilling_event
, such as IMPRESSIONS
AUCTION
POST_ENGAGEMENT
POST_ENGAGEMENT
PIXEL_ID
All parameters except for promoted_object
and optimization_goal
are required. If you do provide targeting, you can use Marketing API to determine the effective placement based on the ones permitted for your settings, see Effective Placement with Targeting. For example:
curl -G \ -d 'account_id=<ACCOUNT_ID>' \ -d 'billing_event=IMPRESSIONS' \ -d 'buying_type=AUCTION' \ -d 'objective=PAGE_LIKES' \ -d 'optimization_goal=IMPRESSIONS' \ https://graph.facebook.com/<VERSION>/ad_campaign_placement?access_token=<TOKEN>
The call returns:
{ "effective_device_platforms": [ "mobile", "desktop" ], "effective_facebook_positions": [ "feed", "right_hand_column" ], "effective_publisher_platforms": [ "facebook" ], "recommendations": [ { "title": "Placement Not Supported By Objective", "message": "Ads with PAGE_LIKES objective do not support facebook.instant_article, facebook.instream_video, facebook.suggested_video, facebook.marketplace, audience_network.classic, audience_network.instream_video, audience_network.rewarded_video, instagram.stream, instagram.story, messenger.messenger_home.", "code": 1815609, "importance": "LOW", "confidence": "HIGH", "blame_field": "targeting" }, { "title": "Device Platform Not Supported By Objective", "message": "Ads with PAGE_LIKES objective do not support connected_tv.", "code": 1815610, "importance": "LOW", "confidence": "HIGH", "blame_field": "targeting" } ], } }
You can use the code
field from this result in a call to /ad-recommendation
to see a detailed reason. For example, you can get this information:
[{“code”: 1815610, “summary”: “Device Platform Not Supported By Objective”},]
For more information, see Ad Recommendation, Reference and Effective Placement with Targeting.
You preview an ad in one of two ways—with ad preview API or the ad preview plugin.
There are three ways to generate a preview with the API:
Following the reference docs for the preview API, the minimum required API call is:
The creative spec is an array of each field and value required to create the ad creative.
Currently, our ad creative call looks like this:
Take object_story_id
and use it in the preview API call:
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdPreviewFields;
use FacebookAds\Object\Fields\AdCreativeFields;
$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->getGeneratePreviews(array(), array(
AdPreviewFields::CREATIVE => array(
AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
),
AdPreviewFields::AD_FORMAT => '<FORMAT>',
));
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adcreative import AdCreative
account = AdAccount('act_<AD_ACCOUNT_ID>')
params = {
'creative': {
AdCreative.Field.object_story_id: '<POST_ID>',
},
'ad_format': '<FORMAT>',
}
account.get_generate_previews(params=params)
APINodeList<AdPreview> adPreviews = new AdAccount(act_<AD_ACCOUNT_ID>, context).getGeneratePreviews()
.setCreative(
new AdCreative()
.setFieldObjectStoryId(<OBJECT_STORY_ID>)
)
.setAdFormat(<FORMAT>)
.execute();
curl -G \
-d 'creative={"object_story_id":"<POST_ID>"}' \
-d 'ad_format=<FORMAT>' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/generatepreviews
The available values for ad_format
differ a bit from page_types
. But, in this scenario, Desktop News Feed and Right column of Facebook are selected. This requires you to make two API calls to generate the previews for each placement:
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdPreviewFields;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Values\AdPreviewAdFormatValues;
$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->getGeneratePreviews(array(), array(
AdPreviewFields::CREATIVE => array(
AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
),
AdPreviewFields::AD_FORMAT => AdPreviewAdFormatValues::RIGHT_COLUMN_STANDARD,
));
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adpreview import AdPreview
from facebookads.adobjects.adcreative import AdCreative
account = AdAccount('act_<AD_ACCOUNT_ID>')
params = {
'creative': {
AdCreative.Field.object_story_id: '<POST_ID>',
},
'ad_format': AdPreview.AdFormat.right_column_standard,
}
account.get_generate_previews(params=params)
APINodeList<AdPreview> adPreviews = new AdAccount(act_<AD_ACCOUNT_ID>, context).getGeneratePreviews()
.setCreative(
new AdCreative()
.setFieldObjectStoryId(<OBJECT_STORY_ID>)
)
.setAdFormat(AdPreview.EnumAdFormat.VALUE_RIGHT_COLUMN_STANDARD)
.execute();
curl -G \
-d 'creative={"object_story_id":"<POST_ID>"}' \
-d 'ad_format=RIGHT_COLUMN_STANDARD' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/generatepreviews
The response is an iFrame that's valid for 24 hrs.
In July 2018, we deprecated the ability to create a Page Like ad without a page post. If you want to create this type of ad, you should specifically create a post. For example:
curl -X POST \
-F 'name="Creative"' \
-F 'object_story_spec={
"page_id": "<PAGE_ID>",
"link_data": {
"image_hash": "<IMAGE_HASH>",
"link": "https://facebook.com/<PAGE_ID>",
"message": "Creative message",
"call_to_action": {
"type": "LIKE_PAGE",
"value": {
"page": "<PAGE_ID>"
}
}
}
}' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v10.0/act_<AD_ACCOUNT_ID>/adcreatives