I want to get the Impressions of one Campain in per country.
my php code is here:
function Red_GA_GetCampainLocation($adWordsServices,$session,$timeMode)
{
$logDir = ROOT_PATH . '/logs/';
$tempName = uniqid();
$filePath = $logDir . $tempName.'.csv';
$selector = new Selector();
$selector->setFields(array('Id','CampaignId', 'Impressions'));
if (Red_GA_FindString($timeMode,"CUSTOM_DATE")) {
$infoArr = explode('|',$timeMode);
$tmpDate = new DateRange();
$tmpDate->setMin($infoArr[1]);
$tmpDate->setMax($infoArr[2]);
$selector->setDateRange($tmpDate);
$timeMode = "CUSTOM_DATE";
}
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->setSelector($selector);
$reportDefinition->setReportName('CAMPAIGN performance report #' . uniqid());
$reportDefinition->setDateRangeType($timeMode);
$reportDefinition->setReportType('CAMPAIGN_LOCATION_TARGET_REPORT');
$reportDefinition->setDownloadFormat('CSV');
$reportDownloader = new ReportDownloader($session);
$reportSettingsOverride = (new ReportSettingsBuilder())->includeZeroImpressions(false)->build();
$reportDownloadResult = $reportDownloader->downloadReport($reportDefinition, $reportSettingsOverride);
$reportDownloadResult->saveToFile($filePath);
$file = fopen($filePath,"r");
$res = array();
while(! feof($file))
{
$res[] =fgetcsv($file);
}
fclose($file);
unlink($filePath);
return $res;
}
the result is :
["Location","Campaign ID","Impressions"],
[" --","11xxxxxxxx","67351"]
the Location is --. and a total Impressions. in all country.
who can tell me, how can i get the result like these(show the Impressions of per country):
["Location","Campaign ID","Impressions"],
["2840","11xxxxxxxx","123"]
["2841","11xxxxxxxx","567"]
["2842","11xxxxxxxx","890"]
["2843","11xxxxxxxx","235"]