基本受眾目標設定

基本或核心受眾目標設定包括:

限制

刊登房屋、招聘、信用卡廣告、社會議題、選舉或政治廣告的美國廣告客戶或向美國用戶刊登廣告的廣告客戶,須受不同限制約束。

人口統計資料及活動

您可由根據人口統計資料及地點的基本目標指定開始。一般而言,您可從目標指定搜尋取得用於定義目標指定的數據,然後於目標指定規格指定選項。目標指定規格是廣告組合的屬性,可用於定義看到廣告的對象。

指定目標時,除非您使用自訂廣告受眾,否則請務必指定至少一個國家/地區

按人口統計資料指定目標:

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

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::RELATIONSHIP_STATUSES => array(2, 4),
    TargetingFields::LIFE_EVENTS => array(
      array(
        'id' => 6003054185372,
        'name' => 'Recently Moved',
      ),
    ),
    TargetingFields::INDUSTRIES => array(
      array(
        'id' => 6009003307783,
        'name' => 'Accounting and finance',
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'relationship_statuses': [2, 4],
        'life_events': [
            {
                'id': 6003054185372,
                'name': 'Recently Moved',
            },
        ],
        'industries': [
            {
                'id': 6009003307783,
                'name': 'Accounting and finance',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldIndustries(Arrays.asList(
        new IDName()
          .setFieldId("6009003307783")
          .setFieldName("Accounting and finance")
      ))
      .setFieldLifeEvents(Arrays.asList(
        new IDName()
          .setFieldId("6003054185372")
          .setFieldName("Recently Moved")
      ))
      .setFieldRelationshipStatuses(Arrays.asList(2L, 4L))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "industries": [{"id":6009003307783,"name":"Accounting and finance"}], 
    "life_events": [{"id":6003054185372,"name":"Recently Moved"}], 
    "relationship_statuses": [2,4] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets

可用欄位

名稱說明

genders

陣列

要鎖定的性別。預設為全部。1 指定男性,2 指定女性。

age_min

整數

年齡下限。預設為 18。如要使用,則數值必須為 13 或以上。如果應用程式有自訂年齡限制設定,帶有 APP_INSTALL 目標的廣告便會使用有關應用程式的年齡限制。舉例來說,如果您將 age_min 的數值設為 13,但您應用程式的年齡下限數值為 18,廣告目標設定所用的數值就會是 18。

age_max

整數

年齡上限。如要使用,則數值必須為 65 或以下。

地點

目標指定搜尋 API 搜尋及擷取地點目標指定值。此目標指定設有兩個參數:geo_locations 用於指定地點目標,而選用的 excluded_geo_locations 則用於排除地區。

使用 geo_locationscountry_groups 指定更廣闊的地理區域,例如歐洲或北美洲。

Using radius can cause an error, code: 100, subcode 1815946, when targeting multiple locations. We recommend creating an ad for each location or not using radius in your call.

可用欄位

名稱說明

countries

陣列

國家/地區目標指定。需要提供國碼/區碼陣列。目標指定搜尋,國家/地區範例'countries': ['US']

regions

陣列

州份、省份或地區。如欲了解可用值,請參閱目標指定搜尋,地區。限制:200。
範例'regions': [{'key':'3847'}]

cities

陣列

指定 keyradiusdistance_unit。如欲瞭解 key,請參閱目標指定搜尋,城市radius 即城市周圍的距離,(10 至 50 哩或 17 至 80 公里)。distance_unit 可以是哩或公里。限制:250。
範例'cities': [{'key':'2430536', 'radius':12, 'distance_unit':'mile'}]

zips

陣列

如欲指定郵遞區號目標,請參閱目標指定搜尋 API。限制:50,000。原先為 2,500。如果您提供的數量超過 2,500,我們會建立一個名為 location_cluster 的陣列,該陣列代表一組郵遞區號。範例'zips':[{'key':'US:94304'},{'key':'US:00501'}]

如要讀取 location_cluster 及查看指定目標地點:GET /location_cluster_ID

places

陣列

提供特定地點。限制:200。範例:"places":[{"key":129672430416115,"name":"SFO", "radius":10, "distance_unit":"mile"}]

custom_locations

陣列

適用於所有目標。提供確實緯度及經度位置或地址,以作地區的中心。亦可用於指定地點的半徑(0.63 至 50 哩或 1 至 80 公里)。distance_unit 可以是哩或公里,預設為哩。限制:200。address_string 不支援只含郵政信箱的地址。您必須最少提供街道地址。範例:'custom_locations':[{'address_string': '1601 Willow Road, Menlo Park, CA', 'radius': 5},{'latitude': 36, 'longitude': -121.0, 'radius': 5, 'distance_unit': 'kilometer'},]

custom_locations.latitude

浮點數

地點的緯度

custom_locations.longitude

浮點數

地點的經度

custom_locations.name

字串

地址名稱。您可使用 latitudelongitude 值以指定地理地點目標設定,而無需提供 address_string

custom_locations.radius

浮點數

緯度/經度周圍的半徑,除非另有設定,否則 distance_unit 的預設單位為哩。允許的距離為 0.63 至 50 英里或 1 至 80 公里。

custom_locations.distance_unit

字串

此為選用項目。

kilometermile;預設為 mile

custom_locations.address_string

字串

緯度/經度地址,如 1601 Willow Rd, Menlo Park, CA。建議格式:街道號碼,街道名稱,城市,州份/省份,國家/地區。無需包含郵政編碼。

geo_markets

陣列

市場鍵,格式為「DMA:501」。我們支援所有 Designated Marketing Area(DMA)。透過目標指定搜尋查詢按 DMA 名稱取得 DMA 代碼。限制:2500
範例'geo_markets':[{'key': 'DMA:501', 'name': 'New York'},{'key': 'DMA:543', 'name': 'Springfield-Holyoke'},]

electoral_district

陣列

選區鍵。於目標指定搜尋,選區取得區域。
範例'electoral_districts':[{'key':'US:AK00'},{'key':'US:CA01'},{'key':'US:NY14'}]

location_types

陣列

備註:由 v18.0 版本開始,陣列 ['home', 'recent'] 將是唯一可用選項。


在 v18.0 及以上版本中,如果您未有提供 location_types,系統預設將對此欄位使用陣列 ['home', 'recent']


  • recent:最近地點位於所選區域的用戶,此資料根據流動裝置數據判斷。不適用於排除地點。
  • home:在 Facebook 個人檔案「現居城市」中列明有關區域的用戶。Facebook 會根據用戶 IP 及其朋友的個人檔案地點資訊,來驗證此項資料。

country_groups

陣列

全球地理區域及自由貿易區。需要提供國家/地區群組代碼陣列:


worldwide:全球。

africa:非洲。

afta:東盟自由貿易區。

android_app_store:Android 應用程式商店中支援付費應用程式的國家/地區。

android_free_store:Android 應用程式商店中支援免費應用程式的國家/地區。

apec:亞洲太平洋經濟合作組織。

asia:亞洲

caribbean:加勒比海地區。

central_america:中美洲。

cisfta:獨立國家聯合體。

eea:歐洲經濟區。

emerging_markets:新興市場的國家/地區

europe:歐洲。

gcc:海灣阿拉伯國家合作委員會。

itunes_app_store:支援 iTunes App Store 的國家/地區。

mercosur:南方共同市場。

nafta:北美自由貿易協議。

north_america:北美洲。

oceania:大洋洲。

south_america:南美洲。


詳情請參閱目標指定搜尋,國家/地區群組

範例'country_groups': ['asia','mercosur']

範例

按國家/地區指定目標

curl -X POST \ -F 'name="My Reach Ad Set"' \ -F 'optimization_goal="REACH"' \ -F 'billing_event="IMPRESSIONS"' \ -F 'bid_amount=2' \ -F 'daily_budget=1000' \ -F 'campaign_id="<AD_CAMPAIGN_ID>"' \ -F 'targeting={ "geo_locations": { "countries": [ "US" ] }, "facebook_positions": [ "feed" ] }' \ -F 'status="PAUSED"' \ -F 'promoted_object={ "page_id": "<PAGE_ID>" }' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/adsets
'use strict'; const bizSdk = require('facebook-nodejs-business-sdk'); const AdAccount = bizSdk.AdAccount; const AdSet = bizSdk.AdSet; const access_token = '<ACCESS_TOKEN>'; const app_secret = '<APP_SECRET>'; const app_id = '<APP_ID>'; const id = '<AD_ACCOUNT_ID>'; const api = bizSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const logApiCallResult = (apiCallName, data) => { console.log(apiCallName); if (showDebugingInfo) { console.log('Data:' + JSON.stringify(data)); } }; let fields, params; fields = [ ]; params = { 'name' : 'My Reach Ad Set', 'optimization_goal' : 'REACH', 'billing_event' : 'IMPRESSIONS', 'bid_amount' : '2', 'daily_budget' : '1000', 'campaign_id' : '<adCampaignLinkClicksID>', 'targeting' : {'geo_locations':{'countries':['US']},'facebook_positions':['feed']}, 'status' : 'PAUSED', 'promoted_object' : {'page_id':'<pageID>'}, }; const adsets = (new AdAccount(id)).createAdSet( fields, params ); logApiCallResult('adsets api call complete.', adsets);
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\AdSet; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<AD_ACCOUNT_ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'My Reach Ad Set', 'optimization_goal' => 'REACH', 'billing_event' => 'IMPRESSIONS', 'bid_amount' => '2', 'daily_budget' => '1000', 'campaign_id' => '<adCampaignLinkClicksID>', 'targeting' => array('geo_locations' => array('countries' => array('US')),'facebook_positions' => array('feed')), 'status' => 'PAUSED', 'promoted_object' => array('page_id' => '<pageID>'), ); echo json_encode((new AdAccount($id))->createAdSet( $fields, $params )->exportAllData(), JSON_PRETTY_PRINT);
from facebook_business.adobjects.adaccount import AdAccount from facebook_business.adobjects.adset import AdSet from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'My Reach Ad Set', 'optimization_goal': 'REACH', 'billing_event': 'IMPRESSIONS', 'bid_amount': '2', 'daily_budget': '1000', 'campaign_id': '<adCampaignLinkClicksID>', 'targeting': {'geo_locations':{'countries':['US']},'facebook_positions':['feed']}, 'status': 'PAUSED', 'promoted_object': {'page_id':'<pageID>'}, } print AdAccount(id).create_ad_set( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<AD_ACCOUNT_ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAdSet() .setName(\"My Reach Ad Set\") .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH) .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS) .setBidAmount(2L) .setDailyBudget(1000L) .setCampaignId(\"<adCampaignLinkClicksID>\") .setTargeting( new Targeting() .setFieldFacebookPositions(Arrays.asList(\"feed\")) .setFieldGeoLocations( new TargetingGeoLocation() .setFieldCountries(Arrays.asList(\"US\")) ) ) .setStatus(AdSet.EnumStatus.VALUE_PAUSED) .setPromotedObject(\"{\\"page_id\\":\\"<pageID>\\"}\") .execute(); } }
require 'facebook_ads' access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) adsets = ad_account.adsets.create({ name: 'My Reach Ad Set', optimization_goal: 'REACH', billing_event: 'IMPRESSIONS', bid_amount: '2', daily_budget: '1000', campaign_id: '<adCampaignLinkClicksID>', targeting: {'geo_locations':{'countries':['US']},'facebook_positions':['feed']}, status: 'PAUSED', promoted_object: {'page_id':'<pageID>'}, })

排除地點目標設定

curl -X POST \ -F 'name="My Reach Ad Set"' \ -F 'optimization_goal="REACH"' \ -F 'billing_event="IMPRESSIONS"' \ -F 'bid_amount=2' \ -F 'daily_budget=1000' \ -F 'campaign_id="<AD_CAMPAIGN_ID>"' \ -F 'targeting={ "excluded_geo_locations": { "regions": [ { "key": "3847" } ] }, "geo_locations": { "countries": [ "US" ] }, "facebook_positions": [ "feed" ] }' \ -F 'status="PAUSED"' \ -F 'promoted_object={ "page_id": "<PAGE_ID>" }' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/adsets
'use strict'; const bizSdk = require('facebook-nodejs-business-sdk'); const AdAccount = bizSdk.AdAccount; const AdSet = bizSdk.AdSet; const access_token = '<ACCESS_TOKEN>'; const app_secret = '<APP_SECRET>'; const app_id = '<APP_ID>'; const id = '<AD_ACCOUNT_ID>'; const api = bizSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const logApiCallResult = (apiCallName, data) => { console.log(apiCallName); if (showDebugingInfo) { console.log('Data:' + JSON.stringify(data)); } }; let fields, params; fields = [ ]; params = { 'name' : 'My Reach Ad Set', 'optimization_goal' : 'REACH', 'billing_event' : 'IMPRESSIONS', 'bid_amount' : '2', 'daily_budget' : '1000', 'campaign_id' : '<adCampaignLinkClicksID>', 'targeting' : {'excluded_geo_locations':{'regions':[{'key':'3847'}]},'geo_locations':{'countries':['US']},'facebook_positions':['feed']}, 'status' : 'PAUSED', 'promoted_object' : {'page_id':'<pageID>'}, }; const adsets = (new AdAccount(id)).createAdSet( fields, params ); logApiCallResult('adsets api call complete.', adsets);
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\AdSet; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<AD_ACCOUNT_ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'My Reach Ad Set', 'optimization_goal' => 'REACH', 'billing_event' => 'IMPRESSIONS', 'bid_amount' => '2', 'daily_budget' => '1000', 'campaign_id' => '<adCampaignLinkClicksID>', 'targeting' => array('excluded_geo_locations' => array('regions' => array(array('key' => '3847'))),'geo_locations' => array('countries' => array('US')),'facebook_positions' => array('feed')), 'status' => 'PAUSED', 'promoted_object' => array('page_id' => '<pageID>'), ); echo json_encode((new AdAccount($id))->createAdSet( $fields, $params )->exportAllData(), JSON_PRETTY_PRINT);
from facebook_business.adobjects.adaccount import AdAccount from facebook_business.adobjects.adset import AdSet from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'My Reach Ad Set', 'optimization_goal': 'REACH', 'billing_event': 'IMPRESSIONS', 'bid_amount': '2', 'daily_budget': '1000', 'campaign_id': '<adCampaignLinkClicksID>', 'targeting': {'excluded_geo_locations':{'regions':[{'key':'3847'}]},'geo_locations':{'countries':['US']},'facebook_positions':['feed']}, 'status': 'PAUSED', 'promoted_object': {'page_id':'<pageID>'}, } print AdAccount(id).create_ad_set( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<AD_ACCOUNT_ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAdSet() .setName(\"My Reach Ad Set\") .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH) .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS) .setBidAmount(2L) .setDailyBudget(1000L) .setCampaignId(\"<adCampaignLinkClicksID>\") .setTargeting( new Targeting() .setFieldExcludedGeoLocations( new TargetingGeoLocation() .setFieldRegions(Arrays.asList( new TargetingGeoLocationRegion() .setFieldKey(\"3847\") )) ) .setFieldFacebookPositions(Arrays.asList(\"feed\")) .setFieldGeoLocations( new TargetingGeoLocation() .setFieldCountries(Arrays.asList(\"US\")) ) ) .setStatus(AdSet.EnumStatus.VALUE_PAUSED) .setPromotedObject(\"{\\"page_id\\":\\"<pageID>\\"}\") .execute(); } }
require 'facebook_ads' access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) adsets = ad_account.adsets.create({ name: 'My Reach Ad Set', optimization_goal: 'REACH', billing_event: 'IMPRESSIONS', bid_amount: '2', daily_budget: '1000', campaign_id: '<adCampaignLinkClicksID>', targeting: {'excluded_geo_locations':{'regions':[{'key':'3847'}]},'geo_locations':{'countries':['US']},'facebook_positions':['feed']}, status: 'PAUSED', promoted_object: {'page_id':'<pageID>'}, })

按郵遞區號指定目標

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

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      TargetingFields::ZIPS => array(
        array(
          'key' => 'US:94304',
        ),
        array(
          'key' => 'US:00501',
        ),
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'zips': [
                {
                    'key': 'US:94304',
                },
                {
                    'key': 'US:00501',
                },
            ],
        },
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldZips(Arrays.asList(
            new TargetingGeoLocationZip()
              .setFieldKey("US:94304")
          , 
            new TargetingGeoLocationZip()
              .setFieldKey("US:00501")
          ))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={"geo_locations":{"zips":[{"key":"US:94304"},{"key":"US:00501"}]}}' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets

按自訂地點、DMA 及地點類型指定目標

以下代碼將目標設定為:

  • 1601 Willow Road, Menlo Park, CA 周圍的 5 哩以內
  • 經度為 -121.0、緯度為 36 之地周圍的 5 公里以內
  • 地區類型為最近身處地及居住地的 DMAs 501 和 543 之處
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'custom_locations' => array(
        array(
          'address_string' => '1601 Willow Road, Menlo Park, CA',
          'radius' => '5',
        ),
        array(
          'latitude' => '36',
          'longitude' => '-121.0',
          'radius' => '5',
          'distance_unit' => 'kilometer',
        ),
      ),
      'geo_markets' => array(
        array(
          'key' => 'DMA:501',
          'name' => 'New York',
        ),
        array(
          'key' => 'DMA:543',
          'name' => 'Springfield-Holyoke',
        ),
      ),
      'location_types' => array('recent', 'home'),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'custom_locations': [
                {
                    'custom_type': 'multi_city',
                    'min_population': 500000,
                    'max_population': 1000000,
                    'country': 'BR',
                },
                {
                    'custom_type': 'multi_city',
                    'country_group': 'Europe',
                },
            ],
            'location_types': ['recent', 'home'],
        },
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCustomLocations(Arrays.asList(
            new TargetingGeoLocationCustomLocation()
              .setFieldAddressString("1601 Willow Road, Menlo Park, CA")
              .setFieldRadius((double) 5)
          , 
            new TargetingGeoLocationCustomLocation()
              .setFieldDistanceUnit("kilometer")
              .setFieldLatitude((double) 36)
              .setFieldLongitude((double) -121.0)
              .setFieldRadius((double) 5)
          ))
          .setFieldGeoMarkets(Arrays.asList(
            new TargetingGeoLocationMarket()
              .setFieldKey("DMA:501")
              .setFieldName("New York")
          , 
            new TargetingGeoLocationMarket()
              .setFieldKey("DMA:543")
              .setFieldName("Springfield-Holyoke")
          ))
          .setFieldLocationTypes(Arrays.asList("recent", "home"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": { 
      "custom_locations": [ 
        {"address_string":"1601 Willow Road, Menlo Park, CA","radius":"5"}, 
        { 
          "latitude": "36", 
          "longitude": "-121.0", 
          "radius": "5", 
          "distance_unit": "kilometer" 
        } 
      ], 
      "geo_markets": [ 
        {"key":"DMA:501","name":"New York"}, 
        {"key":"DMA:543","name":"Springfield-Holyoke"} 
      ], 
      "location_types": ["recent","home"] 
    } 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets

搜尋和目標指定

如要將目標指定為年齡介乎 20 至 24、位於加州門洛公園 10 哩範圍以內或日本的男性:

第 1 步

先取得日本的國碼:

use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;

$result = TargetingSearch::search(
  TargetingSearchTypes::GEOLOCATION,
  null,
  'japan',
  array(
    'location_types' => array('country'),
  ));
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
    'q': 'japan',
    'type': 'adgeolocation',
    'location_types': ['country'],
}

resp = TargetingSearch.search(params=params)
print(resp)
curl -G \
  -d 'location_types=["country"]' \
  -d 'type=adgeolocation' \
  -d 'q=japan' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/search
第 2 步

取得德州地區的區碼:

use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;

$result = TargetingSearch::search(
  TargetingSearchTypes::GEOLOCATION,
  null,
  'texas',
  array(
    'location_types' => array('region'),
  ));
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
    'q': 'texas',
    'type': 'adgeolocation',
    'location_types': ['region'],
}

