0

I am using ApplicationInsight as a ReactPlugin in a react nextjs application.

"@microsoft/applicationinsights-react-js": "^17.0.0",
"@microsoft/applicationinsights-web": "^3.0.2",

I want the user to be able to enabled / disable application insights due to privacy settings. I enable / load the plugin using AppInsights.loadAppInsights() and disable it by calling await AppInsights.unload(). When unloading i also delete the ai cookies since unloading does not do this (only ai_authUser is cleared by calling clearUserSession().

The problem is that the second load attempt throws an exception which basically says you cant load a second time.

Error: Core cannot be initialized more than once
    throwError throw.js:14
    _DynamicConstants__WEBPACK_IMPORTED_MODULE_3__._DYN_INITIALIZE AppInsightsCore.js:215
    loadAppInsights AISku.js:177
    doPerf PerfManager.js:183
    loadAppInsights AISku.js:175

Does somebody know what would be the right approach to enable/disable AppInsights? Is there another intended way than load/unload. Thanks for your insights ;)

Diego Frehner
  • 2,396
  • 1
  • 28
  • 35

0 Answers0