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.

TrackingFilterAttribute.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 TrackingFilterAttribute : ActionFilterAttribute
  14. {
  15. public override void OnActionExecuting(ActionExecutingContext filterContext)
  16. {
  17. base.OnActionExecuting(filterContext);
  18. }
  19. public override void OnActionExecuted(ActionExecutedContext filterContext)
  20. {
  21. Config config = Config.Load();
  22. if (config.PiwikConfig.Enabled)
  23. {
  24. try
  25. {
  26. string sub = filterContext.HttpContext.Request.RequestContext.RouteData.Values["sub"].ToString();
  27. if (string.IsNullOrEmpty(sub))
  28. {
  29. sub = filterContext.HttpContext.Request.Url.AbsoluteUri.GetSubdomain();
  30. }
  31. string title = config.Title;
  32. Page page = filterContext.HttpContext.Handler as Page;
  33. if (page != null)
  34. {
  35. title = page.Title;
  36. }
  37. Tracking.TrackPageView(filterContext.HttpContext.Request, title, sub);
  38. }
  39. catch (Exception ex)
  40. {
  41. }
  42. }
  43. base.OnActionExecuted(filterContext);
  44. }
  45. }
  46. }