Skip to content

Commit 66d29d3

Browse files
authored
Merge pull request #46 from warna720/patch-2
Fix for geo + country lever results
2 parents 088f802 + e06371d commit 66d29d3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/GTrends/GTrends.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ public function getRelatedSearchQueries(array $keyWords): array
130130
return $this->explore($keyWords, ['RELATED_QUERIES']);
131131
}
132132

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

138-
private function explore(array $keyWords, array $widgetIds): array
138+
private function explore(array $keyWords, array $widgetIds, string $resolution = 'CITY'): array
139139
{
140140
if (count($keyWords) > 5) {
141141
return [];
@@ -159,6 +159,7 @@ private function explore(array $keyWords, array $widgetIds): array
159159
),
160160
];
161161

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

188189
if ($widget['id'] === 'GEO_MAP' && in_array('GEO_MAP', $widgetIds, true)) {
189-
$widget['request']['resolution'] = 'CITY';
190+
$widget['request']['resolution'] = $resolution;
190191
$widget['request']['includeLowSearchVolumeGeos'] = false;
191-
$payload['req'] = Json\Json::encode($widget['request']);
192+
$payload['req'] = str_replace('"geo":[]', '"geo":{}', Json\Json::encode($widget['request']));
192193
if ($data = $this->getData(self::COMPARED_GEO_ENDPOINT, $payload)) {
193194
$results['GEO_MAP']['widget'] = $widget;
194195
$results['GEO_MAP']['data'] =

0 commit comments

Comments
 (0)