Sitecore - Track user events in a delimited time frame
Almost always we need to track what users have been doing on our site, but what if we need to know if a user has performed a specific action within a certain time period? Recently I was asked to write code that reacts to some form events, e.g. upon submission some forms needed to be hidden and an alert needed to be shown if the submission happened within x days. One of the possible solutions we thought of was to use Sitecore Goals. Once a user submitted a form we registered a goal, on the next page load we checked if the goal was triggered (within a certain time frame) and we hid the form if needed. The following code will allow you to register goals for the current logged in user: public void TriggerGoal(ID goalId, string additionalData) { Assert.IsNotNull(Tracker.Current, "Tracker.Current"); Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session"); Assert.IsNotNull(goalId, "goalId"); using (XCon...