Browse Source

Added Do Not Track support for tracking

tags/2.0.3
Teknikode 4 years ago
parent
commit
06fae90a4c
1 changed files with 35 additions and 31 deletions
  1. 35
    31
      Teknik/Helpers/Tracking.cs

+ 35
- 31
Teknik/Helpers/Tracking.cs View File

@@ -18,43 +18,47 @@ namespace Teknik.Helpers
{
try
{
string sub = request.RequestContext.RouteData.Values["sub"].ToString();
if (string.IsNullOrEmpty(sub))
// Follow Do Not Track
string doNotTrack = request.Headers["DNT"];
if (!string.IsNullOrEmpty(doNotTrack) && doNotTrack != "1")
{
sub = request.Url.AbsoluteUri.GetSubdomain();
}
if (config.DevEnvironment)
{
sub = "dev - " + sub;
}
string sub = request.RequestContext.RouteData.Values["sub"].ToString();
if (string.IsNullOrEmpty(sub))
{
sub = request.Url.AbsoluteUri.GetSubdomain();
}
if (config.DevEnvironment)
{
sub = "dev - " + sub;
}

PiwikTracker.URL = config.PiwikConfig.Url;
PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId);
// Get Request Info
string ipAddress = request.ClientIPFromRequest(true);
tracker.setIp(ipAddress);
tracker.setTokenAuth(config.PiwikConfig.TokenAuth);
tracker.setUrl(request.Url.ToString());
PiwikTracker.URL = config.PiwikConfig.Url;
PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId);

tracker.setUserAgent(request.UserAgent);
// Get Request Info
string ipAddress = request.ClientIPFromRequest(true);
tracker.setIp(ipAddress);
tracker.setTokenAuth(config.PiwikConfig.TokenAuth);
tracker.setUrl(request.Url.ToString());

// Get browser info
tracker.setResolution(request.Browser.ScreenPixelsWidth, request.Browser.ScreenPixelsHeight);
tracker.setBrowserHasCookies(request.Browser.Cookies);
if (!string.IsNullOrEmpty(request.Headers["Accept-Language"]))
tracker.setBrowserLanguage(request.Headers["Accept-Language"]);
BrowserPlugins plugins = new BrowserPlugins();
plugins.java = request.Browser.JavaApplets;
tracker.setPlugins(plugins);
tracker.setUserAgent(request.UserAgent);

// Get Referral
if (request.UrlReferrer != null)
tracker.setUrlReferrer(request.UrlReferrer.ToString());
// Get browser info
tracker.setResolution(request.Browser.ScreenPixelsWidth, request.Browser.ScreenPixelsHeight);
tracker.setBrowserHasCookies(request.Browser.Cookies);
if (!string.IsNullOrEmpty(request.Headers["Accept-Language"]))
tracker.setBrowserLanguage(request.Headers["Accept-Language"]);
BrowserPlugins plugins = new BrowserPlugins();
plugins.java = request.Browser.JavaApplets;
tracker.setPlugins(plugins);

// Send the tracking request
tracker.setRequestTimeout(15);
tracker.doTrackPageView(string.Format("{0}/{1}", sub, title));
// Get Referral
if (request.UrlReferrer != null)
tracker.setUrlReferrer(request.UrlReferrer.ToString());

// Send the tracking request
tracker.doTrackPageView(string.Format("{0}/{1}", sub, title));
}
}
catch (Exception ex)
{

Loading…
Cancel
Save