# Google Trends API

{% hint style="success" %}
To enable this engine, set the **`engine=google_trends`** parameter.
{% endhint %}

Google trends is a tool that returns data about the popularity of search queries. Being able to scrape Google Trends can give you an advantage over your competition or can be used in various marketing campaigns.

<figure><img src="https://1192456954-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9wbsYOleiAqS785aMtPp%2Fuploads%2F69R5S4WjitYy2AxpFN50%2Fgoogle-trends.png?alt=media&#x26;token=65ba1256-2e81-4c93-b724-b3722ecb504d" alt=""><figcaption><p>Scrape Google Trends Page</p></figcaption></figure>

### Google Trends API Integration Example

We will use following URL as an example for this request:

{% code overflow="wrap" %}

```
https://serpapi.webscrapingapi.com/v2?engine=google_trends&api_key=<YOUR_API_KEY>&geo=US&q=american%20football&date=2021-01-01%202022-01-01
```

{% endcode %}

### Ready to Use Google Trends API Scraping Scripts

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```bash
curl --request GET --url "https://serpapi.webscrapingapi.com/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01"
```

{% endcode %}
{% endtab %}

{% tab title="NodeJS" %}
{% code overflow="wrap" %}

```javascript
const http = require("https");

const options = {
  "method": "GET",
  "hostname": "serpapi.webscrapingapi.com",
  "port": null,
  "path": "/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01",
  "headers": {}
};

const req = http.request(options, function (res) {
  const chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    const body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end()2
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code overflow="wrap" %}

```python
import http.client

conn = http.client.HTTPSConnection("serpapi.webscrapingapi.com")

conn.request("GET", "/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01")

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code overflow="wrap" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://serpapi.webscrapingapi.com/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code overflow="wrap" %}

```go
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://serpapi.webscrapingapi.com/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code overflow="wrap" %}

```java
HttpResponse<String> response = Unirest.get("https://serpapi.webscrapingapi.com/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01")
  .asString();
