kayforkind/skill-slice/applicationinsights-web-ts
Claude Code and agent skill by kayforkind/skill-slice
- community
Checking that the SKILL.md file is still in the repository.
Instrument browser/web apps with @microsoft/applicationinsights-web for Real User Monitoring (RUM), page views, clicks, AJAX/fetch dependencies, exceptions, custom events, and browser-side GenAI agent traces. Use when adding App Insights to React, Angular, Vite, Next.js, or React Native frontends. Not for Node.js server OpenTelemetry (azure-monitor-opentelemetry-ts).
Install
npx vskill@latest install kayforkind/skill-slice/applicationinsights-web-tsSKILL.md
The same SKILL.md was published earlier as kayforkind/skill-slice/applicationinsights-web-ts.
Application Insights JavaScript SDK (Web) for TypeScript
When to Use
Use this skill when you need to 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 spans via W3C Trace Context.
Trigger keywords: Application Insights, RUM, browser telemetry, @microsoft/applicationinsights-web, trackPageView, trackEvent, trackException, web vitals, GenAI agent traces, click analytics, SPA route tracking, distributed tracing browser.
Distinct from `azure-monitor-opentelemetry-ts`, which is for Node.js server apps. This skill is for browser/web code (and React Native).
Prerequisites
- Verify package version before coding:
``powershell npm view @microsoft/applicationinsights-web version ``
- 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"
- 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.
- Windows host (PowerShell) is primary. All shell commands below are PowerShell-compatible.
Procedure
1. Install Packages
Typings ship with the package — no separate @types/... install needed.
| 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. |
2. Expose Connection String to Client
3. Initialize (npm path)
HARD RULE: 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.
4. Alternative: SDK Loader Script (zero build pipeline)
Paste this as the first <script> in <head>:
Loader-only API (queued until SDK loads): trackEvent, trackPageView, trackException, trackTrace, trackDependencyData, trackMetric, trackPageViewPerformance, startTrackPage, stopTrackPage, startTrackEvent, stopTrackEvent, addTelemetryInitializer, setAuthenticatedUserContext, clearAuthenticatedUserContext, flush.
5. Core Tracking APIs
6. Telemetry Initializers (enrichment & filtering)
Run for every envelope before send. Return false to drop.
7. Click Analytics
Mark elements with data-ai-* attributes; clicks are emitted as Custom Events with parent-content metadata.
8. SPA Route Tracking
- Built-in: set
enableAutoRouteTracking: true. Hookshistory.pushState/replaceStateandpopstate. - React Router: use
@microsoft/applicationinsights-react-jswithAITrackingHOC. Use the React recipe in this file (step 11) and Microsoft Learn for Angular, Next.js, or Vite plugins. - Manual: call
appInsights.trackPageView({ name, uri })in your router'suseEffecton route change. DisableenableAutoRouteTrackingto avoid double counting.
9. Distributed Tracing (correlate to backend)
Set distributedTracingMode: 2 (DistributedTracingModes.AI_AND_W3C). The SDK adds traceparent (and legacy Request-Id) to outbound fetch/XHR. Backends instrumented with OpenTelemetry (e.g. @azure/monitor-opentelemetry) auto-link to the browser's operation_Id.
For cross-origin calls, also set enableCorsCorrelation: true and add the calling origin to the CORS exposed headers on the API.
10. GenAI Agent Traces (OTel semantic conventions)
When the browser invokes an AI agent (function-calling, tool-use, model calls direct from the client), emit App Insights Dependency telemetry whose attributes follow the OpenTelemetry GenAI semantic conventions so they are queryable alongside backend agent spans.
Set the opt-in env first so backend instrumentations agree on the same schema version:
Use the GenAI attribute tables and content-capture rules in this section when emitting traces. Full OTel names: https://opentelemetry.io/docs/specs/semconv/gen-ai/
Required attribute keys (use the OTel names verbatim)
| Span / op | Required attributes | |||
|---|---|---|---|---|
invoke_agent {agent.name} | gen_ai.operation.name=invoke_agent, gen_ai.provider.name, gen_ai.agent.name, gen_ai.agent.id (when known) | |||
create_agent {agent.name} | gen_ai.operation.name=create_agent, gen_ai.provider.name, gen_ai.agent.name, gen_ai.request.model | |||
chat {model} | gen_ai.operation.name=chat, gen_ai.provider.name, gen_ai.request.model, gen_ai.response.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens | |||
execute_tool {tool.name} | gen_ai.operation.name=execute_tool, gen_ai.tool.name, gen_ai.tool.type (function \ | extension \ | datastore), gen_ai.tool.call.id |
gen_ai.provider.name well-known values: openai, azure.ai.openai, azure.ai.inference, anthropic, aws.bedrock, gcp.gemini, gcp.vertex_ai, cohere, mistral_ai, groq, deepseek, perplexity, x_ai, ibm.watsonx.ai.
HARD RULE — Sensitive content opt-in.gen_ai.system_instructions,gen_ai.input.messages,gen_ai.output.messages,gen_ai.tool.call.arguments,gen_ai.tool.call.resultare Opt-In by default. Gate them behind a runtime flag and avoid them in production unless you have approved data handling.
Pattern: invoke_agent + nested tool/model spans
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/applicationinsights-web-ts/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kayforkind/skill-slice/applicationinsights-web-ts)