ApplicationInsights-JS: [BUG] ClickAnalytics throwing errors in console

Having installed the latest applicationinsights-web and applicationinsights-clickanalytics-js packages, errors are occurring in the console.

Screenshot 2023-05-15 at 2 30 10 PM

caught TypeError: Cannot read properties of undefined (reading 'core')

Packages and versions installed are;

    "@microsoft/applicationinsights-clickanalytics-js": "^3.0.1",
    "@microsoft/applicationinsights-web": "^3.0.1",

And a snippet of how I’m installing is;

export const appInsightsPlugin = {
  install: (app: App, opts: AppInsightsOptions) => {
    const clickPluginInstance = new ClickAnalyticsPlugin()
    const clickPluginConfig = {
      autoCapture: true
    }

    const appInsightsConfig = {
      ...opts.config,
      extensions: [clickPluginInstance],
      extensionConfig: {
        [clickPluginInstance.identifier]: clickPluginConfig
      }
    }

    const appInsights = new ApplicationInsights({
      config: appInsightsConfig
    })

    appInsights.loadAppInsights()
    appInsightsPlugin.setupPageTracking(opts, app)
...

This is a Vue3 project - and Application Insights seems to run ok when loading without the Click Plugin.

If this is a mis-configuration - I’d expect an error indicating so, or something else to go on. 😃

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

Ok, I believe I found the issue and it’s caused by the new onConfigChange callback when a configuration items is changed which indirectly then causes a new _pageAction instance to be created which is passed this, however, the this won’t necessarily be the ClickAnalyticsPlugin instace – it should be _self

@cadriel Ahh, I didn’t notice, what a silly mistake. Thanks!

@antondrozd you’re installing with an incorrect package name, try;

npm i @microsoft/applicationinsights-clickanalytics-js@nightly3

I installed the nightly3 release in my project (both web and clickanalytics-js) and now have new errors;

Screenshot 2023-05-17 at 4 48 10 PM

If I drop theapplicationinsights-web package back to 3.0.1 (but keep clickanalaytics-js at nightly3) then I see no errors in the console.

I assume the server side app insights needs some internal version bump too?