resp = TargetingSearch.search(params=params)
print(resp)
curl -G \
  -d 'location_types=["region"]' \
  -d 'type=adgeolocation' \
  -d 'q=texas' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/search
第 3 步

搜尋加州門洛公園的市碼:

use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;

$result = TargetingSearch::search(
  TargetingSearchTypes::GEOLOCATION,
  null,
  'menlo',
  array(
    'location_types' => array('city'),
  ));
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
    'q': 'menlo',
    'type': 'adgeolocation',
    'location_types': ['city'],
}

resp = TargetingSearch.search(params=params)
print(resp)
curl -G \
  -d 'location_types=["city"]' \
  -d 'type=adgeolocation' \
  -d 'q=menlo' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/search
第 4 步

請提供 genders,並按照 age_minage_max 提供年齡。

第 5 步

我們的目標指定規格已設有國碼、區碼及市碼:

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


$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My First AdSet',
  AdSetFields::DAILY_BUDGET => 10000,
  AdSetFields::BID_AMOUNT => 300,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::PROMOTED_OBJECT => array(
    'page_id' => <PAGE_ID>,
  ),
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array('JP'),
      'regions' => array(array('key' => '3886')),
      'cities' => array(
        array(
          'key' => '2420605',
          'radius' => 10,
          'distance_unit' => 'mile',
        ),
      ),
    ),
    TargetingFields::GENDERS => array(1),
    TargetingFields::AGE_MIN => 20,
    TargetingFields::AGE_MAX => 24,
    TargetingFields::PUBLISHER_PLATFORMS => array(
      'facebook',
      'audience_network',
    ),
    TargetingFields::DEVICE_PLATFORMS => array('mobile'),
  )),
));


