public function testCreateCampaignStats() { $config = (include __DIR__ . '/config.php'); $campaigns = $this->ads->getAdSetsFromAccount($config['account_id']); $campaign_ids = \ebussola\facebook\ads\adcampaign\AdCampaignHelper::extractIds($campaigns); $campaign_report = $this->facebook->createCampaignStats($campaign_ids, new DateTime('-30 days'), new DateTime('today')); $this->assertInstanceOf('\\ebussola\\ads\\reports\\facebook\\campaignstats\\CampaignStatsReport', $campaign_report); foreach ($campaign_report as $campaign_stats) { $this->assertInstanceOf('\\ebussola\\ads\\reports\\facebook\\CampaignStats', $campaign_stats); } }
/** * @param $campaign_ids * @param \DateTime $date_start * @param \DateTime $date_end * @param $stats_data * * @return array */ private function _createDailyCampaignStats($campaign_ids, \DateTime $date_start, \DateTime $date_end) { $data_columns = $this->getCampaignFields(); $filters = array(ReportStatsHelper::createFilter('campaign_id', 'in', $campaign_ids)); $stats = $this->ads->getDailyReportStats($this->account_id, $data_columns, $filters, $date_start, $date_end); $stats_report = new CampaignStatsReport(); foreach ($stats as $stats_data) { $stats = new \ebussola\ads\reports\facebook\campaignstats\CampaignStats($stats_data); $stats->refreshValues(); $stats_report->addStats($stats); } return $stats_report; }