diff --git a/PlexRequests.Helpers/Analytics/Analytics.cs b/PlexRequests.Helpers/Analytics/Analytics.cs index 6bab0ee58..4b4d74ed9 100644 --- a/PlexRequests.Helpers/Analytics/Analytics.cs +++ b/PlexRequests.Helpers/Analytics/Analytics.cs @@ -177,7 +177,7 @@ namespace PlexRequests.Helpers.Analytics request.ContentLength = Encoding.UTF8.GetByteCount(postDataString); // write the request body to the request - using (var writer = new StreamWriter(request.GetRequestStream())) + using (var writer = new StreamWriter(await request.GetRequestStreamAsync())) { await writer.WriteAsync(postDataString); } @@ -203,7 +203,7 @@ namespace PlexRequests.Helpers.Analytics { "v", "1" }, { "tid", TrackingId }, { "t", type.ToString() }, - {"cid", "" } + {"cid", Guid.NewGuid().ToString() } }; if (!string.IsNullOrEmpty(username)) diff --git a/PlexRequests.UI/Content/analytics.js b/PlexRequests.UI/Content/analytics.js new file mode 100644 index 000000000..22f671f41 --- /dev/null +++ b/PlexRequests.UI/Content/analytics.js @@ -0,0 +1,7 @@ +(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); + +ga('create', 'UA-77083919-2', 'auto'); +ga('send', 'pageview'); diff --git a/PlexRequests.UI/Helpers/BaseUrlHelper.cs b/PlexRequests.UI/Helpers/BaseUrlHelper.cs index ff5bb37ae..ae84fb180 100644 --- a/PlexRequests.UI/Helpers/BaseUrlHelper.cs +++ b/PlexRequests.UI/Helpers/BaseUrlHelper.cs @@ -59,7 +59,7 @@ namespace PlexRequests.UI.Helpers } if (settings.ThemeName == "PlexBootstrap.css") settings.ThemeName = Themes.PlexTheme; if (settings.ThemeName == "OriginalBootstrap.css") settings.ThemeName = Themes.OriginalTheme; - + sb.AppendLine($""); sb.AppendLine($""); sb.AppendLine($""); @@ -120,14 +120,12 @@ namespace PlexRequests.UI.Helpers public static IHtmlString LoadIssueDetailsAssets(this HtmlHelpers helper) { - var sb = new StringBuilder(); var assetLocation = GetBaseUrl(); - var content = GetContentUrl(assetLocation); - sb.AppendLine($""); + var asset = $""; - return helper.Raw(sb.ToString()); + return helper.Raw(asset); } public static IHtmlString LoadTableAssets(this HtmlHelpers helper) @@ -143,6 +141,22 @@ namespace PlexRequests.UI.Helpers return helper.Raw(sb.ToString()); } + public static IHtmlString LoadAnalytics(this HtmlHelpers helper) + { + var settings = GetSettings(); + if (!settings.CollectAnalyticData) + { + return helper.Raw(string.Empty); + } + + var assetLocation = GetBaseUrl(); + var content = GetContentUrl(assetLocation); + + var asset = $""; + + return helper.Raw(asset); + } + public static IHtmlString GetSidebarUrl(this HtmlHelpers helper, NancyContext context, string url, string title) { var returnString = string.Empty; @@ -191,7 +205,7 @@ namespace PlexRequests.UI.Helpers { url = $"/{content}{url}"; } - + if (context.Request.Path == url) { returnString = $"
  • {title} {extraHtml}
  • "; diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index cbe10833a..a401877e2 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -256,6 +256,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index 7cb342bd4..4323ae4d0 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -41,6 +41,7 @@ using PlexRequests.Store.Repository; using System.Diagnostics; using System.IO; using System.Linq; +using System.Threading; using System.Windows.Forms; using CommandLine; @@ -48,6 +49,8 @@ using CommandLine; using PlexRequests.Helpers.Analytics; using PlexRequests.UI.Start; +using Action = PlexRequests.Helpers.Analytics.Action; + namespace PlexRequests.UI { class Program diff --git a/PlexRequests.UI/Views/Admin/Settings.cshtml b/PlexRequests.UI/Views/Admin/Settings.cshtml index be5a6576d..b6ad5d09d 100644 --- a/PlexRequests.UI/Views/Admin/Settings.cshtml +++ b/PlexRequests.UI/Views/Admin/Settings.cshtml @@ -1,4 +1,5 @@ @using PlexRequests.UI.Helpers +@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase @Html.Partial("_Sidebar") @{ int port; @@ -190,8 +191,21 @@ { } + + +
    +
    + @if (Model.CollectAnalyticData) + { + + + } + else + { + + }
    diff --git a/PlexRequests.UI/Views/Shared/_Layout.cshtml b/PlexRequests.UI/Views/Shared/_Layout.cshtml index b955abb0e..fee4537f8 100644 --- a/PlexRequests.UI/Views/Shared/_Layout.cshtml +++ b/PlexRequests.UI/Views/Shared/_Layout.cshtml @@ -17,7 +17,7 @@ Plex Requests - + @Html.LoadAnalytics() @Html.LoadAssets()