$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.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.promoted_object: {'page_id': <PAGE_ID>},
    AdSet.Field.targeting: {
        Targeting.Field.geo_locations: {
            'countries': ['JP'],
            'regions': [
                {'key': '3886'},
            ],
            'cities': [
                {
                    'key': '2420605',
                    'radius': '10',
                    'distance_unit': 'mile',
                },
            ],
        },
        Targeting.Field.genders: [1],
        Targeting.Field.age_min: 20,
        Targeting.Field.age_max: 24,
        Targeting.Field.publisher_platforms: ['facebook', 'audience_network'],
        Targeting.Field.device_platforms: ['mobile'],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My First AdSet")
  .setDailyBudget(10000L)
  .setBidAmount(300L)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setCampaignId(<CAMPAIGN_ID>)
  .setPromotedObject("{\"page_id\":\"" + <PAGE_ID> + "\"}")
  .setTargeting(
    new Targeting()
      .setFieldAgeMax(24L)
      .setFieldAgeMin(20L)
      .setFieldDevicePlatforms(Arrays.asList(Targeting.EnumDevicePlatforms.VALUE_MOBILE))
      .setFieldGenders(Arrays.asList(1L))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCities(Arrays.asList(
            new TargetingGeoLocationCity()
              .setFieldDistanceUnit("mile")
              .setFieldKey("2420605")
              .setFieldRadius(10L)
          ))
          .setFieldCountries(Arrays.asList("JP"))
          .setFieldRegions(Arrays.asList(
            new TargetingGeoLocationRegion()
              .setFieldKey("3886")
          ))
      )
      .setFieldPublisherPlatforms(Arrays.asList("facebook", "audience_network"))
  )
  .setStatus(AdSet.EnumStatus.VALUE_PAUSED)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My First AdSet' \
  -F 'daily_budget=10000' \
  -F 'bid_amount=300' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'optimization_goal=REACH' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'promoted_object={"page_id":"<PAGE_ID>"}' \
  -F 'targeting={ 
    "age_max": 24, 
    "age_min": 20, 
    "device_platforms": ["mobile"], 
    "genders": [1], 
    "geo_locations": { 
      "countries": ["JP"], 
      "regions": [{"key":"3886"}], 
      "cities": [ 
        { 
          "key": "2420605", 
          "radius": 10, 
          "distance_unit": "mile" 
        } 
      ] 
    }, 
    "publisher_platforms": ["facebook","audience_network"] 
  }' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets

