Esempio n. 1
0
 private function createAdSet($campaignId)
 {
     $adset = new AdSet(null, 'act_' . $this->adAccountId);
     $adset->setData(array(AdSetFields::NAME => 'My Ad Set ' . date("Y-m-d H:i:s"), AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 20, AdSetFields::DAILY_BUDGET => 1000, AdSetFields::CAMPAIGN_ID => $campaignId, AdSetFields::TARGETING => (new TargetingSpecs())->setData(array(TargetingSpecsFields::GEO_LOCATIONS => array('countries' => array('US'))))));
     $adset->create(array(AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED));
     return $adset->getData()[AdSet::FIELD_ID];
 }
 /**
  * @param mixed $objectId
  * @param array $params
  *
  * @return \Illuminate\Support\Collection
  */
 public function getInsights($objectId, $params = [])
 {
     $fields = $params['fields'];
     unset($params['fields']);
     $adSet = new AdSet($objectId);
     $insights = $adSet->getInsights($fields, $params);
     return $this->response($insights);
 }
Esempio n. 3
0
 public function getAdSets(array $fields = array(), array $params = array(), $pending = false)
 {
     $this->assureId();
     $param_types = array();
     $enums = array();
     $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_GET, '/adsets', new AdSet(), 'EDGE', AdSet::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums));
     $request->addParams($params);
     $request->addFields($fields);
     return $pending ? $request : $request->execute();
 }
 public function tearDown()
 {
     if ($this->adSet) {
         $this->adSet->delete();
         $this->adSet = null;
     }
     if ($this->adCampaign) {
         $this->adCampaign->delete();
         $this->adCampaign = null;
     }
     if ($this->adCreative) {
         $this->adCreative->delete();
         $this->adCreative = null;
     }
     if ($this->adImage) {
         $this->adImage->delete();
         $this->adImage = null;
     }
     parent::tearDown();
 }
 public function testDynamicProductAdsCreation()
 {
     $this->adCampaign = new AdCampaign(null, $this->getConfig()->accountId);
     $this->adCampaign->setData(array(AdCampaignFields::NAME => $this->getConfig()->testRunId, AdCampaignFields::OBJECTIVE => AdObjectives::PRODUCT_CATALOG_SALES, AdCampaignFields::PROMOTED_OBJECT => array('product_catalog_id' => $this->productCatalog->{ProductCatalogFields::ID})));
     $this->assertCanCreate($this->adCampaign);
     $targeting = new TargetingSpecs();
     $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('US'));
     $targeting->{TargetingSpecsFields::DYNAMIC_AUDIENCE_IDS} = array($this->productAudience->{ProductAudienceFields::ID});
     $this->adSet = new AdSet(null, $this->getConfig()->accountId);
     $this->adSet->setData(array(AdSetFields::NAME => $this->getConfig()->testRunId, AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::LINK_CLICKS, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 2, AdSetFields::DAILY_BUDGET => 2000, AdSetFields::CAMPAIGN_GROUP_ID => $this->adCampaign->{AdCampaignFields::ID}, AdSetFields::TARGETING => $targeting, AdsetFields::PROMOTED_OBJECT => array('product_set_id' => $this->productSet->{ProductSetFields::ID})));
     $this->assertCanCreate($this->adSet);
     $template = new TemplateData();
     $template->setData(array(TemplateDataFields::DESCRIPTION => '{{product.description}}', TemplateDataFields::LINK => 'http://www.example.com/', TemplateDataFields::MESSAGE => 'Test DPA Ad Message', TemplateDataFields::NAME => '{{product.name | titleize}}', TemplateDataFields::MAX_PRODUCT_COUNT => 3, TemplateDataFields::CALL_TO_ACTION => array('type' => CallToActionTypes::SHOP_NOW)));
     $story = new ObjectStorySpec();
     $story->setData(array(ObjectStorySpecFields::PAGE_ID => $this->getConfig()->pageId, ObjectStorySpecFields::TEMPLATE_DATA => $template));
     $this->creative = new AdCreative(null, $this->getConfig()->accountId);
     $this->creative->setData(array(AdCreativeFields::NAME => $this->getConfig()->testRunId, AdCreativeFields::OBJECT_STORY_SPEC => $story, AdCreativeFields::PRODUCT_SET_ID => $this->productSet->{ProductSetFields::ID}));
     $this->assertCanCreate($this->creative);
     $this->adGroup = new AdGroup(null, $this->getConfig()->accountId);
     $this->adGroup->setData(array(AdGroupFields::NAME => 'DPA Test Ad 1 ' . $this->getConfig()->testRunId, AdGroupFields::CAMPAIGN_ID => $this->adSet->{AdSetFields::ID}, AdGroupFields::CREATIVE => array('creative_id' => $this->creative->{AdCreativeFields::ID})));
     $this->assertCanCreate($this->adGroup);
 }
