microsoft / ApplicationInsights-JS

Microsoft Application Insights SDK for JavaScript
MIT License
652 stars 242 forks source link

[BUG]: snippet sends pageView if enableAutoRouteTracking = false #2202

Open VitaliyPotapov opened 1 year ago

VitaliyPotapov commented 1 year ago

Description/Screenshot I'm using snippet to setup AppInsights in nextjs app. I track pageView events manually by watching route changes. So that I have enableAutoRouteTracking: false in my app Insights config. But when using snippet interface it always sends initial pageView event. Due to that I get duplicates for initial pageView events.

Steps to Reproduce

  1. Setup snippet with enableAutoRouteTracking = false
  2. Open page

    • OS/Browser: OSX, Chrome
    • SDK Version [e.g. 22]: "@microsoft/applicationinsights-web": "^3.0.3",
    • How you initialized the SDK: snippet

Expected behavior Snippet should not send pageView if enableAutoRouteTracking = false

Additional context

MSNev commented 12 months ago

Yes, this is by design so that the SDK completes initialization.

If you don't want this initial "pageview" then you can either not use the snippet, or add / include a telemetry initializer which will be called once the SDK has initialized (and is processing the backlog of queued events -- which will include this trackPageView) and then when you detect this just return false (to cause the event to be dropped).

The initial page view also includes a page view performace event and is the only trackPageview that will cause this performance event to be sent. The auto route tracking (generally) does not cause this event, the only exception is that when using npm packages the performance event is sent as part of the first trackPageview (which is also what happens here as part of this "queued" event).

github-actions[bot] commented 3 weeks ago

This Issue will be closed in 30 days. Please remove the "Stale" label or comment to avoid closure with no action.