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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using Piwik.Tracker;
  2. using System;
  3. using System.Web;
  4. using Teknik.Configuration;
  5. using Teknik.Utilities;
  6. namespace Teknik.Piwik
  7. {
  8. public static class Tracking
  9. {
  10. public static void TrackPageView(string title, string sub, string clientIp, string url, string urlReferrer, string userAgent, int pixelWidth, int pixelHeight, bool hasCookies, string acceptLang, bool hasJava)
  11. {
  12. try
  13. {
  14. Config config = Config.Load();
  15. if (config.PiwikConfig.Enabled)
  16. {
  17. if (config.DevEnvironment)
  18. {
  19. sub = "dev - " + sub;
  20. }
  21. //PiwikTracker.URL = config.PiwikConfig.Url;
  22. PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId, config.PiwikConfig.Url);
  23. // Set Request Info
  24. tracker.SetIp(clientIp);
  25. tracker.SetTokenAuth(config.PiwikConfig.TokenAuth);
  26. tracker.SetUserAgent(userAgent);
  27. // Set browser info
  28. tracker.SetResolution(pixelWidth, pixelHeight);
  29. tracker.SetBrowserHasCookies(hasCookies);
  30. if (!string.IsNullOrEmpty(acceptLang))
  31. tracker.SetBrowserLanguage(acceptLang);
  32. tracker.SetPlugins(new BrowserPlugins {Java = hasJava});
  33. // Get Referral
  34. if (!string.IsNullOrEmpty(urlReferrer))
  35. tracker.SetUrlReferrer(urlReferrer);
  36. if (!string.IsNullOrEmpty(url))
  37. tracker.SetUrl(url);
  38. // Send the tracking request
  39. tracker.DoTrackPageView(string.Format("{0}/{1}", sub, title));
  40. }
  41. }
  42. catch (Exception ex)
  43. {
  44. }
  45. }
  46. public static void TrackDownload(string userAgent, string clientIp, string url, string urlReferrer)
  47. {
  48. TrackAction(ActionType.Download, userAgent, clientIp, url, urlReferrer);
  49. }
  50. public static void TrackLink(string userAgent, string clientIp, string url, string urlReferrer)
  51. {
  52. TrackAction(ActionType.Link, userAgent, clientIp, url, urlReferrer);
  53. }
  54. private static void TrackAction(ActionType type, string userAgent, string clientIp, string url, string urlReferrer)
  55. {
  56. try
  57. {
  58. Config config = Config.Load();
  59. if (config.PiwikConfig.Enabled)
  60. {
  61. PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId, config.PiwikConfig.Url);
  62. tracker.SetUserAgent(userAgent);
  63. tracker.SetIp(clientIp);
  64. tracker.SetTokenAuth(config.PiwikConfig.TokenAuth);
  65. // Get Referral
  66. if (!string.IsNullOrEmpty(urlReferrer))
  67. tracker.SetUrlReferrer(urlReferrer);
  68. if (!string.IsNullOrEmpty(url))
  69. tracker.SetUrl(url);
  70. tracker.DoTrackAction(url, type);
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. }
  76. }
  77. }
  78. }