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

Wrong page name is logged #194

Open
maxcl10 opened this issue Oct 31, 2024 · 4 comments
Open

Wrong page name is logged #194

maxcl10 opened this issue Oct 31, 2024 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@maxcl10
Copy link

maxcl10 commented Oct 31, 2024

I’m using the basic configuration and I noticed that the although the correct URL is saved, the previous page name is saved. I'm using a title resolver to update the page title. Any idea how to workaround this issue?

@tessa-meh
Copy link

We have the same issue. We are using the native TitleStrategy. We do see PageViewData being logged with the new URL, but with the old page title. We don't use custom TitleStrategy.

Angular version: 18.2.4
Plugin(s) versions:

  • "@microsoft/applicationinsights-analytics-js": "3.3.2",
  • "@microsoft/applicationinsights-angularplugin-js": "15.3.2",
  • "@microsoft/applicationinsights-web": "3.3.2",

Example of route:

{   
    path: 'settings',
    title: 'Settings',
}

@MSNev
Copy link
Contributor

MSNev commented Nov 12, 2024

The main SDK (which knows nothing about angular or any other framework) reads the page title from the document.title the actual code is here https://github.com/microsoft/ApplicationInsights-JS/blob/3dc9e3c34d59076d48d9519b88eb8f584d58538c/extensions/applicationinsights-analytics-js/src/JavaScriptSDK/Telemetry/PageViewManager.ts#L88-L92

So if the title has not change then you will continue to get the previous title, there can also be a race condition between when the page view is triggered (via the listeners) and when you update the title. Generally, when you change the browser URL (if using auto tracking) you should also change the title as the trackPageView is "generally" scheduled (via setTimeout(..., 0)) to run on the next JS execution cycle.

@wbeeftink
Copy link

wbeeftink commented Nov 14, 2024

That makes sense. Then anyone running into this should probably add an event handler of sorts and call .trackPageView() from there (with the correct page title). Right?

The sample project has a similar approach by subscribing to the router events:

this.router.events
.pipe(
filter(
(event): event is NavigationEnd => event instanceof NavigationEnd
)
)
.subscribe((event) => {
const activatedComponent = this.getActivatedComponent(event.state.root);
if (activatedComponent) {
this.appInsights.trackPageView({
name: activatedComponent.name,
uri: event.urlAfterRedirects,
});
}
});

Perhaps it would prevent confusion to touch upon this behaviour somewhere in the documentation. I can imagine people might expect the 'correct' page title to be logged when using the Angular plugin—at least when using the native title strategy Angular provides.

@MSNev MSNev added the documentation Improvements or additions to documentation label Nov 14, 2024
@MSNev
Copy link
Contributor

MSNev commented Nov 14, 2024

Agree, I've tagged as a documentation issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

6 participants