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); }
$object_story_spec = new ObjectStorySpec(); $object_story_spec->setData(array(ObjectStorySpecFields::PAGE_ID => $page_id, ObjectStorySpecFields::TEMPLATE_DATA => (new TemplateData())->setData(array('call_to_action' => array('type' => 'SHOP_NOW'), 'message' => 'Test {{product.name | titleize}}', 'link' => $link, 'name' => 'Headline {{product.price}}', 'description' => 'Description {{product.description}}')))); $creative = new AdCreative(null, $ad_account_id); $creative->setData(array(AdCreativeFields::NAME => 'Dynamic Ad Template Creative Sample', AdCreativeFields::APPLINK_TREATMENT => 'deeplink_with_web_fallback', AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec, AdCreativeFields::PRODUCT_SET_ID => $product_set_id)); $creative->create(); // _DOC close [ADCREATIVE_CREATE_DPA_DEEPLINK] $creative->delete(); $product_set_id_1 = $product_set_id; // _DOC open [ADCREATIVE_CREATE_DPA_RETARGETING] // _DOC vars [ad_account_id:s, page_id, link:s, product_set_id_1] // use FacebookAds\Object\AdCreative; // use FacebookAds\Object\ObjectStorySpec; // use FacebookAds\Object\ObjectStory\TemplateData; // use FacebookAds\Object\Fields\AdCreativeFields; // use FacebookAds\Object\Fields\ObjectStorySpecFields; $object_story_spec = new ObjectStorySpec(); $object_story_spec->setData(array(ObjectStorySpecFields::PAGE_ID => $page_id, ObjectStorySpecFields::TEMPLATE_DATA => (new TemplateData())->setData(array('message' => 'Test {{product.name | titleize}}', 'link' => $link, 'name' => 'Headline {{product.price}}', 'description' => 'Description {{product.description}}', 'max_product_count' => 3)))); $creative = new AdCreative(null, $ad_account_id); $creative->setData(array(AdCreativeFields::NAME => 'Dynamic Ad Template Creative Sample', AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec, AdCreativeFields::PRODUCT_SET_ID => $product_set_id_1)); $creative->create(); // _DOC close [ADCREATIVE_CREATE_DPA_RETARGETING] $creative_id = $creative->{AdCreativeFields::ID}; $creative->delete(); $feed->delete(); $product_set->delete(); $product_catalog->delete(); // FIXME excluded from runtime return; $retailer_id = 'rid'; // _DOC open [ADCREATIVE_READ_DPA_PREVIEW] // _DOC vars [creative_id, catalog_id, retailer_id:s]