microsoft / microsoft/ApplicationInsights-JS

Documentation for addTelemetryInitializer is unclear

Open
#1,008 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
TypeScript
Stars
685
Forks
261
Avg merge
21h 33m
Merged PRs (30d)
5

Description

I am trying to use addTelemetryInitializer as per the documentation but it is unclear because the docs (API-reference.md) refer to:
```
window.appInsights = appInsights;

// Add telemetry initializer
appInsights.trackPageView();
```
but the JS code from the portal does not look like that, it looks like this:
```
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var etc...
{
instrumentationKey:"key"
}); window[aiName] = aisdk,aisdk.queue && aisdk.queue.length ===0 && aisdk.trackPageView({});;
```
I tried splitting the last line and ended up with
```
}); window[aiName];
// Add my initializer here
aisdk.queue && aisdk.trackPageView({});
```
But this doesn't seem to work. The initializer is not called and I cannot see the call to track in the network monitor. Is there some more clear documentation about how this works with the new JS snippet?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with API-reference.md and compare its window.appInsights example with the JavaScript snippet generated by the portal. Clarify how addTelemetryInitializer and trackPageView relate to the snippet, including where an initializer belongs. Done means the documentation gives a working, unambiguous example for the portal-generated setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
documentation, observability
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.