```

{% endcode %}
{% endtab %}

{% tab title=".NET" %}
{% code overflow="wrap" %}

```csharp
var client = new RestClient("https://serpapi.webscrapingapi.com/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code overflow="wrap" %}

```ruby
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://serpapi.webscrapingapi.com/v2?engine=google_trends&api_key=YOUR_API_KEY&geo=US&q=american%20football&date=2021-01-01%202022-01-01")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Google Trends API Parameters

#### #1: Query Parameter

<table><thead><tr><th width="187">Parameter</th><th width="107" align="center">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>q</code></td><td align="center"><code>string</code></td><td>The keyword that you are searching for (the query).</td></tr></tbody></table>

#### #2: Request Customization Parameters

<table><thead><tr><th width="184">Parameter</th><th width="106" align="center">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>geo</code></td><td align="center"><code>string</code></td><td>The location you want to find the results for. It defaults to <code>worldwide</code>.<br><br>For a full list of supported <code>geo</code> options, feel free to check our <a href="google-trends-api/geo-parameter-options-list">list</a>.</td></tr><tr><td><code>date</code></td><td align="center"><code>string</code></td><td><p>You must use the format <code>YYYY-MM-DD YYYY-MM-DD</code> or one of the predefined values: </p><ul><li><code>now 1-H</code>, past 1 hour</li><li><code>now 4-H</code>, past 4 hours</li><li><code>now 1-d</code>, past day</li><li><code>now 7-d</code>, past 7 days</li><li><code>today 1-m</code>, past 30 days</li><li><code>today 3-m</code>, past 90 days</li><li><code>today 12-m</code>, past 12 months (default)</li><li><code>today 5-y</code> , past 5 years</li></ul></td></tr><tr><td><code>cat</code></td><td align="center"><code>string</code></td><td>This is the category parameter. You can find the full list of Google Trends categories <a href="google-trends-api/google-trends-categories-list">here</a>.</td></tr><tr><td><code>gprop</code></td><td align="center"><code>string</code></td><td><p>This parameter specifies the Google property to filter on. Possible values are: </p><ul><li><code>images</code></li><li><code>news</code></li><li><code>froogle</code> (for Google Shopping)</li><li><code>youtube</code></li></ul><p>If unspecified, it defaults to web search.</p></td></tr></tbody></table>

<details>

<summary>Response Example</summary>

```
{
    "widgets": [
        {
            "data": {
                "default": {
                    "timelineData": [],
                    "averages": []
                }
            },
            "id": "TIMESERIES",
            "type": "fe_line_chart",
            "title": "Interest over time"
        },
        {
            "data": {
                "default": {
                    "geoMapData": [
                        {
                            "geoCode": "US-AK",
                            "geoName": "Alaska",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-AL",
                            "geoName": "Alabama",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-AR",
                            "geoName": "Arkansas",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-AZ",
                            "geoName": "Arizona",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-CA",
                            "geoName": "California",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-CO",
                            "geoName": "Colorado",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-CT",
                            "geoName": "Connecticut",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-DC",
                            "geoName": "District of Columbia",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-DE",
                            "geoName": "Delaware",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-FL",
                            "geoName": "Florida",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-GA",
                            "geoName": "Georgia",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-HI",
                            "geoName": "Hawaii",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-IA",
                            "geoName": "Iowa",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-ID",
                            "geoName": "Idaho",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-IL",
                            "geoName": "Illinois",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-IN",
                            "geoName": "Indiana",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-KS",
                            "geoName": "Kansas",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-KY",
                            "geoName": "Kentucky",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-LA",
                            "geoName": "Louisiana",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-MA",
                            "geoName": "Massachusetts",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-MD",
                            "geoName": "Maryland",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-ME",
                            "geoName": "Maine",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-MI",
                            "geoName": "Michigan",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-MN",
                            "geoName": "Minnesota",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-MO",
                            "geoName": "Missouri",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-MS",
                            "geoName": "Mississippi",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-MT",
                            "geoName": "Montana",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-NC",
                            "geoName": "North Carolina",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-ND",
                            "geoName": "North Dakota",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-NE",
                            "geoName": "Nebraska",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-NH",
                            "geoName": "New Hampshire",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-NJ",
                            "geoName": "New Jersey",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-NM",
                            "geoName": "New Mexico",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-NV",
                            "geoName": "Nevada",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-NY",
                            "geoName": "New York",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-OH",
                            "geoName": "Ohio",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-OK",
                            "geoName": "Oklahoma",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-OR",
                            "geoName": "Oregon",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-PA",
                            "geoName": "Pennsylvania",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-RI",
                            "geoName": "Rhode Island",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-SC",
                            "geoName": "South Carolina",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-SD",
                            "geoName": "South Dakota",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-TN",
                            "geoName": "Tennessee",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-TX",
                            "geoName": "Texas",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-UT",
                            "geoName": "Utah",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-VA",
                            "geoName": "Virginia",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-VT",
                            "geoName": "Vermont",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-WA",
                            "geoName": "Washington",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-WI",
                            "geoName": "Wisconsin",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-WV",
                            "geoName": "West Virginia",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        },
                        {
                            "geoCode": "US-WY",
                            "geoName": "Wyoming",
                            "value": [
                                0
                            ],
                            "formattedValue": [
                                ""
                            ],
                            "maxValueIndex": 0,
                            "hasData": [
                                false
                            ]
                        }
                    ]
                }
            },
            "id": "GEO_MAP",
            "type": "fe_geo_chart_explore",
            "title": "Interest by subregion"
        },
        {
            "data": {
                "default": {
                    "rankedList": [
                        {
                            "rankedKeyword": []
                        },
                        {
                            "rankedKeyword": []
                        }
                    ]
                }
            },
            "id": "RELATED_TOPICS",
            "type": "fe_related_searches",
            "title": "Related topics"
        },
        {
            "data": {
                "default": {
                    "rankedList": [
                        {
                            "rankedKeyword": []
                        },
                        {
                            "rankedKeyword": []
                        }
                    ]
                }
            },
            "id": "RELATED_QUERIES",
            "type": "fe_related_searches",
            "title": "Related queries"
        }
    ],
    "keywords": [
        {
            "keyword": "american%20football",
            "name": "american%20football",
            "type": "Search term"
        }
    ]
}
```

</details>
