Browse Source

Added tracking as a global filter.

tags/2.0.3
Teknikode 4 years ago
parent
commit
e95f2cf101

+ 2
- 0
Teknik/App_Start/FilterConfig.cs View File

@@ -1,5 +1,6 @@
using System.Web;
using System.Web.Mvc;
using Teknik.Filters;

namespace Teknik
{
@@ -10,6 +11,7 @@ namespace Teknik
//filters.Add(new HandleErrorAttribute());
filters.Add(new AuthorizeAttribute());
filters.Add(new RequireHttpsAttribute());
filters.Add(new TrackingFilterAttribute());
}
}
}

+ 0
- 6
Teknik/Areas/API/Controllers/APIv1Controller.cs View File

@@ -32,8 +32,6 @@ namespace Teknik.Areas.API.Controllers
{
try
{
if (!doNotTrack)
Tracking.TrackPageView(Request, Config, "Upload");
if (file != null)
{
if (file.ContentLength <= Config.UploadConfig.MaxUploadSize)
@@ -164,8 +162,6 @@ namespace Teknik.Areas.API.Controllers
{
try
{
if (!doNotTrack)
Tracking.TrackPageView(Request, Config, "Paste");
Paste.Models.Paste paste = PasteHelper.CreatePaste(code, title, syntax, expireUnit, expireLength, password, hide);

db.Pastes.Add(paste);
@@ -196,8 +192,6 @@ namespace Teknik.Areas.API.Controllers
{
try
{
if (!doNotTrack)
Tracking.TrackPageView(Request, Config, "Shorten");
if (url.IsValidUrl())
{
ShortenedUrl newUrl = Shortener.Shortener.ShortenUrl(url, Config.ShortenerConfig.UrlLength);

+ 8
- 2
Teknik/Filters/TrackingFilterAttribute.cs View File

@@ -27,11 +27,17 @@ namespace Teknik.Filters
{
title = page.Title;
}
Config config = Config.Load();
Tracking.TrackPageView(filterContext.HttpContext.Request, config, title);
HttpRequestBase request = filterContext.HttpContext.Request;
// Fire and forget. Don't need to wait for it.
Task.Run(() => AsyncTrackPageView(request, title));

base.OnActionExecuted(filterContext);
}

private void AsyncTrackPageView(HttpRequestBase request, string title)
{
Config config = Config.Load();
Tracking.TrackPageView(request, config, title);
}
}
}

+ 1
- 1
Teknik/Helpers/Tracking.cs View File

@@ -45,7 +45,7 @@ namespace Teknik.Helpers
if (request.UrlReferrer != null)
tracker.setUrlReferrer(request.UrlReferrer.ToString());

tracker.setRequestTimeout(5);
tracker.setRequestTimeout(15);
tracker.doTrackPageView(string.Format("{0}/{1}", sub, title));
}
catch (Exception ex)

+ 4
- 4
Teknik/Views/Shared/_Layout.cshtml View File

@@ -14,7 +14,7 @@
}

<!-- Piwik -->
<script type="text/javascript">
@*<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", "@sub/@ViewBag.Title"]);
_paq.push(["setCookieDomain", "*.teknik.io"]);
@@ -28,7 +28,7 @@
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
</script>*@
<!-- End Piwik Code -->
}
<script type="text/javascript">
@@ -58,12 +58,12 @@
</div>
<!-- NoScript Alert -->
<noscript>
@if (Model.Config.PiwikConfig.Enabled)
@*@if (Model.Config.PiwikConfig.Enabled)
{
<!-- Piwik Image Tracker-->
<img src="https://stats.teknik.io/piwik.php?idsite=1&rec=1" style="border:0" alt="" />
<!-- End Piwik -->
}
}*@
<div class="container">
<div class="row">
<div class="col-xs-12 text-center">

Loading…
Cancel
Save