-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Track page visit duration #49
base: main
Are you sure you want to change the base?
Conversation
- Added a no-op constructor for unit testing in net8.0. - Introduced `_pageVisitTimeTracking` to replace `_lastPageAppearing`. - Modified `OnAppearing` and `OnDisappearing` methods for improved page visit duration tracking. - Replaced `TrackPageViewAsync` with `TrackPageVisitTime` to log page visit times. - Updated `IInsightsProvider` interface to include the new tracking method. - Made various formatting and null-checking improvements.
Updated `TrackPageVisitTime` to accept `pageFullName` and `pageDisplayName` parameters for improved telemetry. Modified the `IInsightsProvider` interface to reflect these changes and added XML documentation for better readability. Removed the `duration` parameter from `TrackPageViewAsync` to simplify its signature. Updated the properties dictionary in `ApplicationInsightsProvider` to utilize the new parameters for more informative tracking.
- Updated `ApplicationInsightsProvider` to change the key for page URL and consolidate metrics into a single "Duration" metric. - Modified `IInsights` interface to remove `duration` from `TrackPageViewAsync` and added `TrackPageVisitTime` method. - Adjusted `Insights` class to reflect interface changes and implemented `TrackPageVisitTime`. - Improved formatting in `HasCrashed`, `SendCrashes`, and `ResetCrashes` methods for better readability.
Updated the `OnDisappearing` method in the `ApplicationInsightsProvider` class to use an index-based approach for retrieving the last page added. This change replaces the nullable tuple logic with `FindLastIndex`, improving efficiency by directly manipulating the list. The method now returns early if no last page is found, and the duration calculation is adjusted accordingly.
{ "Duration", pageVisitTime } | ||
}; | ||
|
||
Client.TrackEvent("PageVisitTime", properties, metrics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhindrik I've mostly copied what MS has done in their react library, the main difference is they are using TrackMetric
whereas I've used TrackEvent
, with custom metric parameters.
TrackMetric
can be used instead just by doing this -
Client.TrackMetric("PageVisitTime", pageVisitTime, properties);
I decided not to do this, due to the comment on the TrackMetric
method. As I haven't used metrics before I thought it be safer to stick with events, but feel free to change it to TrackMetric
instead (I'm just not sure about the ramifications of it)
A New custom event called
PageVisitTime
was added, with custom metrics added for theDuration
in milliseconds.In application insights, the new event looks like this -
![image](https://private-user-images.githubusercontent.com/6544051/412423710-2068b274-a62c-4b0d-a2f4-f8a750bca4d9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQ0OTYsIm5iZiI6MTczOTYxNDE5NiwicGF0aCI6Ii82NTQ0MDUxLzQxMjQyMzcxMC0yMDY4YjI3NC1hNjJjLTRiMGQtYTJmNC1mOGE3NTBiY2E0ZDkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTAwOTU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzBjM2VlMDA0OWIyMDYyNzY1NGU4YTkzNjIwZTk4ODExMGFkNThiZDFhNDhkZjQ2MjE2YmQ1NDM5NWM4MzhmYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.rAADGz4VXGmEAjDstAaFpbU-zTmMd4R8D175ZpyDA6g)
This fixes the timeline history of events,
![image](https://private-user-images.githubusercontent.com/6544051/412424426-0d2e09da-1250-4791-82a2-2fc245c61556.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQ0OTYsIm5iZiI6MTczOTYxNDE5NiwicGF0aCI6Ii82NTQ0MDUxLzQxMjQyNDQyNi0wZDJlMDlkYS0xMjUwLTQ3OTEtODJhMi0yZmMyNDVjNjE1NTYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTAwOTU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzEzOTI1ODdjOGExYWRmYTUwNTg5NGViMTkzZDk3NzBmZjFjNGEzMWU0OTYyNDA1NTEyOGE3YWRhMDM2YzE1NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.RXQTqxd944u9YsZrxsaTHcLiqqSyWQzyAXGNQUpD9Yk)
Page View
is tracked as the page loads andPageVisitTime
is tracked as the user leaves the page -#48