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 = $"