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;
}
List<ProfileScoreAndPointsList> profileScoreLists = new List<ProfileScoreAndPointsList>();
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; }
}
{
public ID ProfileID { get; set; }
Comments
Post a Comment