using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.PortalEngine;
using CMS.WebAnalytics;
public partial class CMSWebParts_WebAnalytics_CustomStatistics : CMSAbstractWebPart
{
#region "Properties"
///
/// If true, statistics is loged only once per user session
///
public bool OncePerUser
{
get
{
return ValidationHelper.GetBoolean(GetValue("OncePerUser"), false);
}
set
{
SetValue("OncePerUser", value);
}
}
///
/// Name of statistics to log
///
public String StatisticsName
{
get
{
return ValidationHelper.GetString(GetValue("StatisticsName"), String.Empty);
}
set
{
SetValue("StatisticsName", value);
}
}
///
/// Object name (holds additional info about log)
///
public String StatisticsObjectName
{
get
{
return ValidationHelper.GetString(GetValue("StatisticsObjectName"), String.Empty);
}
set
{
SetValue("StatisticsObjectName", value);
}
}
///
/// Statistics value to log
///
public double StatisticsValue
{
get
{
return ValidationHelper.GetDoubleSystem(GetValue("StatisticsValue"), 0);
}
set
{
SetValue("StatisticsValue", value);
}
}
#endregion
#region "Methods"
///
/// Content loaded event handler
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
if (!StopProcessing && AnalyticsHelper.IsLoggingEnabled(CMSContext.CurrentSiteName, CMSContext.CurrentAliasPath))
{
// Log only for non empty statistics name
if (!String.IsNullOrEmpty(StatisticsName))
{
// Log only for live site
if (CMSContext.ViewMode == ViewModeEnum.LiveSite)
{
// If once per user is set - log only once per session
if (OncePerUser)
{
// If already in the session - do not log
if (SessionHelper.GetValue("CustomStatisticsLogged_" + StatisticsName) != null)
{
return;
}
SessionHelper.SetValue("CustomStatisticsLogged_" + StatisticsName, true);
}
HitLogProvider.LogHit(StatisticsName, CMSContext.CurrentSiteName, CMSContext.CurrentPageInfo.DocumentCulture, StatisticsObjectName, CMSContext.CurrentPageInfo.NodeID, 1, StatisticsValue);
}
}
}
}
#endregion
}