Sitecore Live Goals access programmatically

 To access on going contact triggered goals without waiting till session end.

protected List<ProfileScoreAndPointsList> GetCurrentTrackerTriggeredGoals(IInteractionData interaction)
        {
            List<ProfileScoreAndPointsList> profileScoreLists = new List<ProfileScoreAndPointsList>();
            if (interaction != null)
            {
                IEnumerable<PageEventData> events = interaction.Pages.SelectMany<Page, PageEventData>((p, v) => p.PageEvents).Select(d => d);
                profileScoreLists = events.Where(p => p.IsGoal).GroupBy(l => l.PageEventDefinitionId)
                 .Select(goal => new ProfileScoreAndPointsList
                 {
                     ProfileID = ID.Parse(goal.Select(x => x.PageEventDefinitionId).FirstOrDefault()),
                     ProfileKeyName = goal.Select(x => x.Name).FirstOrDefault(),
                     ProfileKeyScore = goal.Sum(c => c.Value)
                 }).ToList();
            }
            return profileScoreLists;
        }

public class ProfileScoreAndPointsList
    {
        public ID ProfileID { get; set; }
        public string ProfileKeyName { get; set; }
        public double ProfileKeyScore { get; set; }
    }


Comments

Popular posts from this blog

Custom Item Url and resolving the item in Sitecore - Buckets

Fixing Sitecore Buckets folder path - Items created after 12 AM server time zone

Sitecore Search - API Crawler with Edge Pagination