Browse Source

Modified tracking to use JS and removed download tracking

tags/2.0.3
Teknikode 5 years ago
parent
commit
e2abc55872

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

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

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

+ 0
- 3
Teknik/Areas/Upload/Controllers/UploadController.cs View File

@@ -146,9 +146,6 @@ namespace Teknik.Areas.Upload.Controllers

Response.AppendHeader("Content-Disposition", cd.ToString());

// Handle Piwik Tracking if enabled
Tracking.TrackAction(Request, Request.Url.ToString());

return File(data, upload.ContentType);
}
}

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

@@ -27,7 +27,8 @@ namespace Teknik.Filters
{
title = page.Title;
}
Tracking.TrackPageView(filterContext.HttpContext.Request, title);
Config config = Config.Load();
Tracking.TrackPageView(filterContext.HttpContext.Request, config, title);

base.OnActionExecuted(filterContext);
}

+ 0
- 10
Teknik/Global.asax.cs View File

@@ -52,16 +52,6 @@ namespace Teknik
{
HttpContext context = HttpContext.Current;

// Handle Piwik
string title = string.Empty;
Page page = HttpContext.Current.Handler as Page;

if (page != null)
{
title = page.Title;
}
Tracking.TrackPageView(new HttpRequestWrapper(context.Request), title);

Stopwatch stopwatch = (Stopwatch)context.Items["Stopwatch"];
stopwatch.Stop();


+ 4
- 6
Teknik/Helpers/Tracking.cs View File

@@ -11,9 +11,8 @@ namespace Teknik.Helpers
{
public static class Tracking
{
public static void TrackPageView(HttpRequestBase request, string title)
public static void TrackPageView(HttpRequestBase request, Config config, string title)
{
Config config = Config.Load();
// Handle Piwik Tracking if enabled
if (config.PiwikConfig.Enabled)
{
@@ -24,10 +23,9 @@ namespace Teknik.Helpers
{
sub = request.Url.AbsoluteUri.GetSubdomain();
}

if (string.IsNullOrEmpty(title))
if (config.DevEnvironment)
{
title = config.Title;
sub = "dev - " + sub;
}

PiwikTracker.URL = config.PiwikConfig.Url;
@@ -48,7 +46,7 @@ namespace Teknik.Helpers
tracker.setUrlReferrer(request.UrlReferrer.ToString());

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

+ 28
- 27
Teknik/Views/Shared/_Layout.cshtml View File

@@ -1,8 +1,36 @@
@model Teknik.ViewModels.ViewModelBase

@using Teknik.Helpers

<!DOCTYPE html>
<html>
<head>
@if (Model.Config.PiwikConfig.Enabled)
{
string sub = Request.RequestContext.RouteData.Values["sub"].ToString();
if (Model.Config.DevEnvironment)
{
sub = "dev - " + sub;
}

<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", "@sub/@ViewBag.Title"]);
_paq.push(["setCookieDomain", "*.teknik.io"]);
_paq.push(["setDomains", ["*.teknik.io"]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//stats.teknik.io/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
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>
<!-- End Piwik Code -->
}
<script type="text/javascript">
var startTime = new Date();
</script>
@@ -51,33 +79,6 @@
@RenderBody()
</div>
@Html.Partial("_Footer")
@if (Model.Config.PiwikConfig.Enabled)
{
string sub = Request.RequestContext.RouteData.Values["sub"].ToString();
if (Model.Config.DevEnvironment)
{
sub = "dev - " + sub;
}

<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", "@sub/" + document.title]);
_paq.push(["setCookieDomain", "*.teknik.io"]);
_paq.push(["setDomains", ["*.teknik.io"]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//stats.teknik.io/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
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>
<!-- End Piwik Code -->
}

<script type="text/javascript">
$(document).ready(function () {pageloadDoTimer();});

Loading…
Cancel
Save