將目標指定為多個城市

custom_type 設為 'multi_city',並按照上文所述定義 countrycountry_group。其他選用參數如下所示:

名稱 說明

min_population

整數

所選目標城市的最低人口門檻。

max_population

整數

所選目標城市的最高人口門檻。

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

$adset = new AdSet();
$adset->setParentId('act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'custom_locations' => array(
        array(
          'custom_type' => 'multi_city',
          'min_population' => 500000,
          'max_population' => 1000000,
          'country' => 'BR',
        ),
        array(
          'custom_type' => 'multi_city',
          'country_group' => 'Europe',
        ),
      ),
      'location_types' => array('recent', 'home'),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adset import AdSet

ad_account = AdAccount(fbid='act_<AD_ACCOUNT_ID>')

params = {
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'custom_locations': [
                {
                    'custom_type': 'multi_city',
                    'min_population': 500000,
                    'max_population': 1000000,
                    'country': 'BR',
                },
                {
                    'custom_type': 'multi_city',
                    'country_group': 'Europe',
                },
            ],
            'location_types': ['recent', 'home'],
        },
    },
    AdSet.Field.status: AdSet.Status.active,
}
adset = ad_account.create_ad_set(params=params)
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My First AdSet")
  .setDailyBudget(10000L)
  .setBidAmount(300L)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setCampaignId(<CAMPAIGN_ID>)
  .setPromotedObject("{\"page_id\":\"" + <PAGE_ID> + "\"}")
  .setTargeting(
    new Targeting()
      .setFieldAgeMax(24L)
      .setFieldAgeMin(20L)
      .setFieldDevicePlatforms(Arrays.asList(Targeting.EnumDevicePlatforms.VALUE_MOBILE))
      .setFieldGenders(Arrays.asList(1L))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCustomLocations(Arrays.asList(
            new TargetingGeoLocationCustomLocation()
              .setFieldCountry("BR")
              .setFieldCustomType("multi_city")
              .setFieldMaxPopulation(1000000L)
              .setFieldMinPopulation(500000L)
          , 
            new TargetingGeoLocationCustomLocation()
              .setFieldCountryGroup("Asia")
              .setFieldCustomType("multi_city")
          ))
          .setFieldLocationTypes(Arrays.asList("recent", "home"))
      )
      .setFieldPublisherPlatforms(Arrays.asList("facebook", "audience_network"))
  )
  .setStatus(AdSet.EnumStatus.VALUE_PAUSED)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": { 
      "custom_locations": [ 
        { 
          "custom_type": "multi_city", 
          "min_population": 500000, 
          "max_population": 1000000, 
          "country": "BR" 
        }, 
        {"custom_type":"multi_city","country_group":"Europe"} 
      ], 
      "location_types": ["recent","home"] 
    } 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets

