@alkalisummer/google-trends-js

中文文档
0.3.7发布于 2025/09/22MITTypeScriptCommonJS零依赖近 30 天下载 7591

Google Trends API for Node.js

原始使用文档
文档目录20 节
  1. Installation
  2. Features
  3. Usage
  4. Importing
  5. Daily Trends
  6. Trending Articles
  7. Interest Over Time
  8. Real-Time Trends
  9. Autocomplete
  10. Explore
  11. Interest by Region
  12. API Reference
  13. DailyTrendingTopicsOptions
  14. RealTimeTrendsOptions
  15. ExploreOptions
  16. InterestByRegionOptions
  17. TrendingArticlesOptions
  18. InterestOverTimeOptions
  19. Development
  20. Building

@alkalisummer/google-trends-js

This is a TypeScript library that has been updated to incorporate the latest changes to the Google Trends API endpoints. This package provides a simple and type-safe way to access Google Trends data programmatically.

This API was developed based on @shaivpidadi/trends-js with some added and modified features.

The following changes and additions have been made:

  • Daily Trends : Added relatedKeywords and activeTime.
  • Trending Articles : Retrieves information about articles related to trending keywords.
  • Interest Over Time : Retrieves time-series interest data for trending keywords.

Installation

npm install @alkalisummer/google-trends-js

Features

  • Get daily trending topics
  • Get real-time trending topics
  • Get articles related to trending topics
  • Get autocomplete suggestions
  • Explore trends data
  • Get interest by region data
  • Get interest over time (timeline) for keywords
  • TypeScript support
  • Promise-based API

Usage

Importing

import GoogleTrendsApi from '@alkalisummer/google-trends-js';

Get daily trending topics for a specific region:

const result = await GoogleTrendsApi.dailyTrends({
  geo: 'US', // Default: 'US'
  hl: 'en', // Default: 'en'
});

// Result structure:
// {
//   data?: Array<{
//     keyword: string;
//     traffic: number;
//     trafficGrowthRate: number;
//     activeTime: Date;
//     relatedKeywords: string[];
//     articleKeys: ArticleKey[];
//   }>,
//   error?: GoogleTrendsError
// }
//

Get trending articles for specific article keys

You can retrieve articleKeys from the articleKeys field in the response returned by the dailyTrends method.

const result = await GoogleTrendsApi.trendingArticles({
  articleKeys: [[1, hl, geo]], // Array of article keys
  articleCount: 5, // Number of articles to get
});

// Result structure:
// {
//   data?: Array<{
//     title: string;
//     link: string;
//     mediaCompany: string;
//     pressDate: number[];
//     image: string;
//   }>,
//   error?: GoogleTrendsError
// }

Interest Over Time

Get interest over time data for a specific keyword:

const result = await GoogleTrendsApi.interestOverTime({
  keyword: 'bitcoin', // or an array of keywords
  geo: 'US', //Default: 'US'
  period: 'now 7-d', // Default: 'now 1-d'
  hl: 'en-US', // Default: 'en-US'
});

// Result structure:
// {
//   data?: {
//     keyword: string | string[];
//     dates: Date[];
//     values: number[][]; // one series per keyword (for single keyword: a single inner array)
//   },
//   error?: GoogleTrendsError
// }

Multiple keywords example:

const result = await GoogleTrendsApi.interestOverTime({
  keyword: ['bitcoin', 'ethereum'],
  geo: 'US',
  period: 'today 12-m',
});

if (result.data) {
  // result.data.values is number[][] where
  // values[i] corresponds to the i-th sorted date in result.data.dates
}

Get real-time trending topics:

const result = await GoogleTrendsApi.realTimeTrends({
  geo: 'US', // Default: 'US'
  trendingHours: 4, // Default: 4
});

// Result structure (wrapped):
// {
//   data?: Array<{
//     keyword: string;
//     traffic: number;
//     trafficGrowthRate: number;
//     activeTime: Date;
//     relatedKeywords: string[];
//     articleKeys: ArticleKey[];
//   }>,
//   error?: GoogleTrendsError
// }

Autocomplete

Get search suggestions for a keyword:

const suggestions = await GoogleTrendsApi.autocomplete(
  'bitcoin', // Keyword to get suggestions for
  'en-US', // Language (default: 'en-US')
);

if (suggestions.data) {
  // suggestions.data is string[]
}

Explore

Get widget data for a keyword:

const result = await GoogleTrendsApi.explore({
  keyword: 'bitcoin',
  geo: 'US', // Default: 'US'
  time: '2025-06-30 2025-07-01', // Default: 'now 1-d'
  category: 0, // Default: 0
  property: '', // Default: ''
  hl: 'en-US', // Default: 'en-US'
});

