Skip to content

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Google Trends API

Get Google Trends interest over time, geographic interest, and related searches. The examples call the hosted Apify Actor and return its default dataset as JSON.

Quick start

Set APIFY_TOKEN in your shell using your Apify integrations settings. Run one example from the repository root. Each live invocation starts a separate run and may incur charges.

Client Install Run
Python 3.11+ python3 -m pip install 'apify-client>=3,<4' python3 examples/python/run.py
Node.js 20+ npm install --no-save --package-lock=false apify-client@2 node examples/node/run.mjs
curl 7.55+ and Bash Use the system curl and Bash bash examples/curl/run.sh

Use --dry-run to print the input without installing the SDK, setting a token, or starting a run. To use your own input, pass its JSON file path as an argument. The SDK examples wait for the run to finish. For runs that could take more than five minutes, use an SDK or the asynchronous runs API instead of the synchronous HTTP request.

Example input

Get three months of US interest and related queries for one search term. See the Actor input form for more options.

{
  "searchTerms": [
    "air fryer"
  ],
  "geo": "US",
  "timeframe": "today 3-m",
  "sections": [
    "interestOverTime",
    "relatedQueries"
  ]
}

Output fields

Selected dataset fields. Availability varies by record and input settings.

Field Meaning
keyword Search term
geoName Name of the selected geography
timeframe Requested time window
interestOverTime Normalized interest series when requested and available
relatedQueriesTop Top related queries when requested and available
relatedQueriesRising Rising related queries when requested and available
trendsUrl Link to the search on Google Trends

Pricing

Pricing checked on 2026-11-30 UTC. Prices are in USD per 1,000 events. Your Apify plan determines the tier. Check current pricing before running at scale.

Event FREE BRONZE SILVER GOLD PLATINUM DIAMOND When charged
Search term $1.19 $0.59 $0.29 $0.19 $0.19 $0.19 One search term's Google Trends data in your dataset (interest over time, regions, related queries). Terms Google has no data for are free.

SDK examples

The Python and Node.js scripts load the example JSON and read the token from APIFY_TOKEN. These are the functions they use to start a run and read its dataset.

Python

def run_actor(payload, token):
    from apify_client import ApifyClient

    client = ApifyClient(token=token)
    run = client.actor("deepmine/google-trends-api").call(run_input=payload)
    if run is None or run.status != "SUCCEEDED" or not run.default_dataset_id:
        raise RuntimeError("Actor run did not succeed; check Apify Console.")
    return list(client.dataset(run.default_dataset_id).iterate_items())

Node.js

export async function runActor(payload, token) {
  const { ApifyClient } = await import('apify-client');
  const client = new ApifyClient({ token });
  const run = await client.actor("deepmine/google-trends-api").call(payload);
  if (run?.status !== 'SUCCEEDED' || !run.defaultDatasetId) {
    throw new Error('Actor run did not succeed; check Apify Console.');
  }
  const dataset = client.dataset(run.defaultDatasetId);
  const records = [];
  for (let offset = 0; ; ) {
    const { items, total } = await dataset.listItems({ offset, limit: 1000 });
    records.push(...items);
    offset += items.length;
    if (items.length === 0 || offset >= total) return records;
  }
}

MCP

Merge mcp/config.json into your MCP client configuration and replace YOUR_APIFY_TOKEN in your local copy. The Apify MCP server runs via npx with Node.js 22 or later.

{
  "mcpServers": {
    "google-trends-api": {
      "command": "npx",
      "args": [
        "-y",
        "@apify/actors-mcp-server@0.23.0",
        "--tools",
        "deepmine/google-trends-api",
        "--no-telemetry-enabled"
      ],
      "env": {
        "APIFY_TOKEN": "YOUR_APIFY_TOKEN"
      }
    }
  }
}

Example prompt: Show US interest over time and rising queries for air fryer over the past three months.

n8n

Import n8n/workflow.json. In Run Actor, select a Header Auth credential with header name Authorization and value Bearer YOUR_APIFY_TOKEN, using your own token. Start the manual trigger to run the HTTP Request node and read the dataset.

FAQ

Are interest values search counts?
No. Google Trends reports normalized interest. Use compareTerms to put comma-separated terms on a common scale.

Can I preview the input without a run?
Yes. Append --dry-run to any command in the quick start.

The example code is available under the MIT License.

Releases

Packages

Contributors