From d8cca4a971f48ce317d791468fcfaecb73b8b603 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 23 Jun 2016 09:01:05 +0100 Subject: [PATCH] Some more useful analytical information --- PlexRequests.Helpers/Analytics/Action.cs | 6 +++++- PlexRequests.UI/Modules/SearchModule.cs | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/PlexRequests.Helpers/Analytics/Action.cs b/PlexRequests.Helpers/Analytics/Action.cs index 4a42a45be..6cbe2a737 100644 --- a/PlexRequests.Helpers/Analytics/Action.cs +++ b/PlexRequests.Helpers/Analytics/Action.cs @@ -35,6 +35,10 @@ namespace PlexRequests.Helpers.Analytics Save, Update, Start, - View + View, + Movie, + TvShow, + Album, + Request } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index f02a417ea..ddb9f31e1 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -53,11 +53,14 @@ using Nancy.Responses; using PlexRequests.Api.Models.Tv; using PlexRequests.Core.Models; +using PlexRequests.Helpers.Analytics; using PlexRequests.Store.Models; using PlexRequests.Store.Repository; using TMDbLib.Objects.General; +using Action = PlexRequests.Helpers.Analytics.Action; + namespace PlexRequests.UI.Modules { public class SearchModule : BaseAuthModule @@ -69,7 +72,7 @@ namespace PlexRequests.UI.Modules INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService hpService, ICouchPotatoCacher cpCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher, IPlexApi plexApi, ISettingsService plexService, ISettingsService auth, IRepository u, ISettingsService email, - IIssueService issue) : base("search", prSettings) + IIssueService issue, IAnalytics a) : base("search", prSettings) { Auth = auth; PlexService = plexService; @@ -95,6 +98,7 @@ namespace PlexRequests.UI.Modules UsersToNotifyRepo = u; EmailNotificationSettings = email; IssueService = issue; + Analytics = a; Get["/", true] = async (x, ct) => await RequestLoad(); @@ -140,31 +144,31 @@ namespace PlexRequests.UI.Modules private IHeadphonesApi HeadphonesApi { get; } private IRepository UsersToNotifyRepo { get; } private IIssueService IssueService { get; } + private IAnalytics Analytics { get; } private static Logger Log = LogManager.GetCurrentClassLogger(); private async Task RequestLoad() { var settings = await PrService.GetSettingsAsync(); - Log.Trace("Loading Index"); return View["Search/Index", settings]; } private async Task UpcomingMovies() { - Log.Trace("Loading upcoming movies"); + await Analytics.TrackEventAsync(Category.Search, Action.Movie, "Upcoming", Username, CookieHelper.GetAnalyticClientId(Cookies)); return await ProcessMovies(MovieSearchType.Upcoming, string.Empty); } private async Task CurrentlyPlayingMovies() { - Log.Trace("Loading currently playing movies"); + await Analytics.TrackEventAsync(Category.Search, Action.Movie, "CurrentlyPlaying", Username, CookieHelper.GetAnalyticClientId(Cookies)); return await ProcessMovies(MovieSearchType.CurrentlyPlaying, string.Empty); } private async Task SearchMovie(string searchTerm) { - Log.Trace("Searching for Movie {0}", searchTerm); + await Analytics.TrackEventAsync(Category.Search, Action.Movie, searchTerm, Username, CookieHelper.GetAnalyticClientId(Cookies)); return await ProcessMovies(MovieSearchType.Search, searchTerm); } @@ -279,6 +283,7 @@ namespace PlexRequests.UI.Modules private async Task SearchTvShow(string searchTerm) { + await Analytics.TrackEventAsync(Category.Search, Action.TvShow, searchTerm, Username, CookieHelper.GetAnalyticClientId(Cookies)); var plexSettings = await PlexService.GetSettingsAsync(); Log.Trace("Searching for TV Show {0}", searchTerm); @@ -366,6 +371,7 @@ namespace PlexRequests.UI.Modules private async Task SearchMusic(string searchTerm) { + await Analytics.TrackEventAsync(Category.Search, Action.Album, searchTerm, Username, CookieHelper.GetAnalyticClientId(Cookies)); var apiAlbums = new List(); await Task.Run(() => MusicBrainzApi.SearchAlbum(searchTerm)).ContinueWith((t) => { @@ -417,6 +423,7 @@ namespace PlexRequests.UI.Modules private async Task RequestMovie(int movieId) { + await Analytics.TrackEventAsync(Category.Search, Action.Request, "Movie", Username, CookieHelper.GetAnalyticClientId(Cookies)); var movieInfo = MovieApi.GetMovieInformation(movieId).Result; var fullMovieName = $"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}"; Log.Trace("Getting movie info from TheMovieDb"); @@ -559,6 +566,7 @@ namespace PlexRequests.UI.Modules /// private async Task RequestTvShow(int showId, string seasons) { + await Analytics.TrackEventAsync(Category.Search, Action.Request, "TvShow", Username, CookieHelper.GetAnalyticClientId(Cookies)); var tvApi = new TvMazeApi(); var showInfo = tvApi.ShowLookupByTheTvDbId(showId); @@ -762,6 +770,7 @@ namespace PlexRequests.UI.Modules private async Task RequestAlbum(string releaseId) { + await Analytics.TrackEventAsync(Category.Search, Action.Request, "Album", Username, CookieHelper.GetAnalyticClientId(Cookies)); var settings = await PrService.GetSettingsAsync(); var existingRequest = await RequestService.CheckRequestAsync(releaseId); Log.Debug("Checking for an existing request"); @@ -919,6 +928,7 @@ namespace PlexRequests.UI.Modules private async Task NotifyUser(bool notify) { + await Analytics.TrackEventAsync(Category.Search, Action.Save, "NotifyUser", Username, CookieHelper.GetAnalyticClientId(Cookies), notify ? 1 : 0); var authSettings = await Auth.GetSettingsAsync(); var auth = authSettings.UserAuthentication; var emailSettings = await EmailNotificationSettings.GetSettingsAsync(); @@ -984,7 +994,5 @@ namespace PlexRequests.UI.Modules var model = seasons.Select(x => x.number); return Response.AsJson(model); } - - } }