Skip to content

Commit 02facc1

Browse files
committed
feat: Add Google Analytics integration and centralize app title and footer links via configuration.
1 parent ea2b338 commit 02facc1

4 files changed

Lines changed: 54 additions & 6 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@inject NavigationManager Nav
2+
@inject IJSRuntime JS
3+
4+
@using Microsoft.AspNetCore.Components
5+
6+
@if (_markup.HasValue)
7+
{
8+
@_markup.Value
9+
}
10+
11+
@code {
12+
[Parameter, EditorRequired]
13+
public string Id { get; set; } = default!;
14+
15+
private MarkupString? _markup;
16+
17+
protected override void OnParametersSet()
18+
{
19+
if (string.IsNullOrWhiteSpace(Id))
20+
{
21+
_markup = null;
22+
return;
23+
}
24+
25+
_markup = new MarkupString(
26+
$$"""
27+
<!-- Google tag (gtag.js) -->
28+
<script async src="https://www.googletagmanager.com/gtag/js?id={{Id}}"></script>
29+
<script>
30+
window.dataLayer = window.dataLayer || [];
31+
function gtag(){dataLayer.push(arguments);}
32+
gtag('js', new Date());
33+
34+
gtag('config', '{{Id}}');
35+
</script>
36+
""");
37+
}
38+
}

src/BlazorApps/Layout/MainLayout.razor

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
@inherits LayoutComponentBase
1+
@using BlazorApps.Components
2+
@inherits LayoutComponentBase
3+
@inject IConfiguration Config
4+
5+
<GoogleAnalytics Id="@Config["GoogleAnalytics:Id"]" />
26

37
<FluentLayout>
48
<FluentHeader>
5-
BlazorApps
9+
@Config["Title"]
610
</FluentHeader>
711
<FluentStack Class="main" Orientation="Orientation.Horizontal" Width="100%">
812
<NavMenu />
@@ -20,8 +24,8 @@
2024
</FluentBodyContent>
2125
</FluentStack>
2226
<FluentFooter>
23-
<a href="https://www.fluentui-blazor.net" target="_blank">Documentation and demos</a>
27+
Copyright &copy; 2024 - @DateTime.UtcNow.Year &nbsp;<a href="https://www.junian.dev/" target="_blank">junian.dev</a>
2428
<FluentSpacer />
25-
<a href="https://learn.microsoft.com/en-us/aspnet/core/blazor" target="_blank">About Blazor</a>
29+
<a href="https://github.com/junian/blazor-apps" target="_blank">GitHub</a>
2630
</FluentFooter>
2731
</FluentLayout>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"Title": "Blazor Lab",
3+
"GoogleAnalytics": {
4+
"Id": "G-YDEHTJ6WH0"
5+
}
6+
}

src/BlazorApps/wwwroot/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<meta charset="utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>BlazorApps</title>
7+
<title>Blazor Apps</title>
88
<base href="/" />
99
<link rel="preload" id="webassembly" />
1010
<link href="_content/Microsoft.FluentUI.AspNetCore.Components/css/reboot.css" rel="stylesheet" />
@@ -31,4 +31,4 @@
3131
<script src="_framework/blazor.webassembly#[.{fingerprint}].js"></script>
3232
</body>
3333

34-
</html>
34+
</html>

0 commit comments

Comments
 (0)