Dynamic Ads for Lead Generation

Generate leads with your Dynamic Ads. If you have a product catalog ready and run Dynamic Ads you can now collect leads with your ads on Facebook. Facebook selects the most relevant items in your product set, as we with all Dynamic Ads, and display a lead gen form when someone clicks and item.

When you download leads via API or as a file, we include retailer_item_id. This indicates which items someone clicked on and submitted their lead information for.

Creating Dynamic Ads for Lead Generation

Create a campaign with the objective as lead_generation.

use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\CampaignObjectiveValues;

$campaign = new Campaign(null, 'act_<AD_ACCOUNT_ID>');
  CampaignFields::NAME => 'Lead generation campaign',
  CampaignFields::OBJECTIVE => CampaignObjectiveValues::LEAD_GENERATION,

curl \
  -F 'name=Lead generation campaign' \
  -F 'objective=LEAD_GENERATION' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \

This returns a campaign_id you use for your ad set.

As in all Dynamic Ads, you must specify product_set_id in promoted_object for your ad set. This enables you to advertise products from that set. For lead generation, set optimization_goal to lead_generation:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');

  AdSetFields::NAME => 'Product Catalog Sales Adset',
  AdSetFields::BID_AMOUNT => 3000,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::DAILY_BUDGET => 15000,
  AdSetFields::TARGETING => array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array('US'),
    TargetingFields::DYNAMIC_AUDIENCE_IDS => array(<DYNAMIC_AUDIENCE_ID>),
  AdSetFields::PROMOTED_OBJECT => array(
    'product_set_id' => <PRODUCT_SET_ID>,
    'page_id' => <PAGE_ID>,

curl \
  -F 'name=Product Catalog Sales Adset' \
  -F 'bid_amount=3000' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'optimization_goal=LEAD_GENERATION' \
  -F 'daily_budget=15000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "dynamic_audience_ids": ["<DYNAMIC_AUDIENCE_ID>"] 
  }' \
  -F 'promoted_object={"product_set_id":"<PRODUCT_SET_ID>","page_id":"<PAGE_ID>"}' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \

DYNAMIC_AUDIENCE_ID refers to a Product Audience who views your ads. You can omit dynamic_audience_ids from instead set behavioral- or demographic- based targeting to reach an audience. Provide:

  • product_audience_specs or
  • excluded_product_audience_specs parameters.

See Dynamic Ads.

Providing Ad and Creative

First provide ad creative:

use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\Values\AdCreativeCallToActionTypeValues;

$object_story_spec = new AdCreativeObjectStorySpec();
  AdCreativeObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
  AdCreativeObjectStorySpecFields::TEMPLATE_DATA =>
    (new AdCreativeLinkData())->setData(array(
      AdCreativeLinkDataFields::CALL_TO_ACTION => array(
        'type' => AdCreativeCallToActionTypeValues::SIGN_UP,
        'value' => array(
          'lead_gen_form_id' => <FORM_ID>,
      AdCreativeLinkDataFields::MESSAGE => 'Test {{product.name | titleize}}',
      AdCreativeLinkDataFields::LINK => '<LINK>',
      AdCreativeLinkDataFields::NAME => 'Headline {{product.price}}',
      AdCreativeLinkDataFields::DESCRIPTION =>
        'Description {{product.description}}',
      AdCreativeLinkDataFields::MULTI_SHARE_END_CARD => false,

$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');

  AdCreativeFields::NAME => 'Dynamic Ad With Leadgen Template Creative Sample',
  AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
  AdCreativeFields::PRODUCT_SET_ID => <PRODUCT_SET_ID>,

curl \
  -F 'name=Dynamic Ad With Leadgen Template Creative Sample' \
  -F 'object_story_spec={ 
    "page_id": "<PAGE_ID>", 
    "template_data": { 
      "call_to_action": {"type":"SIGN_UP","value":{"lead_gen_form_id":"<FORM_ID>"}}, 
      "description": "Description {{product.description}}", 
      "link": "<LINK>", 
      "message": "Test {{product.name | titleize}}", 
      "multi_share_end_card": false, 
      "name": "Headline {{product.price}}" 
  }' \
  -F 'product_set_id=<PRODUCT_SET_ID>' \
  -F 'access_token=<ACCESS_TOKEN>' \

This returns creative_id you can use to create or update an Ad:

use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;

$data = array(
  AdFields::NAME => 'My Ad',
  AdFields::ADSET_ID => <AD_SET_ID>,
  AdFields::CREATIVE => array(
    'creative_id' => <CREATIVE_ID>,

$ad = new Ad(null, 'act_<AD_ACCOUNT_ID>');
from facebookads.adobjects.ad import Ad

ad = Ad(parent_id='act_<AD_ACCOUNT_ID>')
ad[Ad.Field.name] = 'My Ad'
ad[Ad.Field.adset_id] = <AD_SET_ID>
ad[Ad.Field.creative] = {
    'creative_id': <CREATIVE_ID>,
    'status': Ad.Status.paused,
Ad ad = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAd()
  .setName("My Ad")
    new AdCreative()
ad_account = FacebookAds::AdAccount.get('act_<AD_ACCOUNT_ID>')
ad = ad_account.ads.create({
  name: 'My Ad',
  adset_id: <ADSET_ID>,
  creative: {
    creative_id: <CREATIVE_ID>,
  status: 'PAUSED',
curl \
  -F 'name=My Ad' \
  -F 'adset_id=<AD_SET_ID>' \
  -F 'creative={"creative_id":"<CREATIVE_ID>"}' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \

Fetching Leads

If you have the lead id from a CRM integration for example, you can ask for the details including item_id.

use FacebookAds\Object\Lead;

$form = new Lead(<LEAD_ID>);
curl -G \
  -d 'fields=field_data,retailer_item_id' \
  -d 'access_token=<ACCESS_TOKEN>' \

You can also bulk query all the leads for a form:

use FacebookAds\Object\LeadgenForm;

$form = new LeadgenForm(<FORM_ID>);
$leads = $form->getLeads(array(
curl -G \
  -d 'fields=field_data,retailer_item_id' \
  -d 'access_token=<ACCESS_TOKEN>' \

Or for an ad:

use FacebookAds\Object\Ad;

$ad = new Ad(<AD_ID>);
$leads = $ad->getLeads(array(
curl -G \
  -d 'fields=field_data,retailer_item_id' \
  -d 'access_token=<ACCESS_TOKEN>' \