Last active
July 18, 2016 12:09
-
-
Save karakanb/072d144a4c72c3728b3b769287a07ff3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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