Esempio n. 6
0
 /**
  * @param array $fields
  * @param array $params
  * @return Cursor
  */
 public function getAdSets(array $fields = array(), array $params = array())
 {
     return $this->getManyByConnection(AdSet::className(), $fields, $params);
 }
Esempio n. 7
0
 /**
  * @return array
  */
 public function getAllAds()
 {
     $returnAds = [];
     $ads = $this->account->getAds();
     foreach ($ads->getArrayCopy(true) as $ad) {
         $adData = $ad->getData();
         $tmpAd = new AdSet($adData['id']);
         $tmpAd->read([AdFields::ID, AdFields::NAME, AdFields::CAMPAIGN_ID, AdFields::CREATED_TIME, AdFields::VIEW_TAGS, AdFields::SOCIAL_PREFS, AdFields::AD_REVIEW_FEEDBACK]);
         $returnAdsets[] = $tmpAd->getData();
     }
     return $returnAds;
 }
use FacebookAds\Object\Fields\TargetingSpecsFields;
$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));
/**
 * Step 4 Create the AdSet
 */
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\OptimizationGoals;
use FacebookAds\Object\Values\BillingEvents;
$adset = new AdSet(null, $account->id);
$adset->setData(array(AdSetFields::NAME => 'My First AdSet', AdSetFields::CAMPAIGN_GROUP_ID => $campaign->id, AdSetFields::CAMPAIGN_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";
/**
 * Step 5 Create an AdImage
 */
use FacebookAds\Object\AdImage;
use FacebookAds\Object\Fields\AdImageFields;
$image = new AdImage(null, $account->id);
$image->{AdImageFields::FILENAME} = SDK_DIR . '/test/misc/image.png';
$image->create();
echo 'Image Hash: ' . $image->hash . "\n";
/**
 * Step 6 Create an AdCreative
 */
Esempio n. 9
0
 public function getAdSetsByLabels(array $fields = array(), array $params = array(), $pending = false)
 {
     $this->assureId();
     $param_types = array('ad_label_ids' => 'list<string>', 'operator' => 'operator_enum');
     $enums = array('operator_enum' => AdSetOperatorValues::getInstance()->getValues());
     $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_GET, '/adsetsbylabels', new AdSet(), 'EDGE', AdSet::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums));
     $request->addParams($params);
     $request->addFields($fields);
     return $pending ? $request : $request->execute();
 }
Esempio n. 10
0
 public function getAdSets(array $fields = array(), array $params = array(), $pending = false)
 {
     $this->assureId();
     $param_types = array('ad_draft_id' => 'string', 'date_preset' => 'date_preset_enum', 'effective_status' => 'list<effective_status_enum>', 'is_completed' => 'bool', 'time_range' => 'map');
     $enums = array('date_preset_enum' => AdSetDatePresetValues::getInstance()->getValues(), 'effective_status_enum' => AdSetEffectiveStatusValues::getInstance()->getValues());
     $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_GET, '/adsets', new AdSet(), 'EDGE', AdSet::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums));
     $request->addParams($params);
     $request->addFields($fields);
     return $pending ? $request : $request->execute();
 }
 /**
  * @param array $fields
  * @param array $params
  * @return Cursor
  */
 public function getAdSetsByLabel(array $fields = array(), array $params = array())
 {
     return $this->getManyByConnection(AdSet::classname(), $fields, $params, 'adsetsbylabels');
 }
 * Step 2 Create the AdCampaign
 */
use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Fields\AdCampaignFields;
use FacebookAds\Object\Values\AdObjectives;
use FacebookAds\Object\Values\AdBuyingTypes;
$campaign = new AdCampaign(null, $account->id);
$campaign->setData(array(AdCampaignFields::NAME => 'My First Campaign', AdCampaignFields::OBJECTIVE => AdObjectives::WEBSITE_CLICKS, AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED));
$campaign->create();
echo "Campaign ID:" . $campaign->id . "\n";
/**
 * Step 3 Create the AdSet
 */
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
$adset = new AdSet(null, $account->id);
$adset->setData(array(AdSetFields::NAME => 'My First AdSet', AdSetFields::CAMPAIGN_GROUP_ID => $campaign->id, AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_ACTIVE, AdSetFields::DAILY_BUDGET => '150', AdSetFields::START_TIME => (new \DateTime("+1 week"))->format(\DateTime::ISO8601), AdSetFields::END_TIME => (new \DateTime("+2 week"))->format(\DateTime::ISO8601)));
$adset->create();
echo 'AdSet  ID: ' . $adset->id . "\n";
/**
 * Step 4 Create an AdImage
 */
