Azure Application Insights is a great tool for monitoring and analyzing your website. And quite easy to install. Just add client and server-side integrations and you are set. Right?
There are many things App Insights does right, but one thing it does wrong out of the box is page views tracking. By default App Insights use page title as page view name. Most websites have page names, like: "AppName PageName SomeId", which would result in having multiple versions of the same page in your stats. Example:
- BestApp Order 3242
- BestApp Order 234
- BestApp Order 874
Which could literally create thousands and thousands of different pages, where in reality there are only a few, which would make a further analysis (funnel, flows, events) meaningless.
What to do?
Luckily, App Insights allows event preprocessing at client side before sending them.
var name = item.name.replace("AppName", "");If you put your App/Product name in the title, you probably want to remove it from your event name, because it would just repeat itself everywhere.
appInsights && appInsights.queueyou should check for appInsights.queue because for some reason it can be not defined and it would cause an error.
if (telemetryItem.name.indexOf("Admin") !== -1)return false; returning false will cause event to be not recorded at all. There certain events/pages you most likely do not want to track, like admin part of the website.
There are two types of events which use page title as event name: PageView and PageViewPerformance. It makes sense to modify both of them.