mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed Visitor Data not being pulled correctly.
Fixed a couple Context null reference possibilities with the Config and Pre-Send Headers event.
This commit is contained in:
parent
73403551d6
commit
c099076d8e
@ -53,12 +53,16 @@ namespace Teknik
|
||||
|
||||
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
|
||||
{
|
||||
// Don't server HSTS over HTTP
|
||||
if (HttpContext.Current.Request.Url.Scheme != "https")
|
||||
HttpContext.Current.Response.Headers.Remove("strict-transport-security");
|
||||
if (HttpContext.Current != null)
|
||||
{
|
||||
HttpContext context = HttpContext.Current;
|
||||
// Don't server HSTS over HTTP
|
||||
if (context.Request.Url.Scheme != "https")
|
||||
HttpContext.Current.Response.Headers.Remove("strict-transport-security");
|
||||
|
||||
// Remove stupid headers
|
||||
HttpContext.Current.Response.Headers.Remove("Server");
|
||||
// Remove stupid headers
|
||||
context.Response.Headers.Remove("Server");
|
||||
}
|
||||
}
|
||||
|
||||
protected void Application_EndRequest(object sender, EventArgs e)
|
||||
|
@ -171,12 +171,13 @@ namespace Teknik.Configuration
|
||||
public static Config Load()
|
||||
{
|
||||
HttpContext context = HttpContext.Current;
|
||||
_Config = (Config)context.Cache[_ConfigCacheKey];
|
||||
if (context != null)
|
||||
_Config = (Config)context.Cache[_ConfigCacheKey];
|
||||
if (_Config == null)
|
||||
{
|
||||
string path = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
|
||||
_Config = Load(path);
|
||||
context.Cache.Insert(_ConfigCacheKey, _Config, new CacheDependency(path));
|
||||
context?.Cache.Insert(_ConfigCacheKey, _Config, new CacheDependency(path));
|
||||
}
|
||||
return _Config;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Piwik.Analytics;
|
||||
using Piwik.Analytics;
|
||||
using Piwik.Analytics.Date;
|
||||
using Piwik.Analytics.Modules;
|
||||
using System;
|
||||
@ -32,51 +32,57 @@ namespace Teknik.Piwik
|
||||
|
||||
foreach (string period in results.Keys)
|
||||
{
|
||||
Hashtable result = (Hashtable)results[period];
|
||||
// Create a new object to return
|
||||
VisitorData data = new VisitorData();
|
||||
|
||||
// Set Period Date
|
||||
DateTime date = new DateTime(1900, 1, 1);
|
||||
DateTime.TryParse(period, out date);
|
||||
data.Date = date;
|
||||
|
||||
int UniqueVisitors = 0;
|
||||
int.TryParse(result["nb_uniq_visitors"].ToString(), out UniqueVisitors);
|
||||
data.UniqueVisitors = UniqueVisitors;
|
||||
// Pull Out Data
|
||||
if (results[period].GetType() == typeof(Hashtable))
|
||||
{
|
||||
Hashtable result = (Hashtable) results[period];
|
||||
|
||||
int visits = 0;
|
||||
int.TryParse(result[VisitsSummary.NB_VISITS].ToString(), out visits);
|
||||
data.Visits = visits;
|
||||
int UniqueVisitors = 0;
|
||||
int.TryParse(result["nb_uniq_visitors"].ToString(), out UniqueVisitors);
|
||||
data.UniqueVisitors = UniqueVisitors;
|
||||
|
||||
int VisitsConverted = 0;
|
||||
int.TryParse(result[VisitsSummary.NB_VISITS_CONVERTED].ToString(), out VisitsConverted);
|
||||
data.VisitsConverted = VisitsConverted;
|
||||
int visits = 0;
|
||||
int.TryParse(result[VisitsSummary.NB_VISITS].ToString(), out visits);
|
||||
data.Visits = visits;
|
||||
|
||||
int Actions = 0;
|
||||
int.TryParse(result[VisitsSummary.NB_ACTIONS].ToString(), out Actions);
|
||||
data.Actions = Actions;
|
||||
int VisitsConverted = 0;
|
||||
int.TryParse(result[VisitsSummary.NB_VISITS_CONVERTED].ToString(), out VisitsConverted);
|
||||
data.VisitsConverted = VisitsConverted;
|
||||
|
||||
decimal ActionsPerVisit = 0;
|
||||
decimal.TryParse(result[VisitsSummary.NB_ACTIONS_PER_VISIT].ToString(), out ActionsPerVisit);
|
||||
data.ActionsPerVisit = ActionsPerVisit;
|
||||
int Actions = 0;
|
||||
int.TryParse(result[VisitsSummary.NB_ACTIONS].ToString(), out Actions);
|
||||
data.Actions = Actions;
|
||||
|
||||
int MaxActions = 0;
|
||||
int.TryParse(result[VisitsSummary.MAX_ACTIONS].ToString(), out MaxActions);
|
||||
data.MaxActions = MaxActions;
|
||||
decimal ActionsPerVisit = 0;
|
||||
decimal.TryParse(result[VisitsSummary.NB_ACTIONS_PER_VISIT].ToString(), out ActionsPerVisit);
|
||||
data.ActionsPerVisit = ActionsPerVisit;
|
||||
|
||||
int BounceCount = 0;
|
||||
int.TryParse(result[VisitsSummary.BOUNCE_COUNT].ToString(), out BounceCount);
|
||||
data.BounceCount = BounceCount;
|
||||
int MaxActions = 0;
|
||||
int.TryParse(result[VisitsSummary.MAX_ACTIONS].ToString(), out MaxActions);
|
||||
data.MaxActions = MaxActions;
|
||||
|
||||
data.BounceRate = result[VisitsSummary.BOUNCE_RATE].ToString();
|
||||
int BounceCount = 0;
|
||||
int.TryParse(result[VisitsSummary.BOUNCE_COUNT].ToString(), out BounceCount);
|
||||
data.BounceCount = BounceCount;
|
||||
|
||||
int AverageTimeOnSite = 0;
|
||||
int.TryParse(result[VisitsSummary.AVG_TIME_ON_SITE].ToString(), out AverageTimeOnSite);
|
||||
data.AverageTimeOnSite = AverageTimeOnSite;
|
||||
data.BounceRate = result[VisitsSummary.BOUNCE_RATE].ToString();
|
||||
|
||||
int VisitLengthTotal = 0;
|
||||
int.TryParse(result[VisitsSummary.SUM_VISIT_LENGTH].ToString(), out VisitLengthTotal);
|
||||
data.VisitLengthTotal = VisitLengthTotal;
|
||||
int AverageTimeOnSite = 0;
|
||||
int.TryParse(result[VisitsSummary.AVG_TIME_ON_SITE].ToString(), out AverageTimeOnSite);
|
||||
data.AverageTimeOnSite = AverageTimeOnSite;
|
||||
|
||||
int VisitLengthTotal = 0;
|
||||
int.TryParse(result[VisitsSummary.SUM_VISIT_LENGTH].ToString(), out VisitLengthTotal);
|
||||
data.VisitLengthTotal = VisitLengthTotal;
|
||||
}
|
||||
|
||||
visitorData.Add(data);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -19,5 +19,20 @@ namespace Teknik.Piwik
|
||||
public string BounceRate { get; set; }
|
||||
public int AverageTimeOnSite { get; set; }
|
||||
public int VisitLengthTotal { get; set; }
|
||||
|
||||
public VisitorData()
|
||||
{
|
||||
Date = DateTime.Now;
|
||||
UniqueVisitors = 0;
|
||||
Visits = 0;
|
||||
VisitsConverted = 0;
|
||||
Actions = 0;
|
||||
ActionsPerVisit = 0;
|
||||
MaxActions = 0;
|
||||
BounceCount = 0;
|
||||
BounceRate = string.Empty;
|
||||
AverageTimeOnSite = 0;
|
||||
VisitLengthTotal = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user