diff --git a/Teknik/Areas/API/Controllers/APIv1Controller.cs b/Teknik/Areas/API/Controllers/APIv1Controller.cs index 7398e98..4280fff 100644 --- a/Teknik/Areas/API/Controllers/APIv1Controller.cs +++ b/Teknik/Areas/API/Controllers/APIv1Controller.cs @@ -32,7 +32,7 @@ namespace Teknik.Areas.API.Controllers try { if (!doNotTrack) - Tracking.TrackPageView(Request, "Upload"); + Tracking.TrackPageView(Request, Config, "Upload"); if (file != null) { if (file.ContentLength <= Config.UploadConfig.MaxUploadSize) @@ -133,7 +133,7 @@ namespace Teknik.Areas.API.Controllers try { if (!doNotTrack) - Tracking.TrackPageView(Request, "Paste"); + Tracking.TrackPageView(Request, Config, "Paste"); Paste.Models.Paste paste = PasteHelper.CreatePaste(code, title, syntax, expireUnit, expireLength, password, hide); db.Pastes.Add(paste); @@ -163,7 +163,7 @@ namespace Teknik.Areas.API.Controllers try { if (!doNotTrack) - Tracking.TrackPageView(Request, "Shorten"); + Tracking.TrackPageView(Request, Config, "Shorten"); if (url.IsValidUrl()) { ShortenedUrl newUrl = Shortener.Shortener.ShortenUrl(url, Config.ShortenerConfig.UrlLength); diff --git a/Teknik/Areas/Upload/Controllers/UploadController.cs b/Teknik/Areas/Upload/Controllers/UploadController.cs index 707a4cb..fe57bed 100644 --- a/Teknik/Areas/Upload/Controllers/UploadController.cs +++ b/Teknik/Areas/Upload/Controllers/UploadController.cs @@ -146,9 +146,6 @@ namespace Teknik.Areas.Upload.Controllers Response.AppendHeader("Content-Disposition", cd.ToString()); - // Handle Piwik Tracking if enabled - Tracking.TrackAction(Request, Request.Url.ToString()); - return File(data, upload.ContentType); } } diff --git a/Teknik/Filters/TrackingFilterAttribute.cs b/Teknik/Filters/TrackingFilterAttribute.cs index d02ccec..cab0436 100644 --- a/Teknik/Filters/TrackingFilterAttribute.cs +++ b/Teknik/Filters/TrackingFilterAttribute.cs @@ -27,7 +27,8 @@ namespace Teknik.Filters { title = page.Title; } - Tracking.TrackPageView(filterContext.HttpContext.Request, title); + Config config = Config.Load(); + Tracking.TrackPageView(filterContext.HttpContext.Request, config, title); base.OnActionExecuted(filterContext); } diff --git a/Teknik/Global.asax.cs b/Teknik/Global.asax.cs index 5686aa2..993ab70 100644 --- a/Teknik/Global.asax.cs +++ b/Teknik/Global.asax.cs @@ -52,16 +52,6 @@ namespace Teknik { HttpContext context = HttpContext.Current; - // Handle Piwik - string title = string.Empty; - Page page = HttpContext.Current.Handler as Page; - - if (page != null) - { - title = page.Title; - } - Tracking.TrackPageView(new HttpRequestWrapper(context.Request), title); - Stopwatch stopwatch = (Stopwatch)context.Items["Stopwatch"]; stopwatch.Stop(); diff --git a/Teknik/Helpers/Tracking.cs b/Teknik/Helpers/Tracking.cs index 0e8c21a..019702d 100644 --- a/Teknik/Helpers/Tracking.cs +++ b/Teknik/Helpers/Tracking.cs @@ -11,9 +11,8 @@ namespace Teknik.Helpers { public static class Tracking { - public static void TrackPageView(HttpRequestBase request, string title) + public static void TrackPageView(HttpRequestBase request, Config config, string title) { - Config config = Config.Load(); // Handle Piwik Tracking if enabled if (config.PiwikConfig.Enabled) { @@ -24,10 +23,9 @@ namespace Teknik.Helpers { sub = request.Url.AbsoluteUri.GetSubdomain(); } - - if (string.IsNullOrEmpty(title)) + if (config.DevEnvironment) { - title = config.Title; + sub = "dev - " + sub; } PiwikTracker.URL = config.PiwikConfig.Url; @@ -48,7 +46,7 @@ namespace Teknik.Helpers tracker.setUrlReferrer(request.UrlReferrer.ToString()); tracker.setRequestTimeout(5); - tracker.doTrackPageView(string.Format("{0} / {1}", sub, title)); + tracker.doTrackPageView(string.Format("{0}/{1}", sub, title)); } catch (Exception ex) { diff --git a/Teknik/Views/Shared/_Layout.cshtml b/Teknik/Views/Shared/_Layout.cshtml index 59dd5ed..48ecf34 100644 --- a/Teknik/Views/Shared/_Layout.cshtml +++ b/Teknik/Views/Shared/_Layout.cshtml @@ -1,8 +1,36 @@ @model Teknik.ViewModels.ViewModelBase +@using Teknik.Helpers + + @if (Model.Config.PiwikConfig.Enabled) + { + string sub = Request.RequestContext.RouteData.Values["sub"].ToString(); + if (Model.Config.DevEnvironment) + { + sub = "dev - " + sub; + } + + + + + } @@ -51,33 +79,6 @@ @RenderBody() @Html.Partial("_Footer") - - @if (Model.Config.PiwikConfig.Enabled) - { - string sub = Request.RequestContext.RouteData.Values["sub"].ToString(); - if (Model.Config.DevEnvironment) - { - sub = "dev - " + sub; - } - - - - - }