Some analytic stuff

This commit is contained in:
tidusjar 2016-06-10 11:41:51 +01:00
parent 89db8eb728
commit 1c0e00e4ba
7 changed files with 50 additions and 9 deletions

View file

@ -177,7 +177,7 @@ namespace PlexRequests.Helpers.Analytics
request.ContentLength = Encoding.UTF8.GetByteCount(postDataString); request.ContentLength = Encoding.UTF8.GetByteCount(postDataString);
// write the request body to the request // 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); await writer.WriteAsync(postDataString);
} }
@ -203,7 +203,7 @@ namespace PlexRequests.Helpers.Analytics
{ "v", "1" }, { "v", "1" },
{ "tid", TrackingId }, { "tid", TrackingId },
{ "t", type.ToString() }, { "t", type.ToString() },
{"cid", "" } {"cid", Guid.NewGuid().ToString() }
}; };
if (!string.IsNullOrEmpty(username)) if (!string.IsNullOrEmpty(username))

View file

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

View file

@ -120,14 +120,12 @@ namespace PlexRequests.UI.Helpers
public static IHtmlString LoadIssueDetailsAssets(this HtmlHelpers helper) public static IHtmlString LoadIssueDetailsAssets(this HtmlHelpers helper)
{ {
var sb = new StringBuilder();
var assetLocation = GetBaseUrl(); var assetLocation = GetBaseUrl();
var content = GetContentUrl(assetLocation); 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) public static IHtmlString LoadTableAssets(this HtmlHelpers helper)
@ -143,6 +141,22 @@ namespace PlexRequests.UI.Helpers
return helper.Raw(sb.ToString()); 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) public static IHtmlString GetSidebarUrl(this HtmlHelpers helper, NancyContext context, string url, string title)
{ {
var returnString = string.Empty; var returnString = string.Empty;

View file

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

View file

@ -41,6 +41,7 @@ using PlexRequests.Store.Repository;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using CommandLine; using CommandLine;
@ -48,6 +49,8 @@ using CommandLine;
using PlexRequests.Helpers.Analytics; using PlexRequests.Helpers.Analytics;
using PlexRequests.UI.Start; using PlexRequests.UI.Start;
using Action = PlexRequests.Helpers.Analytics.Action;
namespace PlexRequests.UI namespace PlexRequests.UI
{ {
class Program class Program

View file

@ -1,4 +1,5 @@
@using PlexRequests.UI.Helpers @using PlexRequests.UI.Helpers
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.PlexRequestSettings>
@Html.Partial("_Sidebar") @Html.Partial("_Sidebar")
@{ @{
int port; int port;
@ -190,8 +191,21 @@
{ {
<input type="checkbox" id="UsersCanViewOnlyOwnIssues" name="UsersCanViewOnlyOwnIssues"><label for="UsersCanViewOnlyOwnIssues">Users can view their own issues only</label> <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>
</div> </div>

View file

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