use FacebookAds\Object\AdImage;
use FacebookAds\Object\Fields\AdImageFields;
$image = new AdImage(null, $account->id);
$image->filename = SDK_DIR . '/test/misc/FB-f-Logo__blue_512.png';
$image->create();
echo 'Image Hash: ' . $image->hash . "\n";
/**
 * Step 5 Create an AdCreative
 */
Esempio n. 13
0
 public function updateSelf(array $fields = array(), array $params = array(), $pending = false)
 {
     $this->assureId();
     $param_types = array('account_id' => 'string', 'adlabels' => 'list<Object>', 'adset_schedule' => 'list<Object>', 'attribution_window_days' => 'unsigned int', 'bid_amount' => 'int', 'billing_event' => 'billing_event_enum', 'creative_sequence' => 'list<string>', 'daily_budget' => 'unsigned int', 'daily_imps' => 'unsigned int', 'end_time' => 'datetime', 'execution_options' => 'list<execution_options_enum>', 'is_autobid' => 'bool', 'lifetime_budget' => 'unsigned int', 'lifetime_imps' => 'unsigned int', 'name' => 'string', 'optimization_goal' => 'optimization_goal_enum', 'pacing_type' => 'list<string>', 'promoted_object' => 'Object', 'redownload' => 'bool', 'rf_prediction_id' => 'string', 'start_time' => 'datetime', 'status' => 'status_enum', 'targeting' => 'Targeting', 'time_based_ad_rotation_id_blocks' => 'list<list<unsigned int>>', 'time_based_ad_rotation_intervals' => 'list<unsigned int>');
     $enums = array('billing_event_enum' => AdSetBillingEventValues::getInstance()->getValues(), 'execution_options_enum' => AdSetExecutionOptionsValues::getInstance()->getValues(), 'optimization_goal_enum' => AdSetOptimizationGoalValues::getInstance()->getValues(), 'status_enum' => AdSetStatusValues::getInstance()->getValues());
     $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_POST, '/', new AdSet(), 'NODE', AdSet::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums));
     $request->addParams($params);
     $request->addFields($fields);
     return $pending ? $request : $request->execute();
 }
