private function createCampaign() { $campaign = new Campaign(null, 'act_' . $this->adAccountId); $campaign->setData(array(CampaignFields::NAME => 'My Campaign ' . date("Y-m-d H:i:s"), CampaignFields::OBJECTIVE => AdObjectives::VIDEO_VIEWS)); $campaign->create(array(Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED)); return $campaign->getData()[Campaign::FIELD_ID]; }
/** * Create campaign in Facebook * * @param array $data * @return FacebookAds\Object\Campaign */ public function createCampaign(array $data) { App::make('FacebookAdsAPI'); $campaign = new Campaign(null, $this->config['account_id']); $campaign->setData([CampaignFields::NAME => $data['name'], CampaignFields::OBJECTIVE => AdObjectives::LINK_CLICKS]); $campaign->validate()->create(); return $campaign; }
/** * @param mixed $objectId * @param array $params * * @return \Illuminate\Support\Collection */ public function getInsights($objectId, $params = []) { $fields = $params['fields']; unset($params['fields']); $campaign = new Campaign($objectId); $insights = $campaign->getInsights($fields, $params); return $this->response($insights); }
public function tearDown() { if ($this->adSet) { $this->adSet->delete(); $this->adSet = null; } if ($this->campaign) { $this->campaign->delete(); $this->campaign = 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->campaign = new Campaign(null, $this->getConfig()->accountId); $this->campaign->setData(array(CampaignFields::NAME => $this->getConfig()->testRunId, CampaignFields::OBJECTIVE => AdObjectives::PRODUCT_CATALOG_SALES, CampaignFields::PROMOTED_OBJECT => array('product_catalog_id' => $this->productCatalog->{ProductCatalogFields::ID}))); $this->assertCanCreate($this->campaign); $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_ID => $this->campaign->{CampaignFields::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::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->ad = new Ad(null, $this->getConfig()->accountId); $this->ad->setData(array(AdFields::NAME => 'DPA Test Ad 1 ' . $this->getConfig()->testRunId, AdFields::ADSET_ID => $this->adSet->{AdSetFields::ID}, AdFields::CREATIVE => array('creative_id' => $this->creative->{AdCreativeFields::ID}))); $this->assertCanCreate($this->ad); }
/** * Creates a new Facebook campaign. */ public function createNewCampaign($campaignName) { $campaign = new Campaign(null, $this->accountId); $campaign->setData(array(CampaignFields::NAME => $campaignName, CampaignFields::OBJECTIVE => AdObjectives::LINK_CLICKS)); $campaign->validate()->create(array(Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED)); }
public function getCampaignsByLabels(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' => CampaignOperatorValues::getInstance()->getValues()); $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_GET, '/campaignsbylabels', new Campaign(), 'EDGE', Campaign::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums)); $request->addParams($params); $request->addFields($fields); return $pending ? $request : $request->execute(); }
public function tearDown() { $this->campaign->delete(); $this->campaign = null; parent::tearDown(); }
public function getCampaigns(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, '/campaigns', new Campaign(), 'EDGE', Campaign::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums)); $request->addParams($params); $request->addFields($fields); return $pending ? $request : $request->execute(); }
public function updateSelf(array $fields = array(), array $params = array(), $pending = false) { $this->assureId(); $param_types = array('adlabels' => 'list<Object>', 'execution_options' => 'list<execution_options_enum>', 'name' => 'string', 'objective' => 'objective_enum', 'promoted_object' => 'Object', 'spend_cap' => 'unsigned int', 'status' => 'status_enum'); $enums = array('execution_options_enum' => CampaignExecutionOptionsValues::getInstance()->getValues(), 'objective_enum' => CampaignObjectiveValues::getInstance()->getValues(), 'status_enum' => CampaignStatusValues::getInstance()->getValues()); $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_POST, '/', new Campaign(), 'NODE', Campaign::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 getCampaignsByLabel(array $fields = array(), array $params = array()) { return $this->getManyByConnection(Campaign::classname(), $fields, $params, 'campaignsbylabels'); }
use FacebookAds\Object\AdAccount; use FacebookAds\Object\Fields\AdAccountFields; $account = (new AdAccount($account_id))->read(array(AdAccountFields::ID, AdAccountFields::NAME, AdAccountFields::ACCOUNT_STATUS)); echo "\nUsing this account: "; echo $account->id . "\n"; // Check the account is active if ($account->{AdAccountFields::ACCOUNT_STATUS} !== 1) { throw new \Exception('This account is not active'); } /** * Step 2 Create the Campaign */ use FacebookAds\Object\Campaign; use FacebookAds\Object\Fields\CampaignFields; use FacebookAds\Object\Values\AdObjectives; $campaign = new Campaign(null, $account->id); $campaign->setData(array(CampaignFields::NAME => 'My First Campaign', CampaignFields::OBJECTIVE => AdObjectives::LINK_CLICKS, CampaignFields::STATUS => Campaign::STATUS_PAUSED)); $campaign->validate()->create(); echo "Campaign ID:" . $campaign->id . "\n"; /** * Step 3 Search Targeting */ use FacebookAds\Object\TargetingSearch; use FacebookAds\Object\Search\TargetingSearchTypes; use FacebookAds\Object\TargetingSpecs; 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();