File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
src/BlazorApplicationInsights/Components Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 1- using System . Text . Json ;
1+ using System ;
2+ using System . Text . Json ;
23using System . Text . Json . Serialization ;
34using System . Threading . Tasks ;
45using BlazorApplicationInsights . Interfaces ;
56using Microsoft . AspNetCore . Components ;
7+ using Microsoft . Extensions . Logging ;
68using Microsoft . JSInterop ;
79
810namespace BlazorApplicationInsights ;
@@ -15,6 +17,7 @@ public partial class ApplicationInsightsInit
1517 [ Inject ] IApplicationInsights ApplicationInsights { get ; set ; }
1618 [ Inject ] private IJSRuntime JSRuntime { get ; set ; }
1719 [ Inject ] private ApplicationInsightsInitConfig Config { get ; set ; }
20+ [ Inject ] private ILogger < ApplicationInsightsInit > Logger { get ; set ; }
1821
1922 /// <summary>
2023 /// Must be enabled when running in Blazor Wasm Standalone
@@ -46,9 +49,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
4649
4750 if ( Config . Config != null )
4851 {
49- await ApplicationInsights . UpdateCfg ( Config . Config , false ) ;
50-
51- await ApplicationInsights . TrackPageView ( ) ;
52+ try
53+ {
54+ await ApplicationInsights . UpdateCfg ( Config . Config , false ) ;
55+ await ApplicationInsights . TrackPageView ( ) ;
56+ }
57+ catch ( Exception ex )
58+ {
59+ Logger . LogError ( ex , "Failed to update configuration and track page view. An ad blocker or CSP may be blocking the App Insights script." ) ;
60+ }
5261 }
5362 }
5463
You can’t perform that action at this time.
0 commit comments