diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Configuration/ApplicationInsightsOptions.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Configuration/ApplicationInsightsOptions.cs new file mode 100644 index 000000000..881637c6c --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Configuration/ApplicationInsightsOptions.cs @@ -0,0 +1,8 @@ +namespace Dfe.PrepareConversions.Configuration; + +public class ApplicationInsightsOptions +{ + public const string ConfigurationSection = "ApplicationInsights"; + public string ConnectionString { get; set; } + public string InstrumentationKey { get; set; } +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_AppInsights.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_AppInsights.cshtml new file mode 100644 index 000000000..976909b05 --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_AppInsights.cshtml @@ -0,0 +1,12 @@ +@{ + var authenticatedUserId = (User.Identity is not null && User.Identity.IsAuthenticated) ? User.Identity.Name ?? "Unknown" : "Anonymous"; +} + + + diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_Layout.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_Layout.cshtml index 5e4a42aa9..9c6f4be07 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_Layout.cshtml +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_Layout.cshtml @@ -21,8 +21,6 @@ var isTransfersPage = Context.Request.Path.Value.ToLower().Contains("/transfers"); var notificationBannerMessage = Configuration["notificationBannerMessage"] ?? string.Empty; - - var authenticatedUserId = User.Identity is not null && User.Identity.IsAuthenticated ? User.Identity.Name ?? "Unknown" : "Anonymous"; } @@ -64,16 +62,7 @@ @if (enableAppInsightsAnalytics) { - - - - - + } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/_ViewImports.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/_ViewImports.cshtml index 97b9a1eea..e9a492ca5 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/_ViewImports.cshtml +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/_ViewImports.cshtml @@ -2,7 +2,11 @@ @using Dfe.PrepareConversions.Models @using Dfe.PrepareConversions.ViewModels @using Dfe.PrepareConversions.Extensions +@using Dfe.PrepareConversions.Configuration +@using Microsoft.ApplicationInsights.AspNetCore +@using Microsoft.Extensions.Options @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.FeatureManagement.AspNetCore @addTagHelper *, Dfe.PrepareConversions -@addTagHelper *, NetEscapades.AspNetCore.SecurityHeaders.TagHelpers \ No newline at end of file +@addTagHelper *, NetEscapades.AspNetCore.SecurityHeaders.TagHelpers +@inject IOptions ApplicationInsightsOptions diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Startup.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Startup.cs index 1baba7397..ac1bde54a 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Startup.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Startup.cs @@ -147,6 +147,7 @@ public void ConfigureServices(IServiceCollection services) services.Configure(GetConfigurationSectionFor()); services.Configure(GetConfigurationSectionFor()); + services.Configure(GetConfigurationSectionFor()); services.AddScoped(); services.AddScoped(); @@ -154,7 +155,7 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/wwwroot/src/application-insights.js b/Dfe.PrepareConversions/Dfe.PrepareConversions/wwwroot/src/application-insights.js index a786f777d..d99bf9ee5 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/wwwroot/src/application-insights.js +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/wwwroot/src/application-insights.js @@ -4,6 +4,7 @@ import { ApplicationInsights } from '@microsoft/applicationinsights-web' const clickPluginInstance = new Microsoft.ApplicationInsights.ClickAnalyticsPlugin(); const appInsights = new ApplicationInsights({ config: { connectionString: window.appInsights.connectionString, + instrumentationKey: window.appInsights.instrumentationKey, extensions: [ clickPluginInstance ], extensionConfig: { [clickPluginInstance.identifier] : { autoCapture : true,