-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract App Insights JS SDK (#1226)
* Making it a shared partial keeps the _layout.cshtml cleaner * Adds missing configuration for click tracking and user identification * Extract App Insights connection string into Options
- Loading branch information
1 parent
7086f91
commit 5430458
Showing
12 changed files
with
70 additions
and
22 deletions.
There are no files selected for viewing
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
...Conversions/Dfe.PrepareConversions.Tests/Configuration/ApplicationInsightsOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Dfe.PrepareConversions.Configuration; | ||
using Xunit; | ||
|
||
namespace Dfe.PrepareConversions.Tests.Configuration; | ||
|
||
public class ApplicationInsightsOptionsTests | ||
{ | ||
[Fact] | ||
public void Configuration_section_should_be_ApplicationInsights() | ||
{ | ||
Assert.Equal("ApplicationInsights", ApplicationInsightsOptions.ConfigurationSection); | ||
} | ||
|
||
[Fact] | ||
public void ConnectionString_should_default_to_null() | ||
{ | ||
var _options = new ApplicationInsightsOptions(); | ||
Assert.Null(_options.ConnectionString); | ||
} | ||
|
||
[Fact] | ||
public void InstrumentationKey_should_default_to_null() | ||
{ | ||
var _options = new ApplicationInsightsOptions(); | ||
Assert.Null(_options.InstrumentationKey); | ||
} | ||
|
||
[Fact] | ||
public void EnableBrowserAnalytics_should_default_to_null() | ||
{ | ||
var _options = new ApplicationInsightsOptions(); | ||
Assert.Null(_options.EnableBrowserAnalytics); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Dfe.PrepareConversions/Dfe.PrepareConversions/Configuration/ApplicationInsightsOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Dfe.PrepareConversions.Configuration; | ||
|
||
public class ApplicationInsightsOptions | ||
{ | ||
public const string ConfigurationSection = "ApplicationInsights"; | ||
public string ConnectionString { get; init; } | ||
public string InstrumentationKey { get; init; } | ||
public string EnableBrowserAnalytics { get; init; } | ||
} |
12 changes: 12 additions & 0 deletions
12
Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_AppInsights.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@{ | ||
var authenticatedUserId = (User.Identity is not null && User.Identity.IsAuthenticated) ? User.Identity.Name ?? "Unknown" : "Anonymous"; | ||
} | ||
<script type="text/javascript" integrity="sha384-g/ZkzetdQypWdY0NBZT5r2L3BR9/hURD8OBcd1rEaBpgX6QC7EaTL+o+mzWrBcXW" crossorigin="anonymous" src="https://js.monitor.azure.com/scripts/b/ext/ai.clck.2.8.18.min.js"></script> | ||
<script type="text/javascript" asp-add-nonce> | ||
window.appInsights = { | ||
connectionString: '@ApplicationInsightsOptions.Value.ConnectionString', | ||
instrumentationKey: '@ApplicationInsightsOptions.Value.InstrumentationKey', | ||
authenticatedUserId: '@authenticatedUserId' | ||
} | ||
</script> | ||
<script type="text/javascript" src="~/dist/application-insights.min.js" asp-add-nonce></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Dfe.PrepareConversions/Dfe.PrepareConversions/wwwroot/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 2 additions & 5 deletions
7
Dfe.PrepareConversions/Dfe.PrepareConversions/wwwroot/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,3 @@ | |
display: inline; | ||
line-height: 2; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters