Browse Source

Modified back to use static function for tracking.

Added action tracking function.
master
Teknikode 6 years ago
parent
commit
07ae28b7e2
  1. 2
      Teknik/Areas/Upload/Controllers/UploadController.cs
  2. 1
      Teknik/Controllers/DefaultController.cs
  3. 55
      Teknik/Global.asax.cs
  4. 22
      Teknik/Helpers/Tracking.cs

2
Teknik/Areas/Upload/Controllers/UploadController.cs

@ -147,7 +147,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -147,7 +147,7 @@ namespace Teknik.Areas.Upload.Controllers
Response.AppendHeader("Content-Disposition", cd.ToString());
// Handle Piwik Tracking if enabled
Tracking.TrackPageView(Request, ViewBag.Title, Subdomain);
Tracking.TrackAction(Request.UserAgent, Request.Url.ToString());
return File(data, upload.ContentType);
}

1
Teknik/Controllers/DefaultController.cs

@ -13,7 +13,6 @@ using Teknik.Filters; @@ -13,7 +13,6 @@ using Teknik.Filters;
namespace Teknik.Controllers
{
[TrackingFilter]
public class DefaultController : Controller
{
private Config _config;

55
Teknik/Global.asax.cs

@ -46,6 +46,34 @@ namespace Teknik @@ -46,6 +46,34 @@ namespace Teknik
var stopwatch = new Stopwatch();
HttpContext.Current.Items["Stopwatch"] = stopwatch;
stopwatch.Start();
// Handle Piwik Tracking if enabled
Config config = Config.Load();
if (config.PiwikConfig.Enabled)
{
try
{
HttpRequest request = base.Request;
string sub = request.RequestContext.RouteData.Values["sub"].ToString();
if (string.IsNullOrEmpty(sub))
{
sub = request.Url.AbsoluteUri.GetSubdomain();
}
string title = config.Title;
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
title = page.Title;
}
Tracking.TrackPageView(new HttpRequestWrapper(request), title, sub);
}
catch (Exception ex)
{
}
}
}
protected void Application_EndRequest(object sender, EventArgs e)
@ -66,33 +94,6 @@ namespace Teknik @@ -66,33 +94,6 @@ namespace Teknik
{
context.Response.AppendHeader("Access-Control-Allow-Origin", origin);
}
//// Handle Piwik Tracking if enabled
//Config config = Config.Load();
//if (config.PiwikConfig.Enabled)
//{
// try
// {
// string sub = context.Request.RequestContext.RouteData.Values["sub"].ToString();
// if (string.IsNullOrEmpty(sub))
// {
// sub = context.Request.Url.AbsoluteUri.GetSubdomain();
// }
// string title = config.Title;
// Page page = HttpContext.Current.Handler as Page;
// if (page != null)
// {
// title = page.Title;
// }
// var newContext = ((HttpApplication)sender).Context;
// Tracking.TrackPageView(new HttpRequestWrapper(newContext.Request), title, sub);
// }
// catch (Exception ex)
// {
// }
//}
}
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)

22
Teknik/Helpers/Tracking.cs

@ -43,5 +43,27 @@ namespace Teknik.Helpers @@ -43,5 +43,27 @@ namespace Teknik.Helpers
}
}
}
public static void TrackAction(string userAgent, string url)
{
Config config = Config.Load();
// Handle Piwik Tracking if enabled
if (config.PiwikConfig.Enabled)
{
try
{
PiwikTracker.URL = config.PiwikConfig.Url;
PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId);
tracker.setUserAgent(userAgent);
tracker.doTrackAction(url, PiwikTracker.ActionType.download);
}
catch (Exception ex)
{
}
}
}
}
}

Loading…
Cancel
Save