Reputation: 223
I am using the Facebook Marketing Api to create ads and custom audiences. How ever i cannot find a way to link the custom audiences created to a Adset. Below is the example available in github. For the moment i can only create Adsets with Interest and Geo locations.
As show in the example below we can only target by interest and geo location.
$results = TargetingSearch::search(
$type = TargetingSearchTypes::INTEREST,
$class = null,
$query = 'facebook');
// we'll take the top result for now
$target = (count($results)) ? $results->current() : null;
echo "Using target: ".$target->name."\n";
$targeting = new TargetingSpecs();
$targeting->{TargetingSpecsFields::GEO_LOCATIONS}
= array('countries' => array('GB'));
$targeting->{TargetingSpecsFields::INTERESTS} = array(
array(
'id' => $target->id,
'name' => $target->name,
),
);
$adset = new AdSet(null, $account->id);
$adset->setData(array(
AdSetFields::NAME => 'My First AdSet',
AdSetFields::CAMPAIGN_ID => $campaign->id,
AdSetFields::STATUS => AdSet::STATUS_ACTIVE,
AdSetFields::DAILY_BUDGET => '150',
AdSetFields::TARGETING => $targeting,
AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH,
AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS,
AdSetFields::BID_AMOUNT => 2,
AdSetFields::START_TIME =>
(new \DateTime("+1 week"))->format(\DateTime::ISO8601),
AdSetFields::END_TIME =>
(new \DateTime("+2 week"))->format(\DateTime::ISO8601),
));
$adset->validate()->create();
echo 'AdSet ID: '. $adset->id . "\n";
My requirement is to link a custom audience directly to Adset, for example AdSetFields::CUSTOMAUDIENCE => $audienceid
is this atleast possible ? If cannot how do we associate the custom audience we created with and Adset ?
Upvotes: 1
Views: 966
Reputation: 4397
You can use the field custom_audiences which accepts a set of custom audiences to target. I'm not sure if the name is actually required also, however it's in all the examples:
$targeting->{TargetingSpecsFields::CUSTOM_AUDIENCES} = array(
array(
'id' => <AUDIENCE_ID>,
'name' => <AUDIENCE_NAME>,
),
);
See the targeting doc and search for "Targeting Custom Audience & Partner Categories"
Upvotes: 1