@amplitude/storybook-addon-amplitude

中文文档
3.0.0发布于 2025/12/12MITTypeScriptESM + CJS近 30 天下载 7.4万

A storybook addon to capture events in Amplitude

原始使用文档
文档目录14 节
  1. Prerequisites
  2. Version Compatibility
  3. What does it do?
  4. Getting Started
  5. Example Charts
  6. Event Taxonomy
  7. User navigates to a new page
  8. User changes a story's args
  9. Troubleshooting
  10. Events not showing up in Amplitude?
  11. Storybook not loading?
  12. Contributing
  13. License
  14. Credits

storybook-addon-amplitude

A Storybook addon to capture events in Amplitude.

version MIT License Auto Release PRs Welcome All Contributors

Read the blog post here.

Prerequisites

  • Node.js 20 or higher
  • Storybook 9.0 or higher
  • An Amplitude account (free tier available)

Version Compatibility

Storybook VersionAddon Version
9.x3.x
8.x>= 2.1.0
7.x2.0.0-2.0.1
6.x1.x

What does it do?

The Amplitude Storybook addon emits events to Amplitude on two different occasions: when a user navigates to a new page and when a user changes a story's args.

Getting Started

The first thing you'll need to do is sign up for Amplitude. If you already have an account, great! If you don't, you can sign up here for free.

Once you have an account, you can create a new project which will have an associated API key.

Note: You may want to create both a prod project and a dev project so you can test without influencing your data

To do this, navigate to the Settings page.

Amplitude organization settings nav

Then, select Projects in the sidebar.

Amplitude projects nav

In the top right-hand corner, click the Create Project button and follow the instructions.

Amplitude create new project

Next, install the package as a devDependency in your project:

# Using yarn
yarn add @amplitude/storybook-addon-amplitude --dev

# Using npm
npm install @amplitude/storybook-addon-amplitude --save-dev

in storybook/main.js

module.exports: {
  addons: [
+   '@amplitude/storybook-addon-amplitude',
  ]
}

Then, set your Amplitude API keys in ./storybook/manager.js

window.AMPLITUDE_DEV_API_KEY = "<amplitude-dev-api-key>";
window.AMPLITUDE_PROD_API_KEY = "<amplitude-prod-api-key>";

If you want to post to the EU endpoint make sure to set the serverUrl option:

window.AMPLITUDE_OPTIONS = {
  serverUrl: "https://api.eu.amplitude.com/2/httpapi",
};

Read more: Configurations, Endpoints

If you are in a TypeScript project you might want to add the following declarations:

declare global {
  interface Window {
    AMPLITUDE_DEV_API_KEY: string;
    AMPLITUDE_PROD_API_KEY: string;
    AMPLITUDE_OPTIONS: {
      serverUrl?: string;
    };
  }
}

Now your Storybook will begin emitting events to your project in Amplitude. You're ready to start creating charts in Amplitude!

Example Charts

Weekly unique users viewing Storybook documentation

Amplitude weekly unique users chart

Most commonly referenced categories

Amplitude referenced categories chart

Most viewed components

Amplitude most viewed components chart

Components with most modified arguments

Amplitude most modified arguments chart

Event Taxonomy

User navigates to a new page

When a user switches to a new page, this addon emits an event to Amplitude that looks like this:

{
  event_type: "viewed documentation",
  event_properties: {
    category: "actions",
    page: "button"
  }
}

Tracking the event in this way allows you to build charts in Amplitude to show:

  1. How many people have viewed your Storybook over time
  2. What categories people are viewing most frequently
  3. What pages people are viewing most frequently

User changes a story's args

When a user changes a story's args, this addon emits an event that looks like this:

{
  event_type: "updated story args",
  event_properties: {
    category: "actions",
    page: "button"
  }
}

Tracking the event in this way allows you to build charts in Amplitude to answer:

  1. How often do people use the story args functionality?
  2. In which category of pages people update the story args most frequently?
  3. On which pages people update the story args most frequently?

Troubleshooting

Events not showing up in Amplitude?

  • Verify your API keys are correctly set in storybook/manager.ts
  • Set window.AMPLITUDE_OPTIONS = { logLevel: 4 }; in storybook/manager.ts and check your browser's console for any error messages
  • Ensure you're using the correct server URL for your region

Storybook not loading?

  • Make sure the addon is properly installed and configured in storybook/main.ts
  • Check that your Storybook version is compatible (9.0 or higher)

Contributing

We are always happy to receive contributions! Please refer to our CONTRIBUTING guidelines for more details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits

Owner: Amplitude Inc

Current Maintainer: Jimmy Wilson (@jimmynotjim)

Contributors:


Jimmy Wilson

🐛 💻 📖 💡 🚇 👀 ⚠️ 🔧

Mae Capozzi

🐛 💻 📖 💡 🚇 👀 ⚠️ 🔧

Jack McCloy

💻 🚇 👀

Tijmen van Gurp

💻

Kaelig Deloumeau-Prigent

💻

Slave Mitev

💻 📖 💡 🚇

Brian Soe

👀

Vu Nguyen

👀

This project follows the all-contributors specification. Contributions of any kind welcome!

版本与发布记录

@amplitude/storybook-addon-amplitude 共发布 106 个版本,首次发布于 2022/05/13;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.0.0latest2025/12/1210 个月前
3.0.0-next.2next2025/06/261.4 年前
2.1.1--canary.b68d272.0canary2025/06/251.4 年前
3.0.0--canary.63.e4ad693.12025/06/251.4 年前
3.0.0--canary.63.e4ad693.02025/06/251.4 年前
3.0.0-next.12025/06/251.4 年前

关于 @amplitude/storybook-addon-amplitude 的常见问题

@amplitude/storybook-addon-amplitude 是什么?

A storybook addon to capture events in Amplitude

如何安装 @amplitude/storybook-addon-amplitude?

在项目目录运行 npm install @amplitude/storybook-addon-amplitude,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:storybook(^9.0.0 || ^10.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@amplitude/storybook-addon-amplitude 支持 TypeScript 吗?

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

@amplitude/storybook-addon-amplitude 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@amplitude/storybook-addon-amplitude 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@amplitude/storybook-addon-amplitude 可以商用吗?

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

@amplitude/storybook-addon-amplitude 的下载量有多少?

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

@amplitude/storybook-addon-amplitude 还在维护吗?

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