// Result structure:
// {
//   widgets: Array<{
//     id: string,
//     request: {...},
//     token: string
//   }>
// }

Interest by Region

Get interest data by region:

const result = await GoogleTrendsApi.interestByRegion({
  keyword: 'Stock Market', // Required - string or string[]
  startTime: new Date('2024-01-01'), // Optional - defaults: yesterday
  endTime: new Date(), // Optional - defaults to current date
  geo: 'US', // Optional - string or string[] - defaults to 'US'
  resolution: 'REGION', // Optional - 'COUNTRY' | 'REGION' | 'CITY' | 'DMA'
  hl: 'en-US', // Optional - defaults to 'en-US'
  timezone: -240, // Optional - defaults to local timezone
  category: 0, // Optional - defaults to 0
});

// Result structure:
// {
//   default: {
//     geoMapData: Array<{
//       geoCode: string,
//       geoName: string,
//       value: number[],
//       formattedValue: string[],
//       maxValueIndex: number,
//       hasData: boolean[],
//       coordinates?: {
//         lat: number,
//         lng: number
//       }
//     }>
//   }
// }

Example with multiple keywords and regions:

const result = await GoogleTrendsApi.interestByRegion({
  keyword: ['wine', 'peanuts'],
  geo: ['US-CA', 'US-VA'],
  startTime: new Date('2024-01-01'),
  endTime: new Date(),
  resolution: 'CITY',
});

API Reference

DailyTrendingTopicsOptions

interface DailyTrendingTopicsOptions {
  geo?: string; // Default: 'US'
  hl?: string; // Default: 'en'
}

RealTimeTrendsOptions

interface RealTimeTrendsOptions {
  geo: string;
  trendingHours?: number; // Default: 4
}

ExploreOptions

interface ExploreOptions {
  keyword: string | string[];
  geo?: string; // Default: 'US'
  time?: string; // Default: 'now 1-d'
  category?: number; // Default: 0
  property?: string; // Default: ''
  hl?: string; // Default: 'en-US'
}

InterestByRegionOptions

interface InterestByRegionOptions {
  keyword: string | string[]; // Required - search term(s)
  startTime?: Date; // Optional - start date
  endTime?: Date; // Optional - end date
  geo?: string | string[]; // Optional - geocode(s)
  resolution?: 'COUNTRY' | 'REGION' | 'CITY' | 'DMA'; // Optional
  hl?: string; // Optional - language code
  timezone?: number; // Optional - timezone offset
  category?: number; // Optional - category number
}

TrendingArticlesOptions

interface TrendingArticlesOptions {
  articleKeys: ArticleKey[]; // Required - array of article keys
  articleCount: number; // Required - number of articles to get
}

type ArticleKey = [number, string, string]; // [index, lang, geo]

InterestOverTimeOptions

interface InterestOverTimeOptions {
  keyword: string | string[]; // Required - search term(s)
  geo?: string; // Optional - geocode (default: 'US')
  period?: 'now 1-H' | 'now 4-H' | 'now 1-d' | 'now 7-d' | 'now 1-m' | 'today 3-m' | 'today 12-m' | 'today 5-y'; // Optional - time period (default: 'now 1-d')
  hl?: string; // Optional - language (default: 'en-US')
}

Development

Building


版本与发布记录

@alkalisummer/google-trends-js 共发布 30 个版本,首次发布于 2025/06/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.7latest2025/09/221.1 年前
0.3.62025/09/221.1 年前
0.3.52025/09/221.1 年前
0.3.42025/09/211.1 年前
0.3.32025/09/211.1 年前
0.3.22025/09/211.1 年前

关于 @alkalisummer/google-trends-js 的常见问题

@alkalisummer/google-trends-js 是什么?

Google Trends API for Node.js

如何安装 @alkalisummer/google-trends-js?

在项目目录运行 npm install @alkalisummer/google-trends-js,或使用 pnpm add / yarn add / bun add。

@alkalisummer/google-trends-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alkalisummer/google-trends-js 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@alkalisummer/google-trends-js 可以商用吗?

@alkalisummer/google-trends-js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alkalisummer/google-trends-js 的下载量有多少?

根据 npm 官方下载统计,@alkalisummer/google-trends-js 在 2026/10/06 – 2026/11/04 这 30 天内被下载 7,591 次,日均约 253 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alkalisummer/google-trends-js 还在维护吗?

最新版本 0.3.7 发布于 2025/09/22(1.1 年前);至今共发布 30 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/06/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。