applicationinsights-web-ts
它能做什么
这个工具可以实时监控网页应用的性能和使用情况。它会收集用户与网站的互动信息,比如访问了哪些页面、点击了哪些按钮,以及是否出现错误。
适用场景
- ✓当你想了解真实用户如何使用你的网站时。
- ✓当你需要找出并修复用户浏览器中出现的错误时。
- ✓当你想了解用户的浏览路径和重要的点击行为时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/applicationinsights-web-ts/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何监控网站的性能,以及用户遇到的错误?”
每周 5 个新技能,1 分钟读完。
工作原理
你需要在网站中添加一小段代码,让它把数据发送到监控服务。该服务会整理这些数据,方便你查看。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Application Insights JavaScript SDK (Web) for TypeScript
When to Use
Use this skill when you need instrument browser/web apps with the Application Insights JavaScript SDK (@microsoft/applicationinsights-web). Use for Real User Monitoring (RUM) — page views, clicks, AJAX/fetch dependencies, exceptions, custom events, and browser-side GenAI agent traces correlated to backend...
Real User Monitoring (RUM) for browser apps with @microsoft/applicationinsights-web. Auto-collects page views, AJAX/fetch dependencies, unhandled exceptions, and (with the Click Analytics plugin) clicks. Supports custom events, metrics, and GenAI agent traces that follow OpenTelemetry GenAI semantic conventions and correlate to backend spans via W3C Trace Context.
Distinct from
azure-monitor-opentelemetry-ts, which is for Node.js server apps. This skill is for browser/web code (and React Native).
Before Implementation
Search microsoft-docs MCP for current API patterns:
- Query: "Application Insights JavaScript SDK setup"
- Query: "Application Insights JavaScript SDK configuration"
- Query: "Application Insights JavaScript framework extensions React Angular"
- Verify package version:
npm view @microsoft/applicationinsights-web version
Packages
| Package | Purpose |
|---|---|
@microsoft/applicationinsights-web |
Core RUM SDK (page views, AJAX, exceptions). |
@microsoft/applicationinsights-clickanalytics-js |
Auto-collect click telemetry. |
@microsoft/applicationinsights-react-js |
React plugin (router instrumentation, hooks, HOC, ErrorBoundary). |
@microsoft/applicationinsights-react-native |
React Native plugin (native crashes, sessions). |
@microsoft/applicationinsights-angularplugin-js |
Angular plugin (router events, ErrorHandler). |
@microsoft/applicationinsights-debugplugin-js |
Dev-only telemetry inspector. |
@microsoft/applicationinsights-perfmarkmeasure-js |
User Timing (performance.mark/measure) integration. |
Installation
npm i --save @microsoft/applicationinsights-web
# Optional plugins (install only what you use):
npm i --save @microsoft/applicationinsights-clickanalytics-js
npm i --save @microsoft/applicationinsights-react-js @microsoft/applicationinsights-react-native @microsoft/applicationinsights-angularplugin-js
Typings ship with the package — no separate @types/... install needed.
Connection String
The browser SDK requires a connection string at init time. It ships in plaintext to clients — Microsoft Entra ID auth is not supported for browser telemetry. Use a separate App Insights resource with local auth enabled for browser RUM if you need to isolate it from backend telemetry.
# Vite / CRA / Next.js — expose to client via the public env prefix
VITE_APPINSIGHTS_CONNECTION_STRING="InstrumentationKey=...;IngestionEndpoint=https://...;LiveEndpoint=https://..."
NEXT_PUBLIC_APPINSIGHTS_CONNECTION_STRING="InstrumentationKey=..."
Quick Start (npm)
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
export const appInsights = new ApplicationInsights({
config: {
connectionString: import.meta.env.VITE_APPINSIGHTS_CONNECTION_STRING,
enableAutoRouteTracking: true, // SPA route changes -> page views
enableCorsCorrelation: true, // propagate Request-Id / traceparent to cross-origin AJAX
enableRequestHeaderTracking: true,
enableResponseHeaderTracking: true,
distributedTracingMode: 2, // DistributedTracingModes.AI_AND_W3C — emit traceparent for backend correlation
autoTrackPageVisitTime: true,
disableFetchTracking: false, // fetch() is auto-instrumented by default
excludeRequestFromAutoTrackingPatterns: [/livemetrics\.azure\.com/i]
}
});
appInsights.loadAppInsights();
appInsights.trackPageView();
Call loadAppInsights() exactly once, as early as possible (before user interactions you want tracked). Then trackPageView() for the initial load — when enableAutoRouteTracking is on, subsequent route changes are automatic.
Quick Start (SDK Loader Script)
Recommended when you want auto-updating SDK and zero build pipeline. Paste this as the first <script> in <head>:
<script type="text/javascript" src="https://js.monitor.azure.com/scripts/b/ai.3.gbl.min.js" crossorigin="anonymous"></script>
<script type="text/javascript">
var appInsights = window.appInsights || function (cfg) {
…
常见问题
这适用于移动应用吗?
适用于使用 React Native 开发的应用。React Native 是一种可以同时在 Android 和 iOS 上运行的应用开发框架。
要追踪点击,需要额外安装东西吗?
需要。如果想自动追踪点击,你需要额外安装一个名为 `@microsoft/applicationinsights-clickanalytics-js` 的包。
监控代码应该放在哪里?
最好尽早放在网页加载过程中,通常是放在 `<head>` 中,或者放在主脚本的最开头。
详情
作者的原始描述
Instrument browser/web apps with the Application Insights JavaScript SDK (@microsoft/applicationinsights-web).
热度
- GitHub 星标
- 48k
- 排名
- #3807
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。