Analytics Tracker

Analytics Tracker

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

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

C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == 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();

if (!Sitecore.Analytics.AnalyticsTracker.IsActive) return;
Sitecore.Analytics.AnalyticsTracker tracker = Sitecore.Analytics.AnalyticsTracker.Current;
if (tracker == null || tracker.CurrentGlobalSession == null) return;

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(); //P

output.Write("{0}&#63;&#160;{1}", "Can Be Robot", "<b>" + tracker.CanBeRobot.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Acquaintance", "<b>" + tracker.CurrentGlobalSession.Acquaintance.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Cookie Value", "<b>" + tracker.CurrentGlobalSession.CookieValue + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "External User", "<b>" + tracker.CurrentGlobalSession.ExternalUser + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "State", "<b>" + tracker.CurrentGlobalSession.State + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Current Page Data", "<b>" + tracker.CurrentPage.Data + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Device ID", "<b>" + tracker.CurrentPage.DeviceId.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Is Cancelled", "<b>" + tracker.IsCanceled.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Is Test Campaign", "<b>" + tracker.IsTestCampaignEventMode.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Test Campaign Event ID", "<b>" + tracker.TestCampaignEventId.ToString() + "</b>");

output.RenderEndTag(); //Div


C# Web Control Real-time Output

Item: Analytics Tracker