コード例 #1
0
        public Hashtable GetInformation(string visitId)
        {
            List<Hashtable> goals = new List<Hashtable>();
            List<Hashtable> goals2 = new List<Hashtable>();

            PageStatisticsContext pageStatistics = new PageStatisticsContext();

            Sitecore.SharedSource.Analytics.Context.Visit visit = pageStatistics.GetVisit_ById(visitId);
            if(visit == null)
            {
                return null;
            }

            Sitecore.SharedSource.Analytics.Context.Visitor visitor = pageStatistics.GetVisitor_ById(visit.VisitorId.ToString());
            if (visitor == null)
            {
                return null;
            }

            List<VisitGoal> visitGoalsMet = pageStatistics.GetGoalsMetDuringVisit(visit.VisitId).OrderByDescending(x => x.GoalMetDate).ToList();
            foreach(VisitGoal visitGoal in visitGoalsMet)
            {
                Hashtable goalTable = new Hashtable();
                goalTable.Add("Date", visitGoal.GoalMetDate.Value.ToString("MMMM dd, yyyy H:mm:ss"));
                goalTable.Add("Goal", visitGoal.GoalName);
                goalTable.Add("Amount", visitGoal.EngagementValue);
                goals.Add(goalTable);
            }

            const int startSecondColumnAt = 3;
            if (goals.Count > startSecondColumnAt)
            {
                double dividedValue = ((double)goals.Count) / 2;
                int amountPerColumn = (int)Math.Round(dividedValue, 0, MidpointRounding.AwayFromZero);
                goals2 = goals.GetRange(amountPerColumn, goals.Count - amountPerColumn);

                goals = goals.GetRange(0, amountPerColumn);
            }

            Hashtable hashtable = new Hashtable();
            hashtable.Add("VisitorEngagementValue", pageStatistics.GetVisitorEngagementValue(visitor.VisitorId).ToString("N0"));
            hashtable.Add("VisitEngagementValue", pageStatistics.GetVisitEngagementValue(visit.VisitId).ToString("N0"));
            hashtable.Add("Goals", goals);
            hashtable.Add("Goals2", goals2);

            return hashtable;
        }
コード例 #2
0
        protected override void OnInit(EventArgs e)
        {
            DebugInfoEvent += new EventHandler(AnalyticsControl_DebugInfoEvent);

            //set database
            if (Sitecore.Context.ContentDatabase != null)
            {
                _database = Sitecore.Context.ContentDatabase;
            }
            else
            {
                _database = Sitecore.Context.Database;
            }

            //set context
            _pageStatisticsContext = new PageStatisticsContext();
        }
コード例 #3
0
        public void SetGoal(string currentItemId, string linkedId, string goalId)
        {
            if (string.IsNullOrEmpty(currentItemId) || string.IsNullOrEmpty(linkedId) || string.IsNullOrEmpty(goalId))
            {
                return;
            }

            Database db = Sitecore.Context.Database;
            if(db == null || db.Name.ToLower() == "core")
            {
                db = Sitecore.Context.ContentDatabase;
            }

            if(db == null)
            {
                return;
            }

            Item currentItem = SitecoreItemFinder.GetItem(db, currentItemId);
            Item linkedItem = SitecoreItemFinder.GetItem(db, linkedId);
            Item goalItem = SitecoreItemFinder.GetItem(db, goalId);

            if (currentItem.IsNull() || linkedItem.IsNull() || goalItem.IsNull())
            {
                return;
            }

            PageStatisticsContext pageStatistics = new PageStatisticsContext();
            pageStatistics.SetGoalMet(currentItem, linkedItem, goalItem, Tracker.CurrentVisit.VisitId, Tracker.CurrentVisit.VisitorId);
        }