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.

Tracking.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Piwik.Tracker;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Web;
  8. using Teknik.Configuration;
  9. namespace Teknik.Helpers
  10. {
  11. public static class Tracking
  12. {
  13. public static void TrackPageView(HttpRequestBase request, string title, string sub)
  14. {
  15. Config config = Config.Load();
  16. // Handle Piwik Tracking if enabled
  17. if (config.PiwikConfig.Enabled)
  18. {
  19. try
  20. {
  21. PiwikTracker.URL = config.PiwikConfig.Url;
  22. PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId);
  23. tracker.setForceVisitDateTime(DateTime.Now);
  24. tracker.setUserAgent(request.UserAgent);
  25. tracker.setResolution(request.Browser.ScreenPixelsWidth, request.Browser.ScreenPixelsHeight);
  26. tracker.setBrowserHasCookies(request.Browser.Cookies);
  27. string ipAddress = request.UserHostAddress;
  28. tracker.setIp(ipAddress);
  29. tracker.setUrl(request.Url.ToString());
  30. tracker.setUrlReferrer(request.UrlReferrer.ToString());
  31. tracker.doTrackPageView(string.Format("{0} / {1}", sub, title));
  32. }
  33. catch (Exception ex)
  34. {
  35. }
  36. }
  37. }
  38. }
  39. }