Skip to content

Instantly share code, notes, and snippets.

@karakanb
Last active July 18, 2016 12:09
Show Gist options
  • Save karakanb/072d144a4c72c3728b3b769287a07ff3 to your computer and use it in GitHub Desktop.
Save karakanb/072d144a4c72c3728b3b769287a07ff3 to your computer and use it in GitHub Desktop.
// Burdaki gibi çağırman lazım
$fields = array('searchTerm', 'clicks', 'impressions', 'convertedClicks', 'cost', 'totalConvValue', 'day');
$parameters['ignoreDimensions'] = array('day');
$searchTerms = AdProReports::DownloadSearchTermReport($fields,30, $parameters);
//Bu da search term methodu
public static function DownloadSearchTermReport($fields, $range = 30, $parameters = array()){
// Type of the report.
$reportType = 'SEARCH_QUERY_PERFORMANCE_REPORT';
// Download the report.
$rows = Self::DownloadReport($reportType, $fields, $range, $parameters);
$allData = array();
$valueFields = Self::GetValueFields($fields);
if(in_array('day', $fields)){
// Get the dimension fields.
$dimensionFields = Self::GetDimensionFields($fields);
if(isset($parameters['ignoreDimensions'])){
// Format the fields and store the day as a value of the array.
foreach($rows as $row) {
$dimensions = Self::FormatFields($dimensionFields, $row);
$formattedValues = Self::FormatFields($valueFields, $row);
// For all 'ignore dimension' fields, save them as value instead of dimension.
foreach($parameters['ignoreDimensions'] as $ignoreDimension){
if(isset($dimensions[$ignoreDimension])){ // If that dimension has been set by report fields, make it value.
$formattedValues[$ignoreDimension] = $dimensions[$ignoreDimension];
}
}
$allData[] = $formattedValues;
}
}
else{
// Format the fields and store them with day as the dimension of the array.
foreach($rows as $row) {
$dimensions = Self::FormatFields($dimensionFields, $row);
$allData[$dimensions['day']][] = Self::FormatFields($valueFields, $row);
}
}
}
else{
// Format the fields and store them in an array.
foreach($rows as $row) {
$allData[] = Self::FormatFields($valueFields, $row);
}
}
return $allData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment