Skip to content

Commit

Permalink
google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Jul 21, 2024
1 parent fe07550 commit a3929ef
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace HarmonyDB.Playground.Web.Models;

public class PlaygroundOptions
{
public string? GoogleTagId { get; init; }
}
5 changes: 3 additions & 2 deletions HarmonyDB.Playground/HarmonyDB.Playground.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Globalization;
using HarmonyDB.Index.Analysis;
using HarmonyDB.Index.Api.Client;
using HarmonyDB.Playground.Web.Models;
using HarmonyDB.Source.Api.Client;
using Microsoft.AspNetCore.Localization.Routing;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

namespace HarmonyDB.Playground.Web
{
Expand All @@ -25,7 +25,8 @@ public static void Main(string[] args)
.AddLocalization()
.AddIndexApiClient(builder.Configuration)
.AddSourceApiClient(builder.Configuration)
.AddIndexAnalysis();
.AddIndexAnalysis()
.Configure<PlaygroundOptions>(o => builder.Configuration.GetSection(nameof(PlaygroundOptions)).Bind(o));

const string defaultCulture = "en";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
@using System.Web
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Options
@inject IViewLocalizer ViewLocalizer
@inject IOptions<PlaygroundOptions> Options
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@if (!string.IsNullOrWhiteSpace(Options.Value.GoogleTagId))
{
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/[email protected]"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', '@Options.Value.GoogleTagId');
</script>
}

<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>@ViewData["Title"], Harmony DB</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/chords.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/header.css" asp-append-version="true" />
<link rel="stylesheet" href="~/HarmonyDB.Playground.Web.styles.css" asp-append-version="true" />
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/css/chords.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/css/header.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/HarmonyDB.Playground.Web.styles.css" asp-append-version="true"/>
@await RenderSectionAsync("styles", false)
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"PlaygroundOptions": {
"GoogleTagId": ""
}
}

0 comments on commit a3929ef

Please sign in to comment.