Analytics Session

Analytics Session

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Analytics.AnalyticsSession
  • Sitecore.Analytics.AnalyticsTracker
  • Sitecore.Data.Items.Item

C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

if (!Sitecore.Analytics.AnalyticsTracker.IsActive) return;
Sitecore.Analytics.AnalyticsSession session = Sitecore.Analytics.AnalyticsTracker.Current.CurrentSession;
if (session == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("{0}", "C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //

output.Write("{0}&#58;&#160;{1}", "ASP.NET Session ID", "<b>" + session.AspNetSessionId + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Browser", "<b>" + session.Browser + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Session Domain", "<b>" + session.Domain + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Duration in Milliseconds", "<b>" + session.Duration.TotalMilliseconds.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "IP Address", "<b>" + session.Ip + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Is New Session", "<b>" + session.IsNewSession.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Keywords", "<b>" + session.Keywords + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Language", "<b>" + session.Language + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Multisite", "<b>" + session.MultiSite + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Operating System", "<b>" + session.OperatingSystem + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Referring Site", "<b>" + session.ReferringSite + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Screen", "<b>" + session.Screen + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Session ID", "<b>" + session.SessionId.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Timestamp", "<b>" + session.Timestamp.ToString() + "</b><br/><br/>");

output.RenderEndTag(); //Div


C# Web Control Real-time Output

Item: Analytics Session