Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoTrackPageVisitTime = true causes error #826

Closed
josundt opened this issue Apr 8, 2019 · 1 comment
Closed

autoTrackPageVisitTime = true causes error #826

josundt opened this issue Apr 8, 2019 · 1 comment

Comments

@josundt
Copy link

josundt commented Apr 8, 2019

Application Insights JS SDK Version: 2.0.0-rc.1
Module format: UMD/Bundled
Problem files:
[node_modules]/@microsoft/applicationinsights-web/browser/ai.2.js
[node_modules]/@microsoft/applicationinsights-web/dist/applicationinsights-web.js

Description:

We get an error when calling appInsights.trackPageView() after setting configuration autoTrackPageVisitTime to true

Source line:

ApplicationInsights.prototype.trackPageView = function (pageView, customProperties) {
            try {
                this._pageViewManager.trackPageView(pageView, customProperties);
                if (this.config.autoTrackPageVisitTime) {
                    this._pageVisitTimeManager.trackPreviousPageVisit(pageView.name, pageView.uri);
                    // PS!!! The error occurs on the line above, saying _pageVisitTimeManager is undefined
               }
            []

Stack trace:

TypeError: Cannot read property 'trackPreviousPageVisit' of undefined
    at ApplicationInsights.trackPageView (node_modules\@microsoft\applicationinsights-web\dist\applicationinsights-web.js:2697:49)
    at Initialization.trackPageView (node_modules\@microsoft\applicationinsights-web\dist\applicationinsights-web.js:5771:31)

Suspected cause:

PageVisitTimeManager is missing in the bundling for the files in the folders "dist" and "browser" under "node_modules/@microsoft/applicationinsights-web".

Details:

The @microsoft/applicationinsigts-xxx packages are compiled/bundled into three formats in the folders under [node_modules/[packagename]: "browser", "dist" and "dist-esm".

The "dist-esm" folder contains ESM module format import statements and is referenced by the "module" property in package.json. For applications using WebPack this will become the perferred source files since WebPack prefers this when inspecting package.json.

The files in the "dist" and "browser" folders seem to be in a UMD module format, but they also seem to be bundled to include all the source code from the other depended-upon packages.

I expected the files under "browser" to be a no-modules alternative that allows you to simply add the script through a standard script element on an HTML page. (TIP: If this is the intent, this file may be referenced by a "browser" property in package.json, which it is currently not).

I then expected the files under "dist" to be in a UMD format - which it is - but I did not expect it to be bundled. In the application where we experience the problem we are still using AMD/RequireJS, and it would work fine to have UMD module format without bundling (it would require some more path configuration for RequireJS though).

Anyway: It seems like the PageVisitTimeManager class/module was left out in this bundling process, so whenever you set autoTrackPageVisitTime to true, an error is thrown when calling trackPageView().

PS! I have tested scripts under both "browser" and "dist", but I experience the same problem in both.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant