Small bit of analytics

pull/740/head
Jamie.Rees 8 years ago
parent 121cf90ba7
commit ad796a47bd

@ -54,7 +54,7 @@ namespace PlexRequests.Helpers.Analytics
Track(HitType.@event, username, cat, act, label, clientId, value);
}
public async Task TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null)
public async void TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null)
{
var cat = category.ToString();
var act = action.ToString();
@ -146,7 +146,7 @@ namespace PlexRequests.Helpers.Analytics
request.Method = RequestMethod;
// set the Content-Length header to the correct value
request.ContentLength = Encoding.UTF8.GetByteCount(postDataString);
#if !DEBUG
// write the request body to the request
using (var writer = new StreamWriter(request.GetRequestStream()))
{
@ -165,6 +165,7 @@ namespace PlexRequests.Helpers.Analytics
{
Log.Error(ex, "Analytics tracking failed");
}
#endif
}
private async Task SendRequestAsync(string postDataString)
{
@ -173,6 +174,7 @@ namespace PlexRequests.Helpers.Analytics
// set the Content-Length header to the correct value
request.ContentLength = Encoding.UTF8.GetByteCount(postDataString);
#if !DEBUG
// write the request body to the request
using (var writer = new StreamWriter(await request.GetRequestStreamAsync()))
{
@ -191,6 +193,7 @@ namespace PlexRequests.Helpers.Analytics
{
Log.Error(ex, "Analytics tracking failed");
}
#endif
}
private Dictionary<string, string> BuildRequestData(HitType type, string username, string category, string action, string clientId, string label, int? value, string exceptionDescription, int? fatal)

@ -38,6 +38,7 @@ namespace PlexRequests.Helpers.Analytics
Issues,
UserLogin,
Services,
Navbar
Navbar,
UserManagement
}
}

@ -51,7 +51,7 @@ namespace PlexRequests.Helpers.Analytics
/// <param name="clientId">The client identifier.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
Task TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null);
void TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null);
/// <summary>
/// Tracks the page view.

@ -37,8 +37,8 @@ using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Core.StatusChecker;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Analytics;
using PlexRequests.Helpers.Permissions;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Models;
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
@ -46,10 +46,11 @@ namespace PlexRequests.UI.Modules.Admin
{
public class SystemStatusModule : BaseModule
{
public SystemStatusModule(ISettingsService<PlexRequestSettings> settingsService, ICacheProvider cache, ISettingsService<SystemSettings> ss, ISecurityExtensions security) : base("admin", settingsService, security)
public SystemStatusModule(ISettingsService<PlexRequestSettings> settingsService, ICacheProvider cache, ISettingsService<SystemSettings> ss, ISecurityExtensions security, IAnalytics a) : base("admin", settingsService, security)
{
Cache = cache;
SystemSettings = ss;
Analytics = a;
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
@ -61,6 +62,7 @@ namespace PlexRequests.UI.Modules.Admin
private ICacheProvider Cache { get; }
private ISettingsService<SystemSettings> SystemSettings { get; }
private IAnalytics Analytics { get; }
private async Task<Negotiator> Status()
{
@ -99,8 +101,10 @@ namespace PlexRequests.UI.Modules.Admin
private async Task<Response> Save()
{
var settings = this.Bind<SystemSettings>();
Analytics.TrackEventAsync(Category.Admin, PlexRequests.Helpers.Analytics.Action.Update, $"Updated Branch {EnumHelper<Branches>.GetDisplayValue(settings.Branch)}", Username, CookieHelper.GetAnalyticClientId(Cookies));
await SystemSettings.SaveSettingsAsync(settings);
// Clear the cache
@ -111,6 +115,8 @@ namespace PlexRequests.UI.Modules.Admin
private Response AutoUpdate()
{
Analytics.TrackEventAsync(Category.Admin, PlexRequests.Helpers.Analytics.Action.Update, "AutoUpdate", Username, CookieHelper.GetAnalyticClientId(Cookies));
var url = Request.Form["url"];
var startInfo = Type.GetType("Mono.Runtime") != null

@ -13,12 +13,13 @@ using PlexRequests.Core;
using PlexRequests.Core.Models;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Analytics;
using PlexRequests.Helpers.Permissions;
using PlexRequests.Store;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;
using PlexRequests.UI.Models;
using Action = PlexRequests.Helpers.Analytics.Action;
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
namespace PlexRequests.UI.Modules
@ -26,7 +27,7 @@ namespace PlexRequests.UI.Modules
public class UserManagementModule : BaseModule
{
public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService<PlexSettings> plex, IRepository<UserLogins> userLogins, IPlexUserRepository plexRepo
, ISecurityExtensions security, IRequestService req) : base("usermanagement", pr, security)
, ISecurityExtensions security, IRequestService req, IAnalytics ana) : base("usermanagement", pr, security)
{
#if !DEBUG
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
@ -38,11 +39,12 @@ namespace PlexRequests.UI.Modules
PlexUsersRepository = plexRepo;
PlexRequestSettings = pr;
RequestService = req;
Analytics = ana;
Get["/"] = x => Load();
Get["/users", true] = async (x, ct) => await LoadUsers();
Post["/createuser"] = x => CreateUser();
Post["/createuser", true] = async (x,ct) => await CreateUser();
Get["/local/{id}"] = x => LocalDetails((Guid)x.id);
Get["/plex/{id}", true] = async (x, ct) => await PlexDetails(x.id);
Get["/permissions"] = x => GetEnum<Permissions>();
@ -58,6 +60,7 @@ namespace PlexRequests.UI.Modules
private IPlexUserRepository PlexUsersRepository { get; }
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
private IRequestService RequestService { get; }
private IAnalytics Analytics { get; }
private Negotiator Load()
{
@ -103,8 +106,9 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(model);
}
private Response CreateUser()
private async Task<Response> CreateUser()
{
Analytics.TrackEventAsync(Category.UserManagement, Action.Create, "Created User", Username, CookieHelper.GetAnalyticClientId(Cookies));
var body = Request.Body.AsString();
if (string.IsNullOrEmpty(body))
{
@ -122,7 +126,7 @@ namespace PlexRequests.UI.Modules
});
}
var users = UserMapper.GetUsers();
var users = await UserMapper.GetUsersAsync();
if (users.Any(x => x.UserName.Equals(model.Username, StringComparison.CurrentCultureIgnoreCase)))
{
return Response.AsJson(new JsonResponseModel
@ -158,6 +162,7 @@ namespace PlexRequests.UI.Modules
private async Task<Response> UpdateUser()
{
Analytics.TrackEventAsync(Category.UserManagement, Action.Update, "Updated User", Username, CookieHelper.GetAnalyticClientId(Cookies));
var body = Request.Body.AsString();
if (string.IsNullOrEmpty(body))
{
@ -276,6 +281,7 @@ namespace PlexRequests.UI.Modules
private Response DeleteUser()
{
Analytics.TrackEventAsync(Category.UserManagement, Action.Delete, "Deleted User", Username, CookieHelper.GetAnalyticClientId(Cookies));
var body = Request.Body.AsString();
if (string.IsNullOrEmpty(body))
{

Loading…
Cancel
Save