Some analytic stuff

pull/332/head
tidusjar 9 years ago
parent 89db8eb728
commit 1c0e00e4ba

@ -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))

@ -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');

@ -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($"<script src=\"{content}/Content/issue-details.js\" type=\"text/javascript\"></script>");
var asset = $"<script src=\"{content}/Content/issue-details.js\" type=\"text/javascript\"></script>";
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 = $"<script src=\"{content}/Content/analytics.js\" type=\"text/javascript\"></script>";
return helper.Raw(asset);
}
public static IHtmlString GetSidebarUrl(this HtmlHelpers helper, NancyContext context, string url, string title)
{
var returnString = string.Empty;

@ -256,6 +256,9 @@
<Content Include="Content\issue-details.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\analytics.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\issues.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

@ -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

@ -1,4 +1,5 @@
@using PlexRequests.UI.Helpers
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.PlexRequestSettings>
@Html.Partial("_Sidebar")
@{
int port;
@ -190,8 +191,21 @@
{
<input type="checkbox" id="UsersCanViewOnlyOwnIssues" name="UsersCanViewOnlyOwnIssues"><label for="UsersCanViewOnlyOwnIssues">Users can view their own issues only</label>
}
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.CollectAnalyticData)
{
<input type="checkbox" id="CollectAnalyticData" name="CollectAnalyticData" checked="checked">
<label for="CollectAnalyticData">Allow us to collect anonymous analytical data e.g. browser used</label>
}
else
{
<input type="checkbox" id="CollectAnalyticData" name="CollectAnalyticData"><label for="CollectAnalyticData">Allow us to collect anonymous analytical data e.g. browser</label>
}
</div>
</div>

@ -17,7 +17,7 @@
<title>Plex Requests</title>
<!-- Styles -->
<meta name="viewport" content="width=device-width, initial-scale=1">
@Html.LoadAnalytics()
@Html.LoadAssets()
</head>
<body>

Loading…
Cancel
Save