use FacebookAds\Object\Fields\TargetingSpecsFields;
$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));
/**
 * Step 4 Create the AdSet
 */
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Fields\BidInfoFields;
use FacebookAds\Object\Values\BidTypes;
$adset = new AdSet(null, $account->id);
$adset->setData(array(AdSetFields::NAME => 'My First AdSet', AdSetFields::CAMPAIGN_GROUP_ID => $campaign->id, AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_ACTIVE, AdSetFields::DAILY_BUDGET => '150', AdSetFields::TARGETING => $targeting, AdSetFields::BID_TYPE => BidTypes::BID_TYPE_CPM, AdSetFields::BID_INFO => array(BidInfoFields::IMPRESSIONS => 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";
/**
 * Step 5 Create an AdImage
 */
use FacebookAds\Object\AdImage;
use FacebookAds\Object\Fields\AdImageFields;
$image = new AdImage(null, $account->id);
$image->{AdImageFields::FILENAME} = SDK_DIR . '/test/misc/image.png';
$image->create();
echo 'Image Hash: ' . $image->hash . "\n";
/**
 * Step 6 Create an AdCreative
 */
Esempio n. 15
0
// _DOC vars [ad_account_id:s, product_set_id_1, product_set_id_2, campaign_group_id]
// use FacebookAds\Object\AdSet;
// use FacebookAds\Object\Fields\AdSetFields;
// use FacebookAds\Object\Fields\TargetingSpecsFields;
$adset = new AdSet(null, $ad_account_id);
$adset->setData(array(AdSetFields::NAME => 'My cross sell ad set', AdSetFields::BID_AMOUNT => 3000, AdSetFields::BILLING_EVENT => BillingEvents::LINK_CLICKS, AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::LINK_CLICKS, AdSetFields::CAMPAIGN_STATUS => AdCampaign::STATUS_ACTIVE, AdSetFields::DAILY_BUDGET => 15000, AdSetFields::CAMPAIGN_GROUP_ID => $campaign_group_id, AdSetFields::TARGETING => array(TargetingSpecsFields::GEO_LOCATIONS => array('countries' => array('US')), TargetingSpecsFields::PRODUCT_AUDIENCE_SPECS => array(array('product_set_id' => $product_set_id_2, 'inclusions' => array(array('retention_seconds' => 432000, 'rule' => array('event' => array('eq' => 'ViewContent')))), 'exclusions' => array(array('retention_seconds' => 432000, 'rule' => array('event' => array('eq' => 'Purchase')))))), TargetingSpecsFields::EXCLUDED_PRODUCT_AUDIENCE_SPECS => array(array('product_set_id' => $product_set_id_2, 'inclusions' => array(array('retention_seconds' => 259200, 'rule' => array('event' => array('eq' => 'ViewContent'))))))), AdSetFields::PROMOTED_OBJECT => array('product_set_id' => $product_set_id_1), AdSetFields::PRODUCT_AD_BEHAVIOR => 'FALL_BACK_TO_FB_RECOMMENDATIONS'));
$adset->create();
// _DOC close [ADSET_CREATE_DYNAMIC_RETARGETING]
$adset->delete();
$campaign->delete();
$product_audience->delete();
$product_set->delete();
$product_catalog->delete();
// Create AdCampaign
$campaign = new AdCampaign(null, $ad_account_id);
$campaign->setData(array(AdCampaignFields::NAME => 'My First Campaign', AdCampaignFields::OBJECTIVE => AdObjectives::WEBSITE_CLICKS, AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED));
$campaign->create();
$campaign_group_id = $campaign->{AdCampaignFields::ID};
// _DOC open [ADSET_CREATE_DESKTOP]
// _DOC vars [ad_account_id:s, page_id:s, campaign_group_id]
// use FacebookAds\Object\AdSet;
// use FacebookAds\Object\Values\BillingEvents;
// use FacebookAds\Object\Values\OptimizationGoals;
// use FacebookAds\Object\Fields\AdSetFields;
// use FacebookAds\Object\Fields\TargetingSpecsFields;
$adset = new AdSet(null, $ad_account_id);
$adset->setData(array(AdSetFields::NAME => 'Desktop Ad Set', AdSetFields::CAMPAIGN_GROUP_ID => $campaign_group_id, AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_PAUSED, AdSetFields::DAILY_BUDGET => 10000, AdSetFields::TARGETING => (new TargetingSpecs())->setData(array(TargetingSpecsFields::PAGE_TYPES => array(PageTypes::DESKTOP_FEED), TargetingSpecsFields::GEO_LOCATIONS => array('countries' => array('BR')))), AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::POST_ENGAGEMENT, AdSetFields::BILLING_EVENT => BillingEvents::POST_ENGAGEMENT, AdSetFields::BID_AMOUNT => 1500));
$adset->create();
// _DOC close [ADSET_CREATE_DESKTOP]
$adset->delete();
$campaign->delete();
Esempio n. 16
0
use FacebookAds\Object\Fields\AdImageFields;
use FacebookAds\Object\TargetingSpecs;
use FacebookAds\Object\Values\AdObjectives;
use FacebookAds\Object\Values\BillingEvents;
use FacebookAds\Object\Values\OptimizationGoals;
use FacebookAdsTest\Config\Config;
/** @var Config $config */
$ad_account_id = $config->accountId;
$image_path = $config->testImagePath;
$app_url = $config->appUrl;
// Create AdCampaign
$campaign = new AdCampaign(null, $ad_account_id);
$campaign->setData(array(AdCampaignFields::NAME => 'My First Campaign', AdCampaignFields::OBJECTIVE => AdObjectives::WEBSITE_CLICKS, AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED));
$campaign->create();
// Create AdSet
$adset = new AdSet(null, $ad_account_id);
$adset->setData(array(AdSetFields::NAME => 'My First AdSet', AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 2, AdSetFields::TARGETING => (new TargetingSpecs())->setData(array('geo_locations' => array('countries' => array('US')))), AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_PAUSED, AdSetFields::DAILY_BUDGET => '150', AdSetFields::CAMPAIGN_GROUP_ID => $campaign->{AdCampaignFields::ID}));
$adset->create();
$ad_set_id = $adset->{AdSetFields::ID};
// Create AdImage
$image = new AdImage(null, $ad_account_id);
$image->{AdImageFields::FILENAME} = $image_path;
$image->create();
// Create AdCreative
$creative = new AdCreative(null, $ad_account_id);
$creative->setData(array(AdCreativeFields::NAME => 'Sample Creative', AdCreativeFields::TITLE => 'Welcome to the Jungle', AdCreativeFields::BODY => 'We\'ve got fun \'n\' games', AdCreativeFields::IMAGE_HASH => $image->{AdImageFields::HASH}, AdCreativeFields::OBJECT_URL => $app_url));
$creative->create();
$creative_id = $creative->{AdCreativeFields::ID};
// _DOC open [ADGROUP_CREATE]
// _DOC vars [ad_set_id:s, creative_id, ad_account_id:s]
// use FacebookAds\Object\AdGroup;