Skip to content

Commit

Permalink
Merge pull request #46 from warna720/patch-2
Browse files Browse the repository at this point in the history
Fix for geo + country lever results
  • Loading branch information
x-fran authored Jan 22, 2022
2 parents 088f802 + e06371d commit 66d29d3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/GTrends/GTrends.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ public function getRelatedSearchQueries(array $keyWords): array
return $this->explore($keyWords, ['RELATED_QUERIES']);
}

public function getComparedGeo(array $keyWords): array
public function getComparedGeo(array $keyWords, string $resolution = 'CITY'): array
{
return $this->explore($keyWords, ['GEO_MAP']);
return $this->explore($keyWords, ['GEO_MAP'], $resolution);
}

private function explore(array $keyWords, array $widgetIds): array
private function explore(array $keyWords, array $widgetIds, string $resolution = 'CITY'): array
{
if (count($keyWords) > 5) {
return [];
Expand All @@ -159,6 +159,7 @@ private function explore(array $keyWords, array $widgetIds): array
),
];


$results = [];
if ($data = $this->getData(self::GENERAL_ENDPOINT, $payload)) {
$widgets = Json\Json::decode(trim(substr($data, 5)), Json\Json::TYPE_ARRAY)['widgets'];
Expand Down Expand Up @@ -186,9 +187,9 @@ private function explore(array $keyWords, array $widgetIds): array
);

if ($widget['id'] === 'GEO_MAP' && in_array('GEO_MAP', $widgetIds, true)) {
$widget['request']['resolution'] = 'CITY';
$widget['request']['resolution'] = $resolution;
$widget['request']['includeLowSearchVolumeGeos'] = false;
$payload['req'] = Json\Json::encode($widget['request']);
$payload['req'] = str_replace('"geo":[]', '"geo":{}', Json\Json::encode($widget['request']));
if ($data = $this->getData(self::COMPARED_GEO_ENDPOINT, $payload)) {
$results['GEO_MAP']['widget'] = $widget;
$results['GEO_MAP']['data'] =
Expand Down

0 comments on commit 66d29d3

Please sign in to comment.