The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TrackPageView.cs 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using System.Web.UI;
  9. using Teknik.Configuration;
  10. using Teknik.Helpers;
  11. namespace Teknik.Filters
  12. {
  13. public class TrackPageView : ActionFilterAttribute
  14. {
  15. public override void OnActionExecuting(ActionExecutingContext filterContext)
  16. {
  17. base.OnActionExecuting(filterContext);
  18. }
  19. public override void OnActionExecuted(ActionExecutedContext filterContext)
  20. {
  21. string title = string.Empty;
  22. if (filterContext.Controller != null && filterContext.Controller.ViewBag != null && filterContext.Controller.ViewBag.Title != null)
  23. {
  24. title = filterContext.Controller.ViewBag.Title;
  25. }
  26. HttpRequestBase request = filterContext.HttpContext.Request;
  27. // Fire and forget. Don't need to wait for it.
  28. Task.Run(() => AsyncTrackPageView(request, title));
  29. base.OnActionExecuted(filterContext);
  30. }
  31. private void AsyncTrackPageView(HttpRequestBase request, string title)
  32. {
  33. Config config = Config.Load();
  34. Tracking.TrackPageView(request, config, title);
  35. }
  36. }
  37. }