Reputation: 797
How can I generate the report CAMPAIGN_PERFORMANCE_REPORT
without downloading the file (for example just showing the result).
Here is actually what I do:
$reportQuery = 'SELECT CampaignId,CampaignName, Impressions, Clicks, Ctr , Cost '
. ' FROM CAMPAIGN_PERFORMANCE_REPORT '
. ' WHERE CampaignId = '.$campaignId.' DURING '.$date.','.$date;
// Download report.
ReportUtils::DownloadReportWithAwql($reportQuery, $filePath, $user,$reportFormat, $options);
$dataArray =file($filePath);
I download the file, then I read from the data to show it up.
Upvotes: 1
Views: 1255
Reputation: 2191
After a day I found the solution:
In the source of the lib the method DownloadReport of Utils/ReportUtils.php say that:
Downloads a new instance of an existing report definition. If the path parameter is specified it will be downloaded to the file at that path, otherwise it will be downloaded to memory and be returned as a string.
You can set NULL to path and use the return value
$filePath = null;
$stringOfResult = $reportUtils->DownloadReport($reportDefinition, $filePath, $user, $options);
//now you can parse the result
Upvotes: 0
Reputation: 797
Actualy i didn't found a way except that i generate that file then i read from it and i use that result :
$reportQuery = 'SELECT CampaignId,CampaignName, Impressions, Clicks, Ctr , ConversionRate '
. ' FROM CAMPAIGN_PERFORMANCE_REPORT '
. ' WHERE CampaignId = '.$id.' DURING '.$date.','.$date;
// Download report.
ReportUtils::DownloadReportWithAwql($reportQuery, $filePath, $user,$reportFormat, $options);
$dataArray =file($filePath);
foreach ($dataArray as $value) {
$data = explode(",", $value);
$resultat[$i-1]['jours'] = $date;
$resultat[$i-1]['impressions'] = $data[2];
$resultat[$i-1]['clicks'] = $data[3];
$resultat[$i-1]['taux_click'] = $data[4];
$resultat[$i-1]['taux_conversion'] = $data[5];
}
echo json_encode($resultat);
Hope it helps.
Upvotes: 3