From 8673557888738a21d6269fc4d5b6c2e23c55423c Mon Sep 17 00:00:00 2001 From: warna720 Date: Sun, 9 Jan 2022 18:45:18 +0100 Subject: [PATCH 1/2] Fix for geo + country lever results Same fix as #45 + allow for option to see results on country lever and not only city lever. Would be nice to get approved and a new release when/if everything ok! --- src/GTrends/GTrends.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/GTrends/GTrends.php b/src/GTrends/GTrends.php index 115fa4c..599a5f8 100644 --- a/src/GTrends/GTrends.php +++ b/src/GTrends/GTrends.php @@ -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 []; @@ -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']; @@ -186,9 +187,10 @@ 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'])); + var_dump($payload); if ($data = $this->getData(self::COMPARED_GEO_ENDPOINT, $payload)) { $results['GEO_MAP']['widget'] = $widget; $results['GEO_MAP']['data'] = From e06371d76f611a45039a7b34ae7307939e492c6f Mon Sep 17 00:00:00 2001 From: warna720 Date: Sun, 9 Jan 2022 18:46:38 +0100 Subject: [PATCH 2/2] Update GTrends.php --- src/GTrends/GTrends.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GTrends/GTrends.php b/src/GTrends/GTrends.php index 599a5f8..789761f 100644 --- a/src/GTrends/GTrends.php +++ b/src/GTrends/GTrends.php @@ -190,7 +190,6 @@ private function explore(array $keyWords, array $widgetIds, string $resolution = $widget['request']['resolution'] = $resolution; $widget['request']['includeLowSearchVolumeGeos'] = false; $payload['req'] = str_replace('"geo":[]', '"geo":{}', Json\Json::encode($widget['request'])); - var_dump($payload); if ($data = $this->getData(self::COMPARED_GEO_ENDPOINT, $payload)) { $results['GEO_MAP']['widget'] = $widget; $results['GEO_MAP']['data'] =