#1702 use tracking event
67c07a15
Michael Schmitz
committed
succeeded
2 changed files
NavigationHistory.cs
/WPE.App.Services/Navigation/NavigationHistory.cs-3+14
/WPE.App.Services/Navigation/NavigationHistory.cs
Add comment 1 using Infsoft.WPE.App.Services.Analytics;
Add comment 2 Plus  using Infsoft.WPE.App.Services.Models;
Add comment 2 3 using Microsoft.AspNetCore.Components;
Add comment 3 4 using Microsoft.AspNetCore.Components.Routing;
Add comment 4 5
Add comment 13 14
Add comment 14 15 private NavigationManager NavigationManager { get; }
Add comment 15 16 private IAnalyticsService AnalyticsService { get; }
Add comment 17 Plus   private IPageTitleCache PageTitleCache { get; }
Add comment 16 18
Add comment 17 19 private Stack<string> History { get; } = [];
Add comment 18 20
Add comment 19 Minus   public NavigationHistory(NavigationManager NavigationManager, IAnalyticsService AnalyticsService)
Add comment 21 Plus   public NavigationHistory(NavigationManager NavigationManager, IAnalyticsService AnalyticsService, IPageTitleCache PageTitleCache)
Add comment 20 22 {
Add comment 21 23 this.NavigationManager = NavigationManager;
Add comment 22 24 this.AnalyticsService = AnalyticsService;
Add comment 25 Plus   this.PageTitleCache = PageTitleCache;
Add comment 23 26
Add comment 24 27 handler = this.NavigationManager.RegisterLocationChangingHandler(OnLocationChange);
Add comment 25 28 }
Add comment 60 63 var pageUrl = GetWithoutParams(relative);
Add comment 61 64 // track event only if page has changed or on first history entry
Add comment 62 65 if (!History.TryPeek(out var current) || GetWithoutParams(current) != pageUrl)
Add comment 63 Minus   await AnalyticsService.OnPageView(pageUrl);
Add comment 66 Plus   await AnalyticsService.TrackEvent(new AnalyticsEvent("Page.View")
Add comment 67 Plus   {
Add comment 68 Plus   Tags =
Add comment 69 Plus   {
Add comment 70 Plus   { "Url.Path", $"/{pageUrl}" },
Add comment 71 Plus   { "Url.Title", (PageTitleCache.TryGetPageTitle(pageUrl, out var title) ? title : "Unknown") }
Add comment 72 Plus   }
Add comment 73 Plus   });
Add comment 64 74
Add comment 65 75 History.Push(relative);
Add comment 66 76 }
Add comment 67 77
Add comment 68 Minus   private string GetRelativeUrl(string url) {
Add comment 78 Plus   private string GetRelativeUrl(string url)
Add comment 79 Plus   {
Add comment 69 80 if (url.StartsWith(NavigationManager.BaseUri))
Add comment 70 81 return NavigationManager.ToBaseRelativePath(url);
Add comment 71 82
WPE.App.Services.csproj
/WPE.App.Services/WPE.App.Services.csproj-1+1
/WPE.App.Services/WPE.App.Services.csproj
Add comment 16 <PackageIcon>icon.png</PackageIcon>
Add comment 17 <PackageReadmeFile>ReadMe.md</PackageReadmeFile>
Add comment 18 <PackageTags>WPE;Workplace Experience;infsoft</PackageTags>
Add comment 19 Minus   <Version>0.9.3</Version>
Add comment 19 Plus   <Version>0.9.4</Version>
Add comment 20 <GenerateDocumentationFile>true</GenerateDocumentationFile>
Add comment 21 </PropertyGroup>
Add comment 22