diff --git a/src/Imagile.Framework.Blazor.ApplicationInsights/Components/ApplicationInsightsInit.razor.cs b/src/Imagile.Framework.Blazor.ApplicationInsights/Components/ApplicationInsightsInit.razor.cs
index 3afb1a8..1ea8a4f 100644
--- a/src/Imagile.Framework.Blazor.ApplicationInsights/Components/ApplicationInsightsInit.razor.cs
+++ b/src/Imagile.Framework.Blazor.ApplicationInsights/Components/ApplicationInsightsInit.razor.cs
@@ -41,6 +41,58 @@ public partial class ApplicationInsightsInit : ComponentBase, IDisposable
private string script { get; set; } = string.Empty;
+ // Inlined from wwwroot/Imagile.Framework.Blazor.ApplicationInsights.lib.module.js
+ // Avoids dependency on _content/ static asset serving, which is unreliable for NuGet-distributed RCLs.
+ private const string BlazerApplicationInsightsJs = """
+ window.blazorApplicationInsights = {
+ addTelemetryInitializer: function (telemetryItem) {
+ var telemetryInitializer = (envelope) => {
+ if (telemetryItem.ver !== null) { envelope.ver = telemetryItem.ver; }
+ if (telemetryItem.name !== null) { envelope.name = telemetryItem.name; }
+ if (telemetryItem.time !== null) { envelope.time = telemetryItem.time; }
+ if (telemetryItem.iKey !== null) { envelope.iKey = telemetryItem.iKey; }
+ if (telemetryItem.ext !== null) { Object.assign(envelope.ext, telemetryItem.ext); }
+ if (telemetryItem.tags !== null) { Object.assign(envelope.tags, telemetryItem.tags); }
+ if (telemetryItem.data !== null) { Object.assign(envelope.data, telemetryItem.data); }
+ if (telemetryItem.baseType !== null) { envelope.baseType = telemetryItem.baseType; }
+ if (telemetryItem.baseData !== null) { Object.assign(envelope.baseData, telemetryItem.baseData); }
+ };
+ appInsights.addTelemetryInitializer(telemetryInitializer);
+ },
+ trackDependencyData: function (dependencyTelemetry) {
+ if (dependencyTelemetry.startTime !== null) {
+ dependencyTelemetry.startTime = new Date(dependencyTelemetry.startTime);
+ }
+ appInsights.trackDependencyData(dependencyTelemetry);
+ },
+ getContext: function () {
+ if (appInsights.context !== undefined) { return appInsights.context; }
+ },
+ cookieMgrSetCookiesEnabled: function (enabled) {
+ if (appInsights.getCookieMgr !== undefined) { appInsights.getCookieMgr().setEnabled(enabled); }
+ },
+ cookieMgrGetCookiesEnabled: function () {
+ if (appInsights.getCookieMgr !== undefined) { return appInsights.getCookieMgr().isEnabled(); }
+ return false;
+ },
+ cookieMgrSet: function (name, value, maxAgeSec, domain, path) {
+ if (appInsights.getCookieMgr !== undefined) { appInsights.getCookieMgr().set(name, value, maxAgeSec, domain, path); }
+ },
+ cookieMgrGet: function (name) {
+ if (appInsights.getCookieMgr !== undefined) { appInsights.getCookieMgr().get(name); }
+ },
+ cookieMgrDel: function (name, path) {
+ if (appInsights.getCookieMgr !== undefined) { appInsights.getCookieMgr().del(name, path); }
+ },
+ cookieMgrPurge: function (name, path) {
+ if (appInsights.getCookieMgr !== undefined) { appInsights.getCookieMgr().purge(name, path); }
+ },
+ cookieMgrUnload: function (isAsync) {
+ if (appInsights.getCookieMgr !== undefined) { appInsights.getCookieMgr().unload(isAsync); }
+ },
+ };
+ """;
+
///
protected override void OnInitialized()
{
@@ -52,6 +104,11 @@ protected override void OnInitialized()
// Application Insights Snippet
// https://github.com/microsoft/ApplicationInsights-JS#snippet-setup-ignore-if-using-npm-setup
script = $$$"""""";
+
+ // Append blazorApplicationInsights setup as a second inline script.
+ // This avoids any dependency on _content/ static asset serving, which doesn't work
+ // reliably for .lib.module.js files in NuGet-distributed Razor class libraries.
+ script += $"";
}
///
@@ -62,13 +119,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
ApplicationInsights.InitJSRuntime(JSRuntime);
- // Explicitly import the JS module to ensure window.blazorApplicationInsights is defined.
- // The .lib.module.js auto-loading mechanism is not reliable for NuGet-distributed RCLs,
- // so we import it explicitly here before making any interop calls.
- await JSRuntime.InvokeAsync(
- "import",
- "./_content/Imagile.Framework.Blazor.ApplicationInsights/Imagile.Framework.Blazor.ApplicationInsights.lib.module.js");
-
if (Config.Config != null)
{
try