興趣目標設定

根據用戶生活時報中的興趣、其讚好的專頁,或與其使用的專頁或應用程式相關的關鍵字指定目標。詳情請參閱目標指定搜尋,興趣

如要將目標指定為對足球有興趣的用戶,請先查詢:

use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;

$result = TargetingSearch::search(
  TargetingSearchTypes::INTEREST,
  null,
  'soccer');
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
    'q': 'soccer',
    'type': 'adinterest',
}

resp = TargetingSearch.search(params=params)
print(resp)
curl -G \
  -d 'type=adinterest' \
  -d 'q=soccer' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/search

nameid 將此興趣加至目標指定規格,而 path 則為廣告工具內此興趣的路徑。

curl -X POST \ -F 'name="My First AdSet"' \ -F 'daily_budget=10000' \ -F 'bid_amount=300' \ -F 'billing_event="IMPRESSIONS"' \ -F 'optimization_goal="REACH"' \ -F 'campaign_id="<AD_CAMPAIGN_ID>"' \ -F 'promoted_object={ "page_id": "<PAGE_ID>" }' \ -F 'targeting={ "facebook_positions": [ "feed" ], "geo_locations": { "countries": [ "US" ], "regions": [ { "key": "4081" } ], "cities": [ { "key": 777934, "radius": 10, "distance_unit": "mile" } ] }, "genders": [ 1 ], "age_max": 24, "age_min": 20, "publisher_platforms": [ "facebook", "audience_network" ], "device_platforms": [ "mobile" ], "flexible_spec": [ { "interests": [ { "id": "<INTEREST_ID>", "name": "<INTEREST_NAME>" } ] } ] }' \ -F 'status="PAUSED"' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/adsets
'use strict'; const bizSdk = require('facebook-nodejs-business-sdk'); const AdAccount = bizSdk.AdAccount; const AdSet = bizSdk.AdSet; const access_token = '<ACCESS_TOKEN>'; const app_secret = '<APP_SECRET>'; const app_id = '<APP_ID>'; const id = '<AD_ACCOUNT_ID>'; const api = bizSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const logApiCallResult = (apiCallName, data) => { console.log(apiCallName); if (showDebugingInfo) { console.log('Data:' + JSON.stringify(data)); } }; let fields, params; fields = [ ]; params = { 'name' : 'My First AdSet', 'daily_budget' : '10000', 'bid_amount' : '300', 'billing_event' : 'IMPRESSIONS', 'optimization_goal' : 'REACH', 'campaign_id' : '<adCampaignLinkClicksID>', 'promoted_object' : {'page_id':'<pageID>'}, 'targeting' : {'facebook_positions':['feed'],'geo_locations':{'countries':['US'],'regions':[{'key':'4081'}],'cities':[{'key':777934,'radius':10,'distance_unit':'mile'}]},'genders':[1],'age_max':24,'age_min':20,'publisher_platforms':['facebook','audience_network'],'device_platforms':['mobile'],'flexible_spec':[{'interests':[{'id':'<adsInterestID>','name':'<adsInterestName>'}]}]}, 'status' : 'PAUSED', }; const adsets = (new AdAccount(id)).createAdSet( fields, params ); logApiCallResult('adsets api call complete.', adsets);
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\AdSet; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<AD_ACCOUNT_ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'My First AdSet', 'daily_budget' => '10000', 'bid_amount' => '300', 'billing_event' => 'IMPRESSIONS', 'optimization_goal' => 'REACH', 'campaign_id' => '<adCampaignLinkClicksID>', 'promoted_object' => array('page_id' => '<pageID>'), 'targeting' => array('facebook_positions' => array('feed'),'geo_locations' => array('countries' => array('US'),'regions' => array(array('key' => '4081')),'cities' => array(array('key' => 777934,'radius' => 10,'distance_unit' => 'mile'))),'genders' => array(1),'age_max' => 24,'age_min' => 20,'publisher_platforms' => array('facebook','audience_network'),'device_platforms' => array('mobile'),'flexible_spec' => array(array('interests' => array(array('id' => '<adsInterestID>','name' => '<adsInterestName>'))))), 'status' => 'PAUSED', ); echo json_encode((new AdAccount($id))->createAdSet( $fields, $params )->exportAllData(), JSON_PRETTY_PRINT);
from facebook_business.adobjects.adaccount import AdAccount from facebook_business.adobjects.adset import AdSet from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'My First AdSet', 'daily_budget': '10000', 'bid_amount': '300', 'billing_event': 'IMPRESSIONS', 'optimization_goal': 'REACH', 'campaign_id': '<adCampaignLinkClicksID>', 'promoted_object': {'page_id':'<pageID>'}, 'targeting': {'facebook_positions':['feed'],'geo_locations':{'countries':['US'],'regions':[{'key':'4081'}],'cities':[{'key':777934,'radius':10,'distance_unit':'mile'}]},'genders':[1],'age_max':24,'age_min':20,'publisher_platforms':['facebook','audience_network'],'device_platforms':['mobile'],'flexible_spec':[{'interests':[{'id':'<adsInterestID>','name':'<adsInterestName>'}]}]}, 'status': 'PAUSED', } print AdAccount(id).create_ad_set( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<AD_ACCOUNT_ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAdSet() .setName(\"My First AdSet\") .setDailyBudget(10000L) .setBidAmount(300L) .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS) .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH) .setCampaignId(\"<adCampaignLinkClicksID>\") .setPromotedObject(\"{\\"page_id\\":\\"<pageID>\\"}\") .setTargeting( new Targeting() .setFieldAgeMax(24L) .setFieldAgeMin(20L) .setFieldDevicePlatforms(Arrays.asList(Targeting.EnumDevicePlatforms.VALUE_MOBILE)) .setFieldFacebookPositions(Arrays.asList(\"feed\")) .setFieldFlexibleSpec(Arrays.asList( new FlexibleTargeting() .setFieldInterests(Arrays.asList( new IDName() .setFieldId(\"<adsInterestID>\") .setFieldName(\"<adsInterestName>\") )) )) .setFieldGenders(Arrays.asList(1L)) .setFieldGeoLocations( new TargetingGeoLocation() .setFieldCities(Arrays.asList( new TargetingGeoLocationCity() .setFieldDistanceUnit(\"mile\") .setFieldKey(777934L) .setFieldRadius(10L) )) .setFieldCountries(Arrays.asList(\"US\")) .setFieldRegions(Arrays.asList( new TargetingGeoLocationRegion() .setFieldKey(\"4081\") )) ) .setFieldPublisherPlatforms(Arrays.asList(\"facebook\", \"audience_network\")) ) .setStatus(AdSet.EnumStatus.VALUE_PAUSED) .execute(); } }
require 'facebook_ads' access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) adsets = ad_account.adsets.create({ name: 'My First AdSet', daily_budget: '10000', bid_amount: '300', billing_event: 'IMPRESSIONS', optimization_goal: 'REACH', campaign_id: '<adCampaignLinkClicksID>', promoted_object: {'page_id':'<pageID>'}, targeting: {'facebook_positions':['feed'],'geo_locations':{'countries':['US'],'regions':[{'key':'4081'}],'cities':[{'key':777934,'radius':10,'distance_unit':'mile'}]},'genders':[1],'age_max':24,'age_min':20,'publisher_platforms':['facebook','audience_network'],'device_platforms':['mobile'],'flexible_spec':[{'interests':[{'id':'<adsInterestID>','name':'<adsInterestName>'}]}]}, status: 'PAUSED', })

以下為另一個範例:

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

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::INTERESTS => array(
      array(
        'id' => 6003139266461,
        'name' => 'Movies',
      ),
      array(
        'id' => 6003397425735,
        'name' => 'Tennis',
      ),
      array(
        'id' => 6003659420716,
        'name' => 'Cooking',
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'interests': [
            {
                'id': 6003139266461,
                'name': 'Movies',
            },
            {
                'id': 6003397425735,
                'name': 'Tennis',
            },
            {
                'id': 6003659420716,
                'name': 'Cooking',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldInterests(Arrays.asList(
        new IDName()
          .setFieldId("6003139266461")
          .setFieldName("Movies")
      , 
        new IDName()
          .setFieldId("6003397425735")
          .setFieldName("Tennis")
      , 
        new IDName()
          .setFieldId("6003659420716")
          .setFieldName("Cooking")
      ))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "interests": [ 
      {"id":6003139266461,"name":"Movies"}, 
      {"id":6003397425735,"name":"Tennis"}, 
      {"id":6003659420716,"name":"Cooking"} 
    ] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets

可用欄位

名稱 說明

interests

陣列

設有「id」及選用「name」欄位的陣列:'interests':[{id: 6003139266461, 'name': 'Movies'}, {id: 6003139266462}, 6003139266463]

行為目標指定

根據數碼活動、用戶所使用的裝置、過去或計劃中的訂單,以及旅遊地點指定目標。請前往 Browse 查閱飛行常客等選項。詳情請參閱目標指定搜尋 API

use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;

$result = TargetingSearch::search(
  TargetingSearchTypes::TARGETING_CATEGORY,
  'behaviors');
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
    'type': 'adTargetingCategory',
    'class': 'behaviors',
}

resp = TargetingSearch.search(params=params)
print(resp)
curl -G \
  -d 'type=adTargetingCategory' \
  -d 'class=behaviors' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/search

將行為加入 targeting_spec

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


$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My First AdSet',
  AdSetFields::DAILY_BUDGET => 10000,
  AdSetFields::BID_AMOUNT => 300,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::PROMOTED_OBJECT => array(
    'page_id' => <PAGE_ID>,
  ),
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array('JP'),
      'regions' => array(array('key' => '3886')),
      'cities' => array(
        array(
          'key' => '2420605',
          'radius' => 10,
          'distance_unit' => 'mile',
        ),
      ),
    ),
    TargetingFields::GENDERS => array(1),
    TargetingFields::AGE_MIN => 20,
    TargetingFields::AGE_MAX => 24,
    TargetingFields::PUBLISHER_PLATFORMS => array(
      'facebook',
      'audience_network',
    ),
    TargetingFields::DEVICE_PLATFORMS => array('mobile'),
    TargetingFields::INTERESTS => array(
      array(
        'id' => 6003107902433,
        'name' => 'Association football (Soccer)',
      ),
    ),
    TargetingFields::BEHAVIORS => array(
      array(
        'id' => 6002714895372,
        'name' => 'All frequent travelers',
      ),
    ),
  )),
));


$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.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.promoted_object: {'page_id': <PAGE_ID>},
    AdSet.Field.targeting: {
        Targeting.Field.geo_locations: {
            'countries': ['JP'],
            'regions': [
                {'key': '3886'},
            ],
            'cities': [
                {
                    'key': '2420605',
                    'radius': '10',
                    'distance_unit': 'mile',
                },
            ],
        },
        Targeting.Field.genders: [1],
        Targeting.Field.age_min: 20,
        Targeting.Field.age_max: 24,
        Targeting.Field.publisher_platforms: ['facebook', 'audience_network'],
        Targeting.Field.device_platforms: ['mobile'],
        Targeting.Field.interests: [
            {
                'id': 6003107902433,
                'name': 'Association football (Soccer)',
            },
        ],
        Targeting.Field.behaviors: [
            {
                'id': 6002714895372,
                'name': 'All frequent travelers',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My First AdSet")
  .setDailyBudget(10000L)
  .setBidAmount(300L)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setCampaignId(<CAMPAIGN_ID>)
  .setPromotedObject("{\"page_id\":\"" + <PAGE_ID> + "\"}")
  .setTargeting(
    new Targeting()
      .setFieldAgeMax(24L)
      .setFieldAgeMin(20L)
      .setFieldBehaviors(Arrays.asList(
        new IDName()
          .setFieldId("6002714895372")
          .setFieldName("All frequent travelers")
      ))
      .setFieldDevicePlatforms(Arrays.asList(Targeting.EnumDevicePlatforms.VALUE_MOBILE))
      .setFieldGenders(Arrays.asList(1L))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCities(Arrays.asList(
            new TargetingGeoLocationCity()
              .setFieldDistanceUnit("mile")
              .setFieldKey("2420605")
              .setFieldRadius(10L)
          ))
          .setFieldCountries(Arrays.asList("JP"))
          .setFieldRegions(Arrays.asList(
            new TargetingGeoLocationRegion()
              .setFieldKey("3886")
          ))
      )
      .setFieldInterests(Arrays.asList(
        new IDName()
          .setFieldId("6003107902433")
          .setFieldName("Association football (Soccer)")
      ))
      .setFieldPublisherPlatforms(Arrays.asList("facebook", "audience_network"))
  )
  .setStatus(AdSet.EnumStatus.VALUE_PAUSED)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My First AdSet' \
  -F 'daily_budget=10000' \
  -F 'bid_amount=300' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'optimization_goal=REACH' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'promoted_object={"page_id":"<PAGE_ID>"}' \
  -F 'targeting={ 
    "age_max": 24, 
    "age_min": 20, 
    "behaviors": [{"id":6002714895372,"name":"All frequent travelers"}], 
    "device_platforms": ["mobile"], 
    "genders": [1], 
    "geo_locations": { 
      "countries": ["JP"], 
      "regions": [{"key":"3886"}], 
      "cities": [ 
        { 
          "key": "2420605", 
          "radius": 10, 
          "distance_unit": "mile" 
        } 
      ] 
    }, 
    "interests": [{"id":6003107902433,"name":"Association football (Soccer)"}], 
    "publisher_platforms": ["facebook","audience_network"] 
  }' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets

以下為另一個範例:

curl -X POST \ -F 'name="My AdSet"' \ -F 'optimization_goal="REACH"' \ -F 'billing_event="IMPRESSIONS"' \ -F 'bid_amount=2' \ -F 'daily_budget=1000' \ -F 'campaign_id="<AD_CAMPAIGN_ID>"' \ -F 'targeting={ "facebook_positions": [ "feed" ], "geo_locations": { "countries": [ "US" ] }, "behaviors": [ { "id": 6007101597783, "name": "Business Travelers" }, { "id": 6004386044572, "name": "Android Owners (All)" } ] }' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/adsets
'use strict'; const bizSdk = require('facebook-nodejs-business-sdk'); const AdAccount = bizSdk.AdAccount; const AdSet = bizSdk.AdSet; const access_token = '<ACCESS_TOKEN>'; const app_secret = '<APP_SECRET>'; const app_id = '<APP_ID>'; const id = '<AD_ACCOUNT_ID>'; const api = bizSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const logApiCallResult = (apiCallName, data) => { console.log(apiCallName); if (showDebugingInfo) { console.log('Data:' + JSON.stringify(data)); } }; let fields, params; fields = [ ]; params = { 'name' : 'My AdSet', 'optimization_goal' : 'REACH', 'billing_event' : 'IMPRESSIONS', 'bid_amount' : '2', 'daily_budget' : '1000', 'campaign_id' : '<adCampaignConversionsID>', 'targeting' : {'facebook_positions':['feed'],'geo_locations':{'countries':['US']},'behaviors':[{'id':6007101597783,'name':'Business Travelers'},{'id':6004386044572,'name':'Android Owners (All)'}]}, }; const adsets = (new AdAccount(id)).createAdSet( fields, params ); logApiCallResult('adsets api call complete.', adsets);
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\AdSet; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<AD_ACCOUNT_ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'My AdSet', 'optimization_goal' => 'REACH', 'billing_event' => 'IMPRESSIONS', 'bid_amount' => '2', 'daily_budget' => '1000', 'campaign_id' => '<adCampaignConversionsID>', 'targeting' => array('facebook_positions' => array('feed'),'geo_locations' => array('countries' => array('US')),'behaviors' => array(array('id' => 6007101597783,'name' => 'Business Travelers'),array('id' => 6004386044572,'name' => 'Android Owners (All)'))), ); echo json_encode((new AdAccount($id))->createAdSet( $fields, $params )->exportAllData(), JSON_PRETTY_PRINT);
from facebook_business.adobjects.adaccount import AdAccount from facebook_business.adobjects.adset import AdSet from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'My AdSet', 'optimization_goal': 'REACH', 'billing_event': 'IMPRESSIONS', 'bid_amount': '2', 'daily_budget': '1000', 'campaign_id': '<adCampaignConversionsID>', 'targeting': {'facebook_positions':['feed'],'geo_locations':{'countries':['US']},'behaviors':[{'id':6007101597783,'name':'Business Travelers'},{'id':6004386044572,'name':'Android Owners (All)'}]}, } print AdAccount(id).create_ad_set( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<AD_ACCOUNT_ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAdSet() .setName(\"My AdSet\") .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH) .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS) .setBidAmount(2L) .setDailyBudget(1000L) .setCampaignId(\"<adCampaignConversionsID>\") .setTargeting( new Targeting() .setFieldBehaviors(Arrays.asList( new IDName() .setFieldId(6007101597783L) .setFieldName(\"Business Travelers\") , new IDName() .setFieldId(6004386044572L) .setFieldName(\"Android Owners (All)\") )) .setFieldFacebookPositions(Arrays.asList(\"feed\")) .setFieldGeoLocations( new TargetingGeoLocation() .setFieldCountries(Arrays.asList(\"US\")) ) ) .execute(); } }
require 'facebook_ads' access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<AD_ACCOUNT_ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) adsets = ad_account.adsets.create({ name: 'My AdSet', optimization_goal: 'REACH', billing_event: 'IMPRESSIONS', bid_amount: '2', daily_budget: '1000', campaign_id: '<adCampaignConversionsID>', targeting: {'facebook_positions':['feed'],'geo_locations':{'countries':['US']},'behaviors':[{'id':6007101597783,'name':'Business Travelers'},{'id':6004386044572,'name':'Android Owners (All)'}]}, })

可用欄位

名稱 說明

behaviors

陣列

設有「id」及選用「name」欄位的陣列:'behaviors':[{id: 6004386044572, 'name': 'Android Owners (All)'}, {id: 6004386044573}, 6004386044574]

相關資源

其他目標指定:

  • 廣告受眾網絡:於廣告受眾網絡刊登廣告,並增加您的連結或應用程式